diff --git a/Runtime.msbuild b/Runtime.msbuild index 3caf2c471..3aab942e5 100644 --- a/Runtime.msbuild +++ b/Runtime.msbuild @@ -100,8 +100,7 @@ <_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.dll" /> <_TestDLLsXunit Include="bin\$(Configuration)\test\*.Test.*.dll" /> - <_TestDLLsXunit Include="bin\$(Configuration)\Test\NetCore\*.Test.dll" /> - <_TestDLLsXunit Include="bin\$(Configuration)\Test\NetStandard\*.Test.dll" /> + <_TestDLLsXunit Include="bin\$(Configuration)\Test\NetCore\*.Test.dll" Condition="'$(BuildPortable)' == 'true'" /> <_XunitProject Include="tools\WebStack.xunit.targets"> TestAssembly=%(_TestDLLsXunit.FullPath);XmlPath=$(TestResultsDirectory)%(_TestDLLsXunit.FileName)-XunitResults.xml @@ -112,6 +111,12 @@ + + + diff --git a/RuntimePortable.sln b/RuntimePortable.sln index 0aee6d4ba..f20623fd4 100644 --- a/RuntimePortable.sln +++ b/RuntimePortable.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27019.1 +VisualStudioVersion = 15.0.27116.1 MinimumVisualStudioVersion = 15.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A9836F9E-6DB3-4D9F-ADCA-CF42D8C8BA93}" EndProject @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.NetStandard", "src\System.Net.Http.Formatting.NetStandard\System.Net.Http.Formatting.NetStandard.csproj", "{636CA76A-C85C-42E2-B4AA-88046279B3CA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http.Formatting.NetStandard.Test", "test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj", "{DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.Http.Formatting.NetStandard.Test", "test\System.Net.Http.Formatting.NetStandard.Test\System.Net.Http.Formatting.NetStandard.Test.csproj", "{DECB05DF-B33A-44A0-B5DE-B14A8CE0740F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A72045D4-B048-4697-9535-C3A6EDCA85B9}" ProjectSection(SolutionItems) = preProject diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 288f92f33..c81c39ff4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -4,6 +4,6 @@ true false - v4.5 + v4.5 diff --git a/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj b/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj index ba2a16918..0211316d3 100644 --- a/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj +++ b/src/System.Net.Http.Formatting.NetStandard/System.Net.Http.Formatting.NetStandard.csproj @@ -1,39 +1,36 @@ - netstandard1.1 + netstandard2.0 System.Net.Http System.Net.Http.Formatting $(OutputPath)NetStandard\ $(OutputPath)$(AssemblyName).xml - 1.6.0 - $(CodeAnalysis) - ..\Strict.ruleset - /assemblycomparemode:StrongNameIgnoringVersion - false - $(DefineConstants);NETFX_CORE;ASPNETMVC;NOT_CLS_COMPLIANT;NETSTANDARD1_1 + false + $(DefineConstants);ASPNETMVC;NEWTONSOFTJSON10 1591 - false $(Configurations);CodeAnalysis false - - - - - - + + - Properties\CommonAssemblyInfo.cs + + + Common\CollectionExtensions.cs + Common\Error.cs + + Common\ListWrapperCollection.cs + Common\TaskHelpers.cs @@ -43,197 +40,9 @@ Common\UriQueryUtility.cs - - Common\CollectionExtensions.cs - - - Common\ListWrapperCollection.cs - - - FormattingUtilities.cs - - - Formatting\BaseJsonMediaTypeFormatter.cs - - - Formatting\BsonMediaTypeFormatter.cs - - - Formatting\DelegatingEnumerable.cs - - - Formatting\FormDataCollection.cs - - - Formatting\FormUrlEncodedJson.cs - - - Formatting\FormUrlEncodedMediaTypeFormatter.cs - - - Formatting\IFormatterLogger.cs - - - Formatting\JsonMediaTypeFormatter.cs - - - Formatting\MediaTypeConstants.cs - - - Formatting\MediaTypeFormatter.cs - - - Formatting\MediaTypeFormatterCollection.cs - - - Formatting\MediaTypeHeaderValueExtensions.cs - - - Formatting\MediaTypeHeaderValueRange.cs - - - Formatting\ParsedMediaTypeHeaderValue.cs - - - Formatting\Parsers\FormUrlEncodedParser.cs - - - Formatting\Parsers\HttpRequestHeaderParser.cs - - - Formatting\Parsers\HttpRequestLineParser.cs - - - Formatting\Parsers\HttpResponseHeaderParser.cs - - - Formatting\Parsers\HttpStatusLineParser.cs - - - Formatting\Parsers\InternetMessageFormatHeaderParser.cs - - - Formatting\Parsers\MimeMultipartBodyPartParser.cs - - - Formatting\Parsers\MimeMultipartParser.cs - - - Formatting\Parsers\ParserState.cs - - - Formatting\StringComparisonHelper.cs - - - Formatting\XmlMediaTypeFormatter.cs - - - HttpContentFormDataExtensions.cs - - - Internal\HttpValueCollection.cs - - - UriExtensions.cs - - - GlobalSuppressions.cs - - - Handlers\HttpProgressEventArgs.cs - - - Handlers\ProgressContent.cs - - - Handlers\ProgressMessageHandler.cs - - - Handlers\ProgressStream.cs - - - HttpClientExtensions.cs - - - HttpClientFactory.cs - - - HttpContentExtensions.cs - - - HttpContentMessageExtensions.cs - - - HttpContentMultipartExtensions.cs - - - HttpHeaderExtensions.cs - - - HttpMessageContent.cs - - - HttpUnsortedHeaders.cs - - - HttpUnsortedRequest.cs - - - HttpUnsortedResponse.cs - - - Internal\AsyncResult.cs - - - Internal\DelegatingStream.cs - - - Internal\ReadOnlyStreamWithEncodingPreamble.cs - - - Internal\TypeExtensions.cs - - - MimeBodyPart.cs - - - MultipartFileData.cs - - - MultipartMemoryStreamProvider.cs - - - MultipartRelatedStreamProvider.cs - - - MultipartStreamProvider.cs - - - ObjectContent.cs - - - ObjectContentOfT.cs - - - PushStreamContent.cs - - - Properties\AssemblyInfo.cs - - - Properties\Resources.Designer.cs - True - True - Resources.resx - - - UnsupportedMediaTypeException.cs - - - Internal\ConcurrentDictionary.cs - - - MediaTypeHeaderValueExtensions.cs + + + %(RecursiveDir)\%(Filename).cs @@ -243,8 +52,6 @@ True CommonWebApiResources.resx - - Properties\CommonWebApiResources.resx ResXFileCodeGenerator @@ -252,6 +59,11 @@ + + True + True + Resources.resx + Properties\Resources.resx ResXFileCodeGenerator diff --git a/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs b/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs index 8b686f0c5..cf2608de7 100644 --- a/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs +++ b/src/System.Net.Http.Formatting/Formatting/BsonMediaTypeFormatter.cs @@ -11,7 +11,12 @@ using System.Threading.Tasks; using System.Web.Http; using Newtonsoft.Json; +#if NEWTONSOFTJSON10 +using BsonReader = Newtonsoft.Json.Bson.BsonDataReader; +using BsonWriter = Newtonsoft.Json.Bson.BsonDataWriter; +#else using Newtonsoft.Json.Bson; +#endif namespace System.Net.Http.Formatting { diff --git a/src/System.Net.Http.Formatting/Properties/AssemblyInfo.cs b/src/System.Net.Http.Formatting/Properties/AssemblyInfo.cs index 6186d7b3b..454c8861c 100644 --- a/src/System.Net.Http.Formatting/Properties/AssemblyInfo.cs +++ b/src/System.Net.Http.Formatting/Properties/AssemblyInfo.cs @@ -3,7 +3,7 @@ using System.Reflection; using System.Runtime.CompilerServices; -#if !NETFX_CORE || NETSTANDARD1_1 +#if !NETFX_CORE using System.Runtime.InteropServices; #endif @@ -14,11 +14,11 @@ [assembly: AssemblyTitle("System.Net.Http.Formatting")] [assembly: AssemblyDescription("")] -#if !NETFX_CORE || NETSTANDARD1_1 // GuidAttibute is not supported in portable libraries but is in .NET Standard. +#if !NETFX_CORE // GuidAttibute is not supported in portable libraries. [assembly: Guid("7fa1ae84-36e2-46b6-812c-c985a8e65e9a")] #endif -#if NETSTANDARD1_1 +#if NETSTANDARD2_0 [assembly: InternalsVisibleTo("System.Net.Http.Formatting.NetStandard.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] #elif NETFX_CORE [assembly: InternalsVisibleTo("System.Net.Http.Formatting.NetCore.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 6843cc70d..8dc298fd2 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -4,6 +4,6 @@ false true - v4.5.2 + v4.5.2 diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets index 7c7d5e2cc..72087f737 100644 --- a/test/Directory.Build.targets +++ b/test/Directory.Build.targets @@ -1,12 +1,33 @@ - - + + + + + + + + + + + + + + + + + + + - - + - - + diff --git a/test/Microsoft.TestCommon/PlatformInfo.cs b/test/Microsoft.TestCommon/PlatformInfo.cs index ee36ccb18..678ecff08 100644 --- a/test/Microsoft.TestCommon/PlatformInfo.cs +++ b/test/Microsoft.TestCommon/PlatformInfo.cs @@ -11,6 +11,7 @@ namespace Microsoft.TestCommon public static class PlatformInfo { private const string _net45TypeName = "System.IWellKnownStringEqualityComparer, mscorlib, Version=4.0.0.0, PublicKeyToken=b77a5c561934e089"; + private const string _netCore20TypeName = "System.OrdinalCaseSensitiveComparer, system.private.corelib, Version=4.0.0.0, PublicKeyToken=7cec85d7bea7798e"; private static Lazy _platform = new Lazy(GetPlatform, isThreadSafe: true); /// @@ -23,6 +24,12 @@ public static Platform Platform private static Platform GetPlatform() { + if (Type.GetType(_netCore20TypeName, throwOnError: false) != null) + { + // Treat .NET Core 2.0 as a .NET 4.5 superset though internal types are different. + return Platform.Net45; + } + if (Type.GetType(_net45TypeName, throwOnError: false) != null) { return Platform.Net45; diff --git a/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj b/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj index 801ef54da..31732bd10 100644 --- a/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj +++ b/test/System.Net.Http.Formatting.NetStandard.Test/System.Net.Http.Formatting.NetStandard.Test.csproj @@ -1,322 +1,32 @@ - - - - + - {DECB05DF-B33A-44A0-B5DE-B14A8CE0740F} - Library - Properties + netcoreapp2.0;net461 System.Net.Http System.Net.Http.Formatting.NetStandard.Test - ..\..\bin\$(Configuration)\Test\NetStandard\ - $(DefineConstants);NETFX_CORE + ..\..\bin\$(Configuration)\Test\ + $(DefineConstants);NEWTONSOFTJSON10 + $(Configurations);CodeAnalysis + false - - ..\..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll - True - - - ..\..\packages\Moq.4.7.142\lib\net45\Moq.dll - True - - - ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - - - - - - - - ..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - True - - - ..\..\packages\xunit.assert.2.3.0\lib\netstandard1.1\xunit.assert.dll - True - - - ..\..\packages\xunit.extensibility.core.2.3.0\lib\netstandard1.1\xunit.core.dll - True - - - ..\..\packages\xunit.extensibility.execution.2.3.0\lib\net452\xunit.execution.desktop.dll - True - + + + - - False - - - - - DataSets\Types\DerivedFormUrlEncodedMediaTypeFormatter.cs - - - Formatting\BsonMediaTypeFormatterTests.cs - - - Internal\FormDataCollectionTests.cs - - - Formatting\FormUrlEncodedFromContentTests.cs - - - Formatting\FormUrlEncodedFromUriQueryTests.cs - - - Internal\FormUrlEncodedJsonTests.cs - - - Formatting\FormUrlEncodedMediaTypeFormatterTests.cs - - - Formatting\JsonNetSerializationTest.cs - - - Formatting\JsonNetValidationTest.cs - - - Internal\FormUrlEncodedParserTests.cs - - - HttpContentFormDataExtensionsTest.cs - - - HttpValueCollectionTest.cs - - - Internal\ReadOnlyStreamWithEncodingPreambleTest.cs - - - MimeBodyPartTest.cs - - - HttpHeaderExtensionsTest.cs - - - HttpUnsortedResponseTest.cs - - - HttpUnsortedRequestTest.cs - - - SFormatting\tringComparisonHelperTest.cs - - - Mocks\MockAsyncCallback.cs - - - Mocks\MockCompletedAsyncResult.cs - - - HttpClientFactoryTest.cs - - - Handlers\ProgressContentTest.cs - - - Handlers\ProgressStreamTest.cs - - - Handlers\HttpProgressEventArgsTest.cs - - - MultipartRelatedStreamProviderTests.cs - - - MultipartStreamProviderTestBase.cs - - - MultipartFileDataTest.cs - - - DataSets\Types\DataContractEnum.cs - - - DataSets\Types\DataContractType.cs - - - DataSets\Types\DerivedDataContractType.cs - - - DataSets\Types\DerivedJsonMediaTypeFormatter.cs - - - DataSets\Types\DerivedWcfPocoType.cs - - - DataSets\Types\DerivedXmlMediaTypeFormatter.cs - - - DataSets\Types\DerivedXmlSerializableType.cs - - - DataSets\HttpTestData.cs - - - DataSets\Types\INotJsonSerializable.cs - - - DataSets\Types\WcfPocoType.cs - - - DataSets\Types\XmlSerializableType.cs - - - Formatting\SerializerConsistencyTests.cs - - - Formatting\XmlSerializerMediaTypeFormatterTests.cs - - - Formatting\MediaTypeFormatterTestBase.cs - - - HttpClientExtensionsTest.cs - - - Internal\AsyncResultTest.cs - - - Internal\DelegatingStreamTest.cs - - - Mocks\MockDelegatingHandler.cs - - - Mocks\MockDelegatingStream.cs - - - Mocks\MockProgressEventHandler.cs - - - Mocks\TestableHttpMessageHandler.cs - - - UriExtensionsTests.cs - - - UriQueryDataSet.cs - - - FormattingUtilitiesTests.cs - - - Formatting\JsonMediaTypeFormatterTests.cs - - - Formatting\MediaTypeConstantsTests.cs - - - Formatting\MediaTypeFormatterCollectionTests.cs - - - Formatting\MediaTypeFormatterTests.cs - - - Formatting\MediaTypeHeaderValueExtensionsTests.cs - - - Formatting\ParsedMediaTypeHeaderValueTests.cs - - - Formatting\XmlMediaTypeFormatterTests.cs - - - HttpContentMessageExtensionsTests.cs - - - HttpContentMultipartExtensionsTests.cs - - - HttpMessageContentTests.cs - - - Formatting\Parsers\HttpRequestHeaderParserTests.cs - - - Formatting\Parsers\HttpRequestLineParserTests.cs - - - Formatting\Parsers\HttpResponseHeaderParserTests.cs - - - Formatting\Parsers\HttpStatusLineParserTests.cs - - - Formatting\Parsers\InternetMessageFormatHeaderParserTests.cs - - - Formatting\Parsers\MimeMultipartParserTests.cs - - - MultipartMemoryStreamProviderTests.cs - - - ObjectContentOfTTests.cs - - - ObjectContentTests.cs - - - ParserData.cs - - - Mocks\MockHttpContent.cs - - - Mocks\MockMediaTypeFormatter.cs - - - HttpContentExtensionsTest.cs - - - PushStreamContentTest.cs - - - ProgressMessageHandlerTest.cs - - - ConcurrentDictionaryTests.cs + + %(RecursiveDir)\%(Filename).cs - - {636ca76a-c85c-42e2-b4aa-88046279b3ca} - System.Net.Http.Formatting.NetStandard - - - {fccc4cb7-baf7-4a57-9f89-e5766fe536c0} - Microsoft.TestCommon - + + - - Designer - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - \ No newline at end of file + diff --git a/test/System.Net.Http.Formatting.NetStandard.Test/packages.config b/test/System.Net.Http.Formatting.NetStandard.Test/packages.config deleted file mode 100644 index 3bfcd8764..000000000 --- a/test/System.Net.Http.Formatting.NetStandard.Test/packages.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/System.Net.Http.Formatting.Test/DataSets/HttpTestData.cs b/test/System.Net.Http.Formatting.Test/DataSets/HttpTestData.cs index 50911b2f9..fb482788b 100644 --- a/test/System.Net.Http.Formatting.Test/DataSets/HttpTestData.cs +++ b/test/System.Net.Http.Formatting.Test/DataSets/HttpTestData.cs @@ -302,9 +302,13 @@ public static TheoryDataSet ReadAndWriteCorrectCharacterEn { "This is a test 激光這兩個字是甚麼意思 string written using utf-8", "utf-8", true }, { "This is a test 激光這兩個字是甚麼意思 string written using utf-16", "utf-16", true }, { "This is a test 激光這兩個字是甚麼意思 string written using utf-32", "utf-32", false }, +#if !NETCOREAPP2_0 // shift_jis and iso-2022-kr are not supported when running on .NET Core 2.0. { "This is a test 激光這兩個字是甚麼意思 string written using shift_jis", "shift_jis", false }, +#endif { "This is a test æøå string written using iso-8859-1", "iso-8859-1", false }, +#if !NETCOREAPP2_0 { "This is a test 레이저 단어 뜻 string written using iso-2022-kr", "iso-2022-kr", false }, +#endif }; } } diff --git a/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs b/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs index 4e5c53cf1..d849df473 100644 --- a/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs +++ b/test/System.Net.Http.Formatting.Test/Formatting/BsonMediaTypeFormatterTests.cs @@ -262,12 +262,20 @@ public async Task FormatterThrowsOnWriteWithInvalidContent() BsonMediaTypeFormatter formatter = new BsonMediaTypeFormatter(); HttpContent content = new StringContent(String.Empty); MemoryStream stream = new MemoryStream(); +#if NEWTONSOFTJSON10 // Json.NET 10's Bson package calculates the path in some exceptions differently. + string expectedPath = "Value"; +#else + string expectedPath = string.Empty; +#endif + string expectedMessage = string.Format( + "Value is too large to fit in a signed 32 bit integer. BSON does not support unsigned values. Path '{0}'.", + expectedPath); // Act & Assert // Note error message is not quite correct: BSON supports byte, ushort, and smaller uint / ulong values. await Assert.ThrowsAsync( () => formatter.WriteToStreamAsync(variationType, testData, stream, content, transportContext: null), - "Value is too large to fit in a signed 32 bit integer. BSON does not support unsigned values. Path ''."); + expectedMessage); } [Fact] @@ -407,6 +415,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull( Assert.Null(readObj); } +#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0 except at top level (using BsonMediaTypeformatter special case). [Theory] [TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AsDictionary)] public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull_Dictionary(Type variationType, object testData) @@ -479,6 +488,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNull_ TestDataHolder readDataHolder = (TestDataHolder)readObj; Assert.Null(readDataHolder.V1); } +#endif [Fact] public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNullAsNullString() diff --git a/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs b/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs index 4bd2fd72d..34d17d884 100644 --- a/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs +++ b/test/System.Net.Http.Formatting.Test/Formatting/JsonMediaTypeFormatterTests.cs @@ -374,6 +374,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync(Type variatio } } +#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0. // Test alternate null value; always serialized as "null" [Theory] [TestDataSet(typeof(JsonMediaTypeFormatterTests), "DBNullAsObjectTestDataCollection", TestDataVariations.AllSingleInstances)] @@ -491,6 +492,7 @@ public async Task ReadFromStreamAsync_RoundTripsWriteToStreamAsync_DBNull() // Only JSON case where DBNull.Value round-trips Assert.Equal(testData, readObj); } +#endif [Fact] public async Task UseDataContractJsonSerializer_False() diff --git a/test/System.Net.Http.Formatting.Test/Formatting/JsonNetSerializationTest.cs b/test/System.Net.Http.Formatting.Test/Formatting/JsonNetSerializationTest.cs index 6fc985549..b544752f0 100644 --- a/test/System.Net.Http.Formatting.Test/Formatting/JsonNetSerializationTest.cs +++ b/test/System.Net.Http.Formatting.Test/Formatting/JsonNetSerializationTest.cs @@ -258,7 +258,11 @@ public Task DeserializingDeepArraysThrows() // low surrogate not preceded by high surrogate [InlineData("ABC \\udc00\\ud800 DEF", "ABC \ufffd\ufffd DEF")] // make sure unencoded invalid surrogate characters don't make it through +#if NETCOREAPP2_0 // Json.NET uses its regular invalid Unicode character on .NET Core 2.0; '?' elsewhere. + [InlineData("\udc00\ud800\ud800", "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd")] +#else [InlineData("\udc00\ud800\ud800", "??????")] +#endif public async Task InvalidUnicodeStringsAreFixedUp(string input, string expectedString) { string json = "\"" + input + "\""; @@ -458,6 +462,7 @@ IEnumerator IEnumerable.GetEnumerator() [Serializable] class SerializableType : IEquatable { + [JsonConstructor] public SerializableType(string protectedFieldValue) { this.protectedField = protectedFieldValue; diff --git a/test/System.Net.Http.Formatting.Test/Formatting/JsonNetValidationTest.cs b/test/System.Net.Http.Formatting.Test/Formatting/JsonNetValidationTest.cs index 968d33220..5eb23569f 100644 --- a/test/System.Net.Http.Formatting.Test/Formatting/JsonNetValidationTest.cs +++ b/test/System.Net.Http.Formatting.Test/Formatting/JsonNetValidationTest.cs @@ -28,7 +28,15 @@ public static TheoryDataSet Theories {"\"foo\"", typeof(DateTime), 1}, {"[\"a\",\"b\",\"45\",34]", typeof(int[]), 2}, - {"[\"a\",\"b\",\"45\",34]", typeof(DateTime[]), 4}, + { + "[\"a\",\"b\",\"45\",34]", + typeof(DateTime[]), +#if NEWTONSOFTJSON10 // Json.NET 10 detects an additional error over earlier versions. + 5 +#else + 4 +#endif + }, // Required members diff --git a/test/System.Net.Http.Formatting.Test/Internal/HttpValueCollectionTest.cs b/test/System.Net.Http.Formatting.Test/Internal/HttpValueCollectionTest.cs index f9cc72b11..8e06557b4 100644 --- a/test/System.Net.Http.Formatting.Test/Internal/HttpValueCollectionTest.cs +++ b/test/System.Net.Http.Formatting.Test/Internal/HttpValueCollectionTest.cs @@ -14,7 +14,9 @@ namespace System.Net.Http.Internal { public class HttpValueCollectionTest { +#if !NETCOREAPP2_0 // Unused on .NET Core 2.0. private static readonly int _maxCollectionKeys = 1000; +#endif private static HttpValueCollection CreateInstance() { @@ -146,6 +148,7 @@ public void Create_CreatesEmptyCollection() Assert.Empty(nvc); } +#if !NETCOREAPP2_0 // DBNull not serializable on .NET Core 2.0. // This set of tests requires running on a separate appdomain so we don't // touch the static property MediaTypeFormatter.MaxHttpCollectionKeys. [Fact] @@ -202,29 +205,24 @@ private static void Create_CreateDoesntThrowTooManyValuesPrivate() [Fact] public void AddTooManyKeysThrows() { - RunInIsolation(Create_CreateDoesntThrowTooManyValuesPrivate); + RunInIsolation(AddTooManyKeysThrowsPrivate); } - private void AddTooManyKeysThrowsPrivate() + private static void AddTooManyKeysThrowsPrivate() { // Note this is static, but also the expected type in a real run. MediaTypeFormatter.MaxHttpCollectionKeys = _maxCollectionKeys; HttpValueCollection collection = CreateInstance(); - - int i = 0; - - // Act && Assert - Assert.Throws(() => + for (int i = 0; i < _maxCollectionKeys; i++) { - for (; i < 1001; i++) - { - collection.Add(i.ToString(), i.ToString()); - } - }, TooManyKeysError); - + collection.Add(i.ToString(), i.ToString()); + } - Assert.Equal(1000, i); + // Act && Assert + Assert.Throws( + () => collection.Add(_maxCollectionKeys.ToString(), _maxCollectionKeys.ToString()), + TooManyKeysError); } [Fact] @@ -249,6 +247,7 @@ private static void AddDoesntThrowTooManyValuesPrivate() } }); } +#endif [Theory] [PropertyData("KeyValuePairs")]