Rewrite System.Text.Json stream tests to be async friendly and enable on WASM (#38663)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Fri, 10 Jul 2020 20:43:16 +0000 (22:43 +0200)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2020 20:43:16 +0000 (22:43 +0200)
The tests dealing are using a (De)SerializationWrapper so the same code can be used both for String and Stream types.
It does that by wrapping the async Stream serialization calls in `Task.Run().GetAwaiter().GetResult()` to turn them into sync calls.
However that doesn't work on WebAssembly since we can't wait on tasks as there's only a single thread.

To fix this inverse the wrapper so the synchronous String calls are turned into async and use normal awaits for the Stream calls.

This allows the test suite to pass on WebAssembly: `Tests run: 8349, Errors: 0, Failures: 0, Skipped: 11. Time: 475.528706s`

17 files changed:
src/libraries/System.Text.Json/tests/JsonDocumentTests.cs
src/libraries/System.Text.Json/tests/Serialization/CacheTests.cs
src/libraries/System.Text.Json/tests/Serialization/ConstructorTests/ConstructorTests.AttributePresence.cs
src/libraries/System.Text.Json/tests/Serialization/ConstructorTests/ConstructorTests.Cache.cs
src/libraries/System.Text.Json/tests/Serialization/ConstructorTests/ConstructorTests.Exceptions.cs
src/libraries/System.Text.Json/tests/Serialization/ConstructorTests/ConstructorTests.ParameterMatching.cs
src/libraries/System.Text.Json/tests/Serialization/ConstructorTests/ConstructorTests.Stream.cs
src/libraries/System.Text.Json/tests/Serialization/DeserializationWrapper.cs
src/libraries/System.Text.Json/tests/Serialization/InvalidTypeTests.cs
src/libraries/System.Text.Json/tests/Serialization/PolymorphicTests.cs
src/libraries/System.Text.Json/tests/Serialization/ReferenceHandlerTests.Deserialize.cs
src/libraries/System.Text.Json/tests/Serialization/SerializationWrapper.cs
src/libraries/System.Text.Json/tests/Serialization/Stream.Collections.cs
src/libraries/System.Text.Json/tests/Serialization/Stream.ReadTests.cs
src/libraries/System.Text.Json/tests/Utf8JsonReaderTests.MultiSegment.cs
src/libraries/System.Text.Json/tests/Utf8JsonReaderTests.cs
src/libraries/tests.proj

index 86f1bc3..6a940b0 100644 (file)
@@ -231,77 +231,75 @@ namespace System.Text.Json.Tests
         // If the internals change such that one of these is exercising substantially different
         // code, then it should switch to the full variation set.
         [MemberData(nameof(TestCases))]
-        public static void ParseJson_MemoryBytes(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_MemoryBytes(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(bytes.AsMemory()));
+                bytes => Task.FromResult(JsonDocument.Parse(bytes.AsMemory())));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_String(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_String(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
-                str => JsonDocument.Parse(str),
+                str => Task.FromResult(JsonDocument.Parse(str)),
                 null);
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_SeekableStream(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_SeekableStream(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(new MemoryStream(bytes)));
+                bytes => Task.FromResult(JsonDocument.Parse(new MemoryStream(bytes))));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_SeekableStream_Async(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_SeekableStream_Async(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.ParseAsync(new MemoryStream(bytes)).GetAwaiter().GetResult());
+                bytes => JsonDocument.ParseAsync(new MemoryStream(bytes)));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_UnseekableStream(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_UnseekableStream(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(
+                bytes => JsonDocument.ParseAsync(
                     new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, bytes)));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_UnseekableStream_Async(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_UnseekableStream_Async(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.ParseAsync(
-                    new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, bytes)).
-                    GetAwaiter().GetResult());
+                bytes => JsonDocument.ParseAsync(new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, bytes)));
         }
 
 
@@ -361,53 +359,52 @@ namespace System.Text.Json.Tests
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_SeekableStream_WithBOM(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_SeekableStream_WithBOM(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(new MemoryStream(Utf8Bom.Concat(bytes).ToArray())));
+                bytes => Task.FromResult(JsonDocument.Parse(new MemoryStream(Utf8Bom.Concat(bytes).ToArray()))));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_SeekableStream_Async_WithBOM(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_SeekableStream_Async_WithBOM(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.ParseAsync(new MemoryStream(Utf8Bom.Concat(bytes).ToArray())).GetAwaiter().GetResult());
+                bytes => JsonDocument.ParseAsync(new MemoryStream(Utf8Bom.Concat(bytes).ToArray())));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_UnseekableStream_WithBOM(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_UnseekableStream_WithBOM(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(
-                    new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, Utf8Bom.Concat(bytes).ToArray())));
+                bytes => Task.FromResult(JsonDocument.Parse(
+                    new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, Utf8Bom.Concat(bytes).ToArray()))));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_UnseekableStream_Async_WithBOM(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_UnseekableStream_Async_WithBOM(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
                 bytes => JsonDocument.ParseAsync(
-                        new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, Utf8Bom.Concat(bytes).ToArray())).
-                    GetAwaiter().GetResult());
+                        new WrappedMemoryStream(canRead: true, canWrite: false, canSeek: false, Utf8Bom.Concat(bytes).ToArray())));
         }
 
         [Fact]
@@ -486,34 +483,34 @@ namespace System.Text.Json.Tests
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_SequenceBytes_Single(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_SequenceBytes_Single(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(new ReadOnlySequence<byte>(bytes)));
+                bytes => Task.FromResult(JsonDocument.Parse(new ReadOnlySequence<byte>(bytes))));
         }
 
         [Theory]
         [MemberData(nameof(ReducedTestCases))]
-        public static void ParseJson_SequenceBytes_Multi(bool compactData, TestCaseType type, string jsonString)
+        public static async Task ParseJson_SequenceBytes_Multi(bool compactData, TestCaseType type, string jsonString)
         {
-            ParseJson(
+            await ParseJsonAsync(
                 compactData,
                 type,
                 jsonString,
                 null,
-                bytes => JsonDocument.Parse(JsonTestHelper.SegmentInto(bytes, 31)));
+                bytes => Task.FromResult(JsonDocument.Parse(JsonTestHelper.SegmentInto(bytes, 31))));
         }
 
-        private static void ParseJson(
+        private static async Task ParseJsonAsync(
             bool compactData,
             TestCaseType type,
             string jsonString,
-            Func<string, JsonDocument> stringDocBuilder,
-            Func<byte[], JsonDocument> bytesDocBuilder)
+            Func<string, Task<JsonDocument>> stringDocBuilder,
+            Func<byte[], Task<JsonDocument>> bytesDocBuilder)
         {
             // One, but not both, must be null.
             if ((stringDocBuilder == null) == (bytesDocBuilder == null))
@@ -527,7 +524,7 @@ namespace System.Text.Json.Tests
 
             byte[] dataUtf8 = Encoding.UTF8.GetBytes(jsonString);
 
-            using (JsonDocument doc = stringDocBuilder?.Invoke(jsonString) ?? bytesDocBuilder?.Invoke(dataUtf8))
+            using (JsonDocument doc = await (stringDocBuilder?.Invoke(jsonString) ?? bytesDocBuilder?.Invoke(dataUtf8)))
             {
                 Assert.NotNull(doc);
 
@@ -3650,7 +3647,7 @@ namespace System.Text.Json.Tests
         }
 
         [Fact]
-        public static void VerifyMultiThreadedDispose()
+        public static async Task VerifyMultiThreadedDispose()
         {
             Action<object> disposeAction = (object document) => ((JsonDocument)document).Dispose();
 
@@ -3669,7 +3666,7 @@ namespace System.Text.Json.Tests
                 }
             }
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
 
             // When ArrayPool gets corrupted, the Rent method might return an already rented array, which is incorrect.
             // So we will rent as many arrays as calls to JsonElement.Dispose and check they are unique.
index f18274b..96df1bb 100644 (file)
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
@@ -11,18 +11,18 @@ namespace System.Text.Json.Serialization.Tests
     public static class CacheTests
     {
         [Fact, OuterLoop]
-        public static void MultipleThreads_SameType_DifferentJson_Looping()
+        public static async Task MultipleThreads_SameType_DifferentJson_Looping()
         {
             const int Iterations = 100;
 
             for (int i = 0; i < Iterations; i++)
             {
-                MultipleThreads_SameType_DifferentJson();
+                await MultipleThreads_SameType_DifferentJson();
             }
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
-        public static void MultipleThreads_SameType_DifferentJson()
+        [Fact]
+        public static async Task MultipleThreads_SameType_DifferentJson()
         {
             // Use local options to avoid obtaining already cached metadata from the default options.
             var options = new JsonSerializerOptions();
@@ -69,22 +69,22 @@ namespace System.Text.Json.Serialization.Tests
                 tasks[i + 3] = Task.Run(() => SerializeObject());
             };
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
         [Fact, OuterLoop]
-        public static void MultipleThreads_DifferentTypes_Looping()
+        public static async Task MultipleThreads_DifferentTypes_Looping()
         {
             const int Iterations = 100;
 
             for (int i = 0; i < Iterations; i++)
             {
-                MultipleThreads_DifferentTypes();
+                await MultipleThreads_DifferentTypes();
             }
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
-        public static void MultipleThreads_DifferentTypes()
+        [Fact]
+        public static async Task MultipleThreads_DifferentTypes()
         {
             // Use local options to avoid obtaining already cached metadata from the default options.
             var options = new JsonSerializerOptions();
@@ -121,7 +121,7 @@ namespace System.Text.Json.Serialization.Tests
                 tasks[i + 1] = Task.Run(() => Test(TestClassCount - 2));
             }
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
         [Fact]
@@ -164,9 +164,9 @@ namespace System.Text.Json.Serialization.Tests
         // this options is not the default options instance the tests will not use previously cached metadata.
         private static JsonSerializerOptions s_options = new JsonSerializerOptions();
 
-        [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+        [Theory]
         [MemberData(nameof(WriteSuccessCases))]
-        public static void MultipleTypes(ITestClass testObj)
+        public static async Task MultipleTypes(ITestClass testObj)
         {
             Type type = testObj.GetType();
 
@@ -199,7 +199,7 @@ namespace System.Text.Json.Serialization.Tests
                 tasks[i + 1] = Task.Run(() => Serialize());
             };
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
         public static IEnumerable<object[]> WriteSuccessCases
index eaa0ccc..6082035 100644 (file)
@@ -1,6 +1,7 @@
 // Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
+using System.Threading.Tasks;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
@@ -8,152 +9,152 @@ namespace System.Text.Json.Serialization.Tests
     public abstract partial class ConstructorTests
     {
         [Fact]
-        public void NonPublicCtors_NotSupported()
+        public async Task NonPublicCtors_NotSupported()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
-                NotSupportedException ex = Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<T>("{}"));
+                NotSupportedException ex = await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<T>("{}"));
                 Assert.Contains("JsonConstructorAttribute", ex.ToString());
             }
 
-            RunTest<PrivateParameterlessCtor>();
-            RunTest<InternalParameterlessCtor>();
-            RunTest<ProtectedParameterlessCtor>();
-            RunTest<PrivateParameterizedCtor>();
-            RunTest<InternalParameterizedCtor>();
-            RunTest<ProtectedParameterizedCtor>();
-            RunTest<PrivateParameterizedCtor_WithAttribute>();
-            RunTest<InternalParameterizedCtor_WithAttribute>();
-            RunTest<ProtectedParameterizedCtor_WithAttribute>();
+            await RunTestAsync<PrivateParameterlessCtor>();
+            await RunTestAsync<InternalParameterlessCtor>();
+            await RunTestAsync<ProtectedParameterlessCtor>();
+            await RunTestAsync<PrivateParameterizedCtor>();
+            await RunTestAsync<InternalParameterizedCtor>();
+            await RunTestAsync<ProtectedParameterizedCtor>();
+            await RunTestAsync<PrivateParameterizedCtor_WithAttribute>();
+            await RunTestAsync<InternalParameterizedCtor_WithAttribute>();
+            await RunTestAsync<ProtectedParameterizedCtor_WithAttribute>();
         }
 
         [Fact]
-        public void SinglePublicParameterizedCtor_SingleParameterlessCtor_NoAttribute_Supported_UseParameterlessCtor()
+        public async Task SinglePublicParameterizedCtor_SingleParameterlessCtor_NoAttribute_Supported_UseParameterlessCtor()
         {
-            var obj1 = Serializer.Deserialize<SinglePublicParameterizedCtor>(@"{""MyInt"":1,""MyString"":""1""}");
+            var obj1 = await Serializer.DeserializeWrapper<SinglePublicParameterizedCtor>(@"{""MyInt"":1,""MyString"":""1""}");
             Assert.Equal(@"{""MyInt"":0,""MyString"":null}", JsonSerializer.Serialize(obj1));
         }
 
         [Fact]
-        public void MultiplePublicParameterizedCtors_SingleParameterlessCtor_NoAttribute_Supported_UseParameterlessCtor()
+        public async Task MultiplePublicParameterizedCtors_SingleParameterlessCtor_NoAttribute_Supported_UseParameterlessCtor()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
-                var obj1 = Serializer.Deserialize<T>(@"{""MyInt"":1,""MyString"":""1""}");
+                var obj1 = await Serializer.DeserializeWrapper<T>(@"{""MyInt"":1,""MyString"":""1""}");
                 Assert.Equal(@"{""MyInt"":0,""MyString"":null}", JsonSerializer.Serialize(obj1));
             }
 
-            RunTest<SingleParameterlessCtor_MultiplePublicParameterizedCtor>();
-            RunTest<SingleParameterlessCtor_MultiplePublicParameterizedCtor_Struct>();
+            await RunTestAsync<SingleParameterlessCtor_MultiplePublicParameterizedCtor>();
+            await RunTestAsync<SingleParameterlessCtor_MultiplePublicParameterizedCtor_Struct>();
         }
 
         [Fact]
-        public void SinglePublicParameterizedCtor_NoPublicParameterlessCtor_NoAttribute_Supported()
+        public async Task SinglePublicParameterizedCtor_NoPublicParameterlessCtor_NoAttribute_Supported()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
-                var obj1 = Serializer.Deserialize<T>(@"{""MyInt"":1}");
+                var obj1 = await Serializer.DeserializeWrapper<T>(@"{""MyInt"":1}");
                 Assert.Equal(@"{""MyInt"":1}", JsonSerializer.Serialize(obj1));
             }
 
-            RunTest<PublicParameterizedCtor>();
-            RunTest<PrivateParameterlessConstructor_PublicParameterizedCtor>();
+            await RunTestAsync<PublicParameterizedCtor>();
+            await RunTestAsync<PrivateParameterlessConstructor_PublicParameterizedCtor>();
         }
 
         [Fact]
-        public void SinglePublicParameterizedCtor_NoPublicParameterlessCtor_WithAttribute_Supported()
+        public async Task SinglePublicParameterizedCtor_NoPublicParameterlessCtor_WithAttribute_Supported()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
-                var obj1 = Serializer.Deserialize<T>(@"{""MyInt"":1}");
+                var obj1 = await Serializer.DeserializeWrapper<T>(@"{""MyInt"":1}");
                 Assert.Equal(@"{""MyInt"":1}", JsonSerializer.Serialize(obj1));
             }
 
-            RunTest<PublicParameterizedCtor_WithAttribute>();
-            RunTest<Struct_PublicParameterizedConstructor_WithAttribute>();
-            RunTest<PrivateParameterlessConstructor_PublicParameterizedCtor_WithAttribute>();
+            await RunTestAsync<PublicParameterizedCtor_WithAttribute>();
+            await RunTestAsync<Struct_PublicParameterizedConstructor_WithAttribute>();
+            await RunTestAsync<PrivateParameterlessConstructor_PublicParameterizedCtor_WithAttribute>();
         }
 
         [Fact]
-        public void Class_MultiplePublicParameterizedCtors_NoPublicParameterlessCtor_NoAttribute_NotSupported()
+        public Task Class_MultiplePublicParameterizedCtors_NoPublicParameterlessCtor_NoAttribute_NotSupported()
         {
-            Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<MultiplePublicParameterizedCtor>(@"{""MyInt"":1,""MyString"":""1""}"));
+            return Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<MultiplePublicParameterizedCtor>(@"{""MyInt"":1,""MyString"":""1""}"));
         }
 
         [Fact]
-        public void Struct_MultiplePublicParameterizedCtors_NoPublicParameterlessCtor_NoAttribute_Supported_UseParameterlessCtor()
+        public async Task Struct_MultiplePublicParameterizedCtors_NoPublicParameterlessCtor_NoAttribute_Supported_UseParameterlessCtor()
         {
-            var obj = Serializer.Deserialize<MultiplePublicParameterizedCtor_Struct>(@"{""myInt"":1,""myString"":""1""}");
+            var obj = await Serializer.DeserializeWrapper<MultiplePublicParameterizedCtor_Struct>(@"{""myInt"":1,""myString"":""1""}");
             Assert.Equal(0, obj.MyInt);
             Assert.Null(obj.MyString);
             Assert.Equal(@"{""MyInt"":0,""MyString"":null}", JsonSerializer.Serialize(obj));
         }
 
         [Fact]
-        public void NoPublicParameterlessCtor_MultiplePublicParameterizedCtors_WithAttribute_Supported()
+        public async Task NoPublicParameterlessCtor_MultiplePublicParameterizedCtors_WithAttribute_Supported()
         {
-            var obj1 = Serializer.Deserialize<MultiplePublicParameterizedCtor_WithAttribute>(@"{""MyInt"":1,""MyString"":""1""}");
+            var obj1 = await Serializer.DeserializeWrapper<MultiplePublicParameterizedCtor_WithAttribute>(@"{""MyInt"":1,""MyString"":""1""}");
             Assert.Equal(1, obj1.MyInt);
             Assert.Null(obj1.MyString);
             Assert.Equal(@"{""MyInt"":1,""MyString"":null}", JsonSerializer.Serialize(obj1));
 
-            var obj2 = Serializer.Deserialize<MultiplePublicParameterizedCtor_WithAttribute_Struct>(@"{""MyInt"":1,""MyString"":""1""}");
+            var obj2 = await Serializer.DeserializeWrapper<MultiplePublicParameterizedCtor_WithAttribute_Struct>(@"{""MyInt"":1,""MyString"":""1""}");
             Assert.Equal(1, obj2.MyInt);
             Assert.Equal("1", obj2.MyString);
             Assert.Equal(@"{""MyInt"":1,""MyString"":""1""}", JsonSerializer.Serialize(obj2));
         }
 
         [Fact]
-        public void PublicParameterlessCtor_MultiplePublicParameterizedCtors_WithAttribute_Supported()
+        public async Task PublicParameterlessCtor_MultiplePublicParameterizedCtors_WithAttribute_Supported()
         {
-            var obj = Serializer.Deserialize<ParameterlessCtor_MultiplePublicParameterizedCtor_WithAttribute>(@"{""MyInt"":1,""MyString"":""1""}");
+            var obj = await Serializer.DeserializeWrapper<ParameterlessCtor_MultiplePublicParameterizedCtor_WithAttribute>(@"{""MyInt"":1,""MyString"":""1""}");
             Assert.Equal(1, obj.MyInt);
             Assert.Null(obj.MyString);
             Assert.Equal(@"{""MyInt"":1,""MyString"":null}", JsonSerializer.Serialize(obj));
         }
 
         [Fact]
-        public void MultipleAttributes_NotSupported()
+        public async Task MultipleAttributes_NotSupported()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
-                Assert.Throws<InvalidOperationException>(() => Serializer.Deserialize<T>("{}"));
+                await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.DeserializeWrapper<T>("{}"));
             }
 
-            RunTest<MultiplePublicParameterizedCtor_WithMultipleAttributes>();
-            RunTest<PublicParameterlessConstructor_PublicParameterizedCtor_WithMultipleAttributes>();
-            RunTest<PrivateParameterlessCtor_InternalParameterizedCtor_WithMultipleAttributes>();
-            RunTest<ProtectedParameterlessCtor_PrivateParameterizedCtor_WithMultipleAttributes>();
-            RunTest<PublicParameterlessCtor_PrivateParameterizedCtor_WithMultipleAttributes>();
-            RunTest<PublicParameterizedCtor_PublicParameterizedCtor_WithMultipleAttributes>();
-            RunTest<Struct_PublicParameterizedCtor_PrivateParameterizedCtor_WithMultipleAttributes>();
-            RunTest<Point_2D_Struct_WithMultipleAttributes>();
-            RunTest<Point_2D_Struct_WithMultipleAttributes_OneNonPublic>();
+            await RunTestAsync<MultiplePublicParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<PublicParameterlessConstructor_PublicParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<PrivateParameterlessCtor_InternalParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<ProtectedParameterlessCtor_PrivateParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<PublicParameterlessCtor_PrivateParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<PublicParameterizedCtor_PublicParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<Struct_PublicParameterizedCtor_PrivateParameterizedCtor_WithMultipleAttributes>();
+            await RunTestAsync<Point_2D_Struct_WithMultipleAttributes>();
+            await RunTestAsync<Point_2D_Struct_WithMultipleAttributes_OneNonPublic>();
         }
 
         [Fact]
-        public void AttributeIgnoredOnIEnumerable()
+        public async Task AttributeIgnoredOnIEnumerable()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
-                Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<T>("[]"));
+                await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<T>("[]"));
             }
 
-            RunTest<Parameterized_StackWrapper>();
-            RunTest<Parameterized_WrapperForICollection>();
+            await RunTestAsync<Parameterized_StackWrapper>();
+            await RunTestAsync<Parameterized_WrapperForICollection>();
         }
 
         [Fact]
-        public void Struct_Use_DefaultCtor_ByDefault()
+        public async Task Struct_Use_DefaultCtor_ByDefault()
         {
             string json = @"{""X"":1,""Y"":2}";
 
             // By default, serializer uses default ctor to deserializer structs
-            var point1 = Serializer.Deserialize<Point_2D_Struct>(json);
+            var point1 = await Serializer.DeserializeWrapper<Point_2D_Struct>(json);
             Assert.Equal(0, point1.X);
             Assert.Equal(0, point1.Y);
 
-            var point2 = Serializer.Deserialize<Point_2D_Struct_WithAttribute>(json);
+            var point2 = await Serializer.DeserializeWrapper<Point_2D_Struct_WithAttribute>(json);
             Assert.Equal(1, point2.X);
             Assert.Equal(2, point2.Y);
         }
index b37759f..369bc77 100644 (file)
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Reflection;
@@ -9,46 +9,47 @@ namespace System.Text.Json.Serialization.Tests
 {
     public abstract partial class ConstructorTests
     {
-        [Fact, OuterLoop]
-        public void MultipleThreadsLooping()
+        [Fact]
+        [OuterLoop]
+        public async Task MultipleThreadsLooping()
         {
             const int Iterations = 100;
 
             for (int i = 0; i < Iterations; i++)
             {
-                MultipleThreads();
+                await MultipleThreads();
             }
         }
 
         [Fact]
-        public void MultipleThreads()
+        public async Task MultipleThreads()
         {
             // Verify the test class has >32 properties since that is a threshold for using the fallback dictionary.
             Assert.True(typeof(ClassWithConstructor_SimpleAndComplexParameters).GetProperties(BindingFlags.Instance | BindingFlags.Public).Length > 32);
 
-            void DeserializeObject(string json, Type type, JsonSerializerOptions options)
+            async Task DeserializeObjectAsync(string json, Type type, JsonSerializerOptions options)
             {
-                var obj = Serializer.Deserialize(json, type, options);
+                var obj = await Serializer.DeserializeWrapper(json, type, options);
                 ((ITestClassWithParameterizedCtor)obj).Verify();
             }
 
-            void DeserializeObjectMinimal(Type type, JsonSerializerOptions options)
+            async Task DeserializeObjectMinimalAsync(Type type, JsonSerializerOptions options)
             {
                 string json = (string)type.GetProperty("s_json_minimal").GetValue(null);
-                var obj = Serializer.Deserialize(json, type, options);
+                var obj = await Serializer.DeserializeWrapper(json, type, options);
                 ((ITestClassWithParameterizedCtor)obj).VerifyMinimal();
             };
 
-            void DeserializeObjectFlipped(Type type, JsonSerializerOptions options)
+            async Task DeserializeObjectFlippedAsync(Type type, JsonSerializerOptions options)
             {
                 string json = (string)type.GetProperty("s_json_flipped").GetValue(null);
-                DeserializeObject(json, type, options);
+                await DeserializeObjectAsync(json, type, options);
             };
 
-            void DeserializeObjectNormal(Type type, JsonSerializerOptions options)
+            async Task DeserializeObjectNormalAsync(Type type, JsonSerializerOptions options)
             {
                 string json = (string)type.GetProperty("s_json").GetValue(null);
-                DeserializeObject(json, type, options);
+                await DeserializeObjectAsync(json, type, options);
             };
 
             void SerializeObject(Type type, JsonSerializerOptions options)
@@ -57,7 +58,7 @@ namespace System.Text.Json.Serialization.Tests
                 JsonSerializer.Serialize(obj, options);
             };
 
-            void RunTest(Type type)
+            async Task RunTestAsync(Type type)
             {
                 // Use local options to avoid obtaining already cached metadata from the default options.
                 var options = new JsonSerializerOptions();
@@ -69,41 +70,41 @@ namespace System.Text.Json.Serialization.Tests
                 for (int i = 0; i < tasks.Length; i += ConcurrentTestsCount)
                 {
                     // Create race condition to populate the sorted property cache with different json ordering.
-                    tasks[i + 0] = Task.Run(() => DeserializeObjectMinimal(type, options));
-                    tasks[i + 1] = Task.Run(() => DeserializeObjectFlipped(type, options));
-                    tasks[i + 2] = Task.Run(() => DeserializeObjectNormal(type, options));
+                    tasks[i + 0] = Task.Run(() => DeserializeObjectMinimalAsync(type, options));
+                    tasks[i + 1] = Task.Run(() => DeserializeObjectFlippedAsync(type, options));
+                    tasks[i + 2] = Task.Run(() => DeserializeObjectNormalAsync(type, options));
 
                     // Ensure no exceptions on serialization
                     tasks[i + 3] = Task.Run(() => SerializeObject(type, options));
                 };
 
-                Task.WaitAll(tasks);
+                await Task.WhenAll(tasks);
             }
 
-            RunTest(typeof(ClassWithConstructor_SimpleAndComplexParameters));
-            RunTest(typeof(Person_Class));
-            RunTest(typeof(Parameterized_Class_With_ComplexTuple));
+            await RunTestAsync(typeof(ClassWithConstructor_SimpleAndComplexParameters));
+            await RunTestAsync(typeof(Person_Class));
+            await RunTestAsync(typeof(Parameterized_Class_With_ComplexTuple));
         }
 
         [Fact]
-        public void PropertyCacheWithMinInputsFirst()
+        public async Task PropertyCacheWithMinInputsFirst()
         {
             // Use local options to avoid obtaining already cached metadata from the default options.
             var options = new JsonSerializerOptions();
 
             string json = "{}";
-            Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
+            await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
 
             ClassWithConstructor_SimpleAndComplexParameters testObj = ClassWithConstructor_SimpleAndComplexParameters.GetInstance();
             testObj.Verify();
 
             json = JsonSerializer.Serialize(testObj, options);
-            testObj = Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
+            testObj = await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
             testObj.Verify();
         }
 
         [Fact]
-        public void PropertyCacheWithMinInputsLast()
+        public async Task PropertyCacheWithMinInputsLast()
         {
             // Use local options to avoid obtaining already cached metadata from the default options.
             var options = new JsonSerializerOptions();
@@ -112,11 +113,11 @@ namespace System.Text.Json.Serialization.Tests
             testObj.Verify();
 
             string json = JsonSerializer.Serialize(testObj, options);
-            testObj = Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
+            testObj = await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
             testObj.Verify();
 
             json = "{}";
-            Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
+            await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(json, options);
         }
 
         // Use a common options instance to encourage additional metadata collisions across types. Also since
@@ -124,7 +125,7 @@ namespace System.Text.Json.Serialization.Tests
         private JsonSerializerOptions s_options = new JsonSerializerOptions();
 
         [Fact]
-        public void MultipleTypes()
+        public async Task MultipleTypes()
         {
             void Serialize<T>(object[] args)
             {
@@ -136,15 +137,15 @@ namespace System.Text.Json.Serialization.Tests
                 string json = JsonSerializer.Serialize(localTestObj, s_options);
             };
 
-            void Deserialize<T>(string json)
+            async Task DeserializeAsync<T>(string json)
             {
-                ITestClass obj = (ITestClass)Serializer.Deserialize<T>(json, s_options);
+                ITestClass obj = (ITestClass)await Serializer.DeserializeWrapper<T>(json, s_options);
                 obj.Verify();
             };
 
-            void RunTest<T>(T testObj, object[] args)
+            async Task RunTestAsync<T>(T testObj, object[] args)
             {
-                // Get the test json with the default options to avoid cache pollution of Deserialize() below.
+                // Get the test json with the default options to avoid cache pollution of DeserializeAsync() below.
                 ((ITestClass)testObj).Initialize();
                 ((ITestClass)testObj).Verify();
                 string json = JsonSerializer.Serialize(testObj);
@@ -155,20 +156,20 @@ namespace System.Text.Json.Serialization.Tests
 
                 for (int i = 0; i < tasks.Length; i += ConcurrentTestsCount)
                 {
-                    tasks[i + 0] = Task.Run(() => Deserialize<T>(json));
+                    tasks[i + 0] = Task.Run(() => DeserializeAsync<T>(json));
                     tasks[i + 1] = Task.Run(() => Serialize<T>(args));
                 };
 
-                Task.WaitAll(tasks);
+                await Task.WhenAll(tasks);
             }
 
-            RunTest<Point_2D>(new Point_2D(1, 2), new object[] { 1, 2 });
-            RunTest(new Point_3D(1, 2, 3), new object[] { 1, 2, 3 });
-            RunTest(new Point_2D_With_ExtData(1, 2), new object[] { 1, 2 });
+            await RunTestAsync<Point_2D>(new Point_2D(1, 2), new object[] { 1, 2 });
+            await RunTestAsync(new Point_3D(1, 2, 3), new object[] { 1, 2, 3 });
+            await RunTestAsync(new Point_2D_With_ExtData(1, 2), new object[] { 1, 2 });
 
             Guid id = Guid.Parse("270bb22b-4816-4bd9-9acd-8ec5b1a896d3");
-            RunTest(new Parameterized_Person_Simple(id), new object[] { id });
-            RunTest(new Point_MembersHave_JsonPropertyName(1, 2), new object[] { 1, 2 });
+            await RunTestAsync(new Parameterized_Person_Simple(id), new object[] { id });
+            await RunTestAsync(new Point_MembersHave_JsonPropertyName(1, 2), new object[] { 1, 2 });
         }
     }
 }
index 0b398f3..9f1a85e 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
@@ -9,10 +10,10 @@ namespace System.Text.Json.Serialization.Tests
     public abstract partial class ConstructorTests
     {
         [Fact]
-        public void MultipleProperties_Cannot_BindTo_TheSame_ConstructorParameter()
+        public async Task MultipleProperties_Cannot_BindTo_TheSame_ConstructorParameter()
         {
-            InvalidOperationException ex = Assert.Throws<InvalidOperationException>(
-                () => Serializer.Deserialize<Point_MultipleMembers_BindTo_OneConstructorParameter>("{}"));
+            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(
+                () => Serializer.DeserializeWrapper<Point_MultipleMembers_BindTo_OneConstructorParameter>("{}"));
 
             string exStr = ex.ToString();
             Assert.Contains("'X'", exStr);
@@ -20,8 +21,8 @@ namespace System.Text.Json.Serialization.Tests
             Assert.Contains("(Int32, Int32)", exStr);
             Assert.Contains("System.Text.Json.Serialization.Tests.Point_MultipleMembers_BindTo_OneConstructorParameter", exStr);
 
-            ex = Assert.Throws<InvalidOperationException>(
-                () => Serializer.Deserialize<Point_MultipleMembers_BindTo_OneConstructorParameter_Variant>("{}"));
+            ex = await Assert.ThrowsAsync<InvalidOperationException>(
+                () => Serializer.DeserializeWrapper<Point_MultipleMembers_BindTo_OneConstructorParameter_Variant>("{}"));
 
             exStr = ex.ToString();
             Assert.Contains("'X'", exStr);
@@ -31,35 +32,35 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void All_ConstructorParameters_MustBindTo_ObjectMembers()
+        public async Task All_ConstructorParameters_MustBindTo_ObjectMembers()
         {
-            InvalidOperationException ex = Assert.Throws<InvalidOperationException>(
-                () => Serializer.Deserialize<Point_Without_Members>("{}"));
+            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(
+                () => Serializer.DeserializeWrapper<Point_Without_Members>("{}"));
 
             string exStr = ex.ToString();
             Assert.Contains("(Int32, Int32)", exStr);
             Assert.Contains("System.Text.Json.Serialization.Tests.Point_Without_Members", exStr);
 
-            ex = Assert.Throws<InvalidOperationException>(
-                () => Serializer.Deserialize<Point_With_MismatchedMembers>("{}"));
+            ex = await Assert.ThrowsAsync<InvalidOperationException>(
+                () => Serializer.DeserializeWrapper<Point_With_MismatchedMembers>("{}"));
             exStr = ex.ToString();
             Assert.Contains("(Int32, Int32)", exStr);
             Assert.Contains("System.Text.Json.Serialization.Tests.Point_With_MismatchedMembers", exStr);
 
-            ex = Assert.Throws<InvalidOperationException>(
-                () => Serializer.Deserialize<WrapperFor_Point_With_MismatchedMembers>(@"{""MyInt"":1,""MyPoint"":{}}"));
+            ex = await Assert.ThrowsAsync<InvalidOperationException>(
+                () => Serializer.DeserializeWrapper<WrapperFor_Point_With_MismatchedMembers>(@"{""MyInt"":1,""MyPoint"":{}}"));
             exStr = ex.ToString();
             Assert.Contains("(Int32, Int32)", exStr);
             Assert.Contains("System.Text.Json.Serialization.Tests.Point_With_MismatchedMembers", exStr);
         }
 
         [Fact]
-        public void LeadingReferenceMetadataNotSupported()
+        public async Task LeadingReferenceMetadataNotSupported()
         {
             string json = @"{""$id"":""1"",""Name"":""Jet"",""Manager"":{""$ref"":""1""}}";
 
             // Metadata ignored by default.
-            var employee = Serializer.Deserialize<Employee>(json);
+            var employee = await Serializer.DeserializeWrapper<Employee>(json);
 
             Assert.Equal("Jet", employee.Name);
             Assert.Null(employee.Manager.Name); ;
@@ -69,8 +70,8 @@ namespace System.Text.Json.Serialization.Tests
 
             var options = new JsonSerializerOptions { ReferenceHandler = ReferenceHandler.Preserve };
 
-            NotSupportedException ex = Assert.Throws<NotSupportedException>(
-                () => Serializer.Deserialize<Employee>(json, options));
+            NotSupportedException ex = await Assert.ThrowsAsync<NotSupportedException>(
+                () => Serializer.DeserializeWrapper<Employee>(json, options));
 
             string exStr = ex.ToString();
             Assert.Contains("System.Text.Json.Serialization.Tests.ConstructorTests+Employee", exStr);
@@ -89,7 +90,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void RandomReferenceMetadataNotSupported()
+        public async Task RandomReferenceMetadataNotSupported()
         {
             string json = @"{""Name"":""Jet"",""$random"":10}";
 
@@ -103,16 +104,16 @@ namespace System.Text.Json.Serialization.Tests
 
             var options = new JsonSerializerOptions { ReferenceHandler = ReferenceHandler.Preserve };
 
-            NotSupportedException ex = Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<Employee>(json, options));
+            NotSupportedException ex = await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<Employee>(json, options));
             string exStr = ex.ToString();
             Assert.Contains("System.Text.Json.Serialization.Tests.ConstructorTests+Employee", exStr);
             Assert.Contains("$.$random", exStr);
         }
 
         [Fact]
-        public void ExtensionDataProperty_CannotBindTo_CtorParam()
+        public async Task ExtensionDataProperty_CannotBindTo_CtorParam()
         {
-            InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => Serializer.Deserialize<Class_ExtData_CtorParam>("{}"));
+            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.DeserializeWrapper<Class_ExtData_CtorParam>("{}"));
             string exStr = ex.ToString();
             Assert.Contains("System.Collections.Generic.Dictionary`2[System.String,System.Text.Json.JsonElement] ExtensionData", exStr);
             Assert.Contains("System.Text.Json.Serialization.Tests.ConstructorTests+Class_ExtData_CtorParam", exStr);
@@ -142,7 +143,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void DeserializePathForObjectFails()
+        public async Task DeserializePathForObjectFails()
         {
             const string GoodJson = "{\"Property\u04671\":1}";
             const string GoodJsonEscaped = "{\"Property\\u04671\":1}";
@@ -153,19 +154,19 @@ namespace System.Text.Json.Serialization.Tests
             ClassWithUnicodePropertyName obj;
 
             // Baseline.
-            obj = Serializer.Deserialize<ClassWithUnicodePropertyName>(GoodJson);
+            obj = await Serializer.DeserializeWrapper<ClassWithUnicodePropertyName>(GoodJson);
             Assert.Equal(1, obj.Property\u04671);
 
-            obj = Serializer.Deserialize<ClassWithUnicodePropertyName>(GoodJsonEscaped);
+            obj = await Serializer.DeserializeWrapper<ClassWithUnicodePropertyName>(GoodJsonEscaped);
             Assert.Equal(1, obj.Property\u04671);
 
             JsonException e;
 
             // Exception.
-            e = Assert.Throws<JsonException>(() => Serializer.Deserialize<ClassWithUnicodePropertyName>(BadJson));
+            e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<ClassWithUnicodePropertyName>(BadJson));
             Assert.Equal(Expected, e.Path);
 
-            e = Assert.Throws<JsonException>(() => Serializer.Deserialize<ClassWithUnicodePropertyName>(BadJsonEscaped));
+            e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<ClassWithUnicodePropertyName>(BadJsonEscaped));
             Assert.Equal(Expected, e.Path);
         }
 
@@ -180,9 +181,9 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void PathForChildPropertyFails()
+        public async Task PathForChildPropertyFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<RootClass>(@"{""Child"":{""MyInt"":bad]}"));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<RootClass>(@"{""Child"":{""MyInt"":bad]}"));
             Assert.Equal("$.Child.MyInt", e.Path);
         }
 
@@ -205,37 +206,37 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void PathForChildListFails()
+        public async Task PathForChildListFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<RootClass>(@"{""Child"":{""MyIntArray"":[1, bad]}"));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<RootClass>(@"{""Child"":{""MyIntArray"":[1, bad]}"));
             Assert.Contains("$.Child.MyIntArray", e.Path);
         }
 
         [Fact]
-        public void PathForChildDictionaryFails()
+        public async Task PathForChildDictionaryFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<RootClass>(@"{""Child"":{""MyDictionary"":{""Key"": bad]"));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<RootClass>(@"{""Child"":{""MyDictionary"":{""Key"": bad]"));
             Assert.Equal("$.Child.MyDictionary.Key", e.Path);
         }
 
         [Fact]
-        public void PathForSpecialCharacterFails()
+        public async Task PathForSpecialCharacterFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<RootClass>(@"{""Child"":{""MyDictionary"":{""Key1"":{""Children"":[{""MyDictionary"":{""K.e.y"":"""));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<RootClass>(@"{""Child"":{""MyDictionary"":{""Key1"":{""Children"":[{""MyDictionary"":{""K.e.y"":"""));
             Assert.Equal("$.Child.MyDictionary.Key1.Children[0].MyDictionary['K.e.y']", e.Path);
         }
 
         [Fact]
-        public void PathForSpecialCharacterNestedFails()
+        public async Task PathForSpecialCharacterNestedFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<RootClass>(@"{""Child"":{""Children"":[{}, {""MyDictionary"":{""K.e.y"": {""MyInt"":bad"));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<RootClass>(@"{""Child"":{""Children"":[{}, {""MyDictionary"":{""K.e.y"": {""MyInt"":bad"));
             Assert.Equal("$.Child.Children[1].MyDictionary['K.e.y'].MyInt", e.Path);
         }
 
         [Fact]
-        public void EscapingFails()
+        public async Task EscapingFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<Parameterized_ClassWithUnicodeProperty>("{\"A\u0467\":bad}"));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Parameterized_ClassWithUnicodeProperty>("{\"A\u0467\":bad}"));
             Assert.Equal("$.A\u0467", e.Path);
         }
 
@@ -251,9 +252,9 @@ namespace System.Text.Json.Serialization.Tests
 
         [Fact]
         [ActiveIssue("JsonElement needs to support Path")]
-        public void ExtensionPropertyRoundTripFails()
+        public async Task ExtensionPropertyRoundTripFails()
         {
-            JsonException e = Assert.Throws<JsonException>(() => Serializer.Deserialize<Parameterized_ClassWithExtensionProperty>(@"{""MyNestedClass"":{""UnknownProperty"":bad}}"));
+            JsonException e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Parameterized_ClassWithExtensionProperty>(@"{""MyNestedClass"":{""UnknownProperty"":bad}}"));
             Assert.Equal("$.MyNestedClass.UnknownProperty", e.Path);
         }
 
@@ -273,43 +274,43 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void CaseInsensitiveFails()
+        public async Task CaseInsensitiveFails()
         {
             var options = new JsonSerializerOptions();
             options.PropertyNameCaseInsensitive = true;
 
             // Baseline (no exception)
             {
-                var obj = Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(@"{""mydecimal"":1}", options);
+                var obj = await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(@"{""mydecimal"":1}", options);
                 Assert.Equal(1, obj.MyDecimal);
             }
 
             {
-                var obj = Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(@"{""MYDECIMAL"":1}", options);
+                var obj = await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(@"{""MYDECIMAL"":1}", options);
                 Assert.Equal(1, obj.MyDecimal);
             }
 
             JsonException e;
 
-            e = Assert.Throws<JsonException>(() => Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(@"{""mydecimal"":bad}", options));
+            e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(@"{""mydecimal"":bad}", options));
             Assert.Equal("$.mydecimal", e.Path);
 
-            e = Assert.Throws<JsonException>(() => Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(@"{""MYDECIMAL"":bad}", options));
+            e = await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(@"{""MYDECIMAL"":bad}", options));
             Assert.Equal("$.MYDECIMAL", e.Path);
         }
 
         [Fact]
-        public void ClassWithUnsupportedCollectionTypes()
+        public async Task ClassWithUnsupportedCollectionTypes()
         {
             Exception e;
 
-            e = Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<ClassWithInvalidArray>(@"{""UnsupportedArray"":[]}"));
+            e = await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<ClassWithInvalidArray>(@"{""UnsupportedArray"":[]}"));
             Assert.Contains("System.Int32[,]", e.ToString());
             // The exception for element types do not contain the parent type and the property name
             // since the verification occurs later and is no longer bound to the parent type.
             Assert.DoesNotContain("ClassWithInvalidArray.UnsupportedArray", e.ToString());
 
-            e = Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<ClassWithInvalidDictionary>(@"{""UnsupportedDictionary"":{}}"));
+            e = await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<ClassWithInvalidDictionary>(@"{""UnsupportedDictionary"":{}}"));
             Assert.Contains("System.Int32[,]", e.ToString());
             Assert.DoesNotContain("ClassWithInvalidDictionary.UnsupportedDictionary", e.ToString());
         }
index 1b7fb7c..7cf5745 100644 (file)
@@ -1,8 +1,9 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
 using System.Collections.Specialized;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
@@ -27,191 +28,191 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void ReturnNullForNullObjects()
+        public async Task ReturnNullForNullObjects()
         {
-            Assert.Null(Serializer.Deserialize<Point_2D>("null"));
-            Assert.Null(Serializer.Deserialize<Point_3D>("null"));
+            Assert.Null(await Serializer.DeserializeWrapper<Point_2D>("null"));
+            Assert.Null(await Serializer.DeserializeWrapper<Point_3D>("null"));
         }
 
         [Fact]
-        public void JsonExceptionWhenAssigningNullToStruct()
+        public Task JsonExceptionWhenAssigningNullToStruct()
         {
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D_With_ExtData>("null"));
+            return Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D_With_ExtData>("null"));
         }
 
         [Fact]
-        public void MatchJsonPropertyToConstructorParameters()
+        public async Task MatchJsonPropertyToConstructorParameters()
         {
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{""X"":1,""Y"":2}");
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{""X"":1,""Y"":2}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""Y"":2,""X"":1}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""Y"":2,""X"":1}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
         }
 
         [Fact]
-        public void UseDefaultValues_When_NoJsonMatch()
+        public async Task UseDefaultValues_When_NoJsonMatch()
         {
             // Using CLR value when `ParameterInfo.DefaultValue` is not set.
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{""x"":1,""y"":2}");
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{""x"":1,""y"":2}");
             Assert.Equal(0, point.X);
             Assert.Equal(0, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""y"":2,""x"":1}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""y"":2,""x"":1}");
             Assert.Equal(0, point.X);
             Assert.Equal(0, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""x"":1,""Y"":2}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""x"":1,""Y"":2}");
             Assert.Equal(0, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""y"":2,""X"":1}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""y"":2,""X"":1}");
             Assert.Equal(1, point.X);
             Assert.Equal(0, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""X"":1}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""X"":1}");
             Assert.Equal(1, point.X);
             Assert.Equal(0, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""Y"":2}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""Y"":2}");
             Assert.Equal(0, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""X"":1}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""X"":1}");
             Assert.Equal(1, point.X);
             Assert.Equal(0, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""Y"":2}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""Y"":2}");
             Assert.Equal(0, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{}");
             Assert.Equal(0, point.X);
             Assert.Equal(0, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""a"":1,""b"":2}");
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""a"":1,""b"":2}");
             Assert.Equal(0, point.X);
             Assert.Equal(0, point.Y);
 
             // Using `ParameterInfo.DefaultValue` when set; using CLR value as fallback.
-            Point_3D point3d = Serializer.Deserialize<Point_3D>(@"{""X"":1}");
+            Point_3D point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""X"":1}");
             Assert.Equal(1, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(50, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""y"":2}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""y"":2}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(50, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""Z"":3}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""Z"":3}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(3, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""X"":1}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""X"":1}");
             Assert.Equal(1, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(50, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""Y"":2}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""Y"":2}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(2, point3d.Y);
             Assert.Equal(50, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""Z"":3}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""Z"":3}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(3, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""x"":1,""Y"":2}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""x"":1,""Y"":2}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(2, point3d.Y);
             Assert.Equal(50, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""Z"":3,""y"":2}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""Z"":3,""y"":2}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(3, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""x"":1,""Z"":3}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""x"":1,""Z"":3}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(3, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(50, point3d.Z);
 
-            point3d = Serializer.Deserialize<Point_3D>(@"{""a"":1,""b"":2}");
+            point3d = await Serializer.DeserializeWrapper<Point_3D>(@"{""a"":1,""b"":2}");
             Assert.Equal(0, point3d.X);
             Assert.Equal(0, point3d.Y);
             Assert.Equal(50, point3d.Z);
         }
 
         [Fact]
-        public void CaseInsensitivityWorks()
+        public async Task CaseInsensitivityWorks()
         {
             var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
 
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{""x"":1,""y"":2}", options);
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{""x"":1,""y"":2}", options);
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""y"":2,""x"":1}", options);
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""y"":2,""x"":1}", options);
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""x"":1,""Y"":2}", options);
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""x"":1,""Y"":2}", options);
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
 
-            point = Serializer.Deserialize<Point_2D>(@"{""y"":2,""X"":1}", options);
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""y"":2,""X"":1}", options);
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
         }
 
         [Fact]
-        public void VaryingOrderingOfJson()
+        public async Task VaryingOrderingOfJson()
         {
-            Point_3D point = Serializer.Deserialize<Point_3D>(@"{""X"":1,""Y"":2,""Z"":3}");
+            Point_3D point = await Serializer.DeserializeWrapper<Point_3D>(@"{""X"":1,""Y"":2,""Z"":3}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(3, point.Z);
 
-            point = Serializer.Deserialize<Point_3D>(@"{""X"":1,""Z"":3,""Y"":2}");
+            point = await Serializer.DeserializeWrapper<Point_3D>(@"{""X"":1,""Z"":3,""Y"":2}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(3, point.Z);
 
-            point = Serializer.Deserialize<Point_3D>(@"{""Y"":2,""Z"":3,""X"":1}");
+            point = await Serializer.DeserializeWrapper<Point_3D>(@"{""Y"":2,""Z"":3,""X"":1}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(3, point.Z);
 
-            point = Serializer.Deserialize<Point_3D>(@"{""Y"":2,""X"":1,""Z"":3}");
+            point = await Serializer.DeserializeWrapper<Point_3D>(@"{""Y"":2,""X"":1,""Z"":3}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(3, point.Z);
 
-            point = Serializer.Deserialize<Point_3D>(@"{""Z"":3,""Y"":2,""X"":1}");
+            point = await Serializer.DeserializeWrapper<Point_3D>(@"{""Z"":3,""Y"":2,""X"":1}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(3, point.Z);
 
-            point = Serializer.Deserialize<Point_3D>(@"{""Z"":3,""X"":1,""Y"":2}");
+            point = await Serializer.DeserializeWrapper<Point_3D>(@"{""Z"":3,""X"":1,""Y"":2}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(3, point.Z);
         }
 
         [Fact]
-        public void AsListElement()
+        public async Task AsListElement()
         {
-            List<Point_3D> list = Serializer.Deserialize<List<Point_3D>>(@"[{""Y"":2,""Z"":3,""X"":1},{""Z"":10,""Y"":30,""X"":20}]");
+            List<Point_3D> list = await Serializer.DeserializeWrapper<List<Point_3D>>(@"[{""Y"":2,""Z"":3,""X"":1},{""Z"":10,""Y"":30,""X"":20}]");
             Assert.Equal(1, list[0].X);
             Assert.Equal(2, list[0].Y);
             Assert.Equal(3, list[0].Z);
@@ -221,9 +222,9 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void AsDictionaryValue()
+        public async Task AsDictionaryValue()
         {
-            Dictionary<string, Point_3D> dict = Serializer.Deserialize<Dictionary<string, Point_3D>>(@"{""0"":{""Y"":2,""Z"":3,""X"":1},""1"":{""Z"":10,""Y"":30,""X"":20}}");
+            Dictionary<string, Point_3D> dict = await Serializer.DeserializeWrapper<Dictionary<string, Point_3D>>(@"{""0"":{""Y"":2,""Z"":3,""X"":1},""1"":{""Z"":10,""Y"":30,""X"":20}}");
             Assert.Equal(1, dict["0"].X);
             Assert.Equal(2, dict["0"].Y);
             Assert.Equal(3, dict["0"].Z);
@@ -233,9 +234,9 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void AsProperty_Of_ObjectWithParameterlessCtor()
+        public async Task AsProperty_Of_ObjectWithParameterlessCtor()
         {
-            WrapperForPoint_3D obj = Serializer.Deserialize<WrapperForPoint_3D>(@"{""Point_3D"":{""Y"":2,""Z"":3,""X"":1}}");
+            WrapperForPoint_3D obj = await Serializer.DeserializeWrapper<WrapperForPoint_3D>(@"{""Point_3D"":{""Y"":2,""Z"":3,""X"":1}}");
             Point_3D point = obj.Point_3D;
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
@@ -243,9 +244,9 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void AsProperty_Of_ObjectWithParameterizedCtor()
+        public async Task AsProperty_Of_ObjectWithParameterizedCtor()
         {
-            ClassWrapperForPoint_3D obj = Serializer.Deserialize<ClassWrapperForPoint_3D>(@"{""Point3D"":{""Y"":2,""Z"":3,""X"":1}}");
+            ClassWrapperForPoint_3D obj = await Serializer.DeserializeWrapper<ClassWrapperForPoint_3D>(@"{""Point3D"":{""Y"":2,""Z"":3,""X"":1}}");
             Point_3D point = obj.Point3D;
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
@@ -253,28 +254,28 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void At_Symbol_As_ParameterNamePrefix()
+        public async Task At_Symbol_As_ParameterNamePrefix()
         {
-            ClassWrapper_For_Int_String obj = Serializer.Deserialize<ClassWrapper_For_Int_String>(@"{""Int"":1,""String"":""1""}");
+            ClassWrapper_For_Int_String obj = await Serializer.DeserializeWrapper<ClassWrapper_For_Int_String>(@"{""Int"":1,""String"":""1""}");
             Assert.Equal(1, obj.Int);
             Assert.Equal("1", obj.String);
         }
 
         [Fact]
-        public void At_Symbol_As_ParameterNamePrefix_UseDefaultValues()
+        public async Task At_Symbol_As_ParameterNamePrefix_UseDefaultValues()
         {
-            ClassWrapper_For_Int_String obj = Serializer.Deserialize<ClassWrapper_For_Int_String>(@"{""@Int"":1,""@String"":""1""}");
+            ClassWrapper_For_Int_String obj = await Serializer.DeserializeWrapper<ClassWrapper_For_Int_String>(@"{""@Int"":1,""@String"":""1""}");
             Assert.Equal(0, obj.Int);
             Assert.Null(obj.String);
         }
 
         [Fact]
-        public void PassDefaultValueToComplexStruct()
+        public async Task PassDefaultValueToComplexStruct()
         {
-            ClassWrapperForPoint_3D obj = Serializer.Deserialize<ClassWrapperForPoint_3D>(@"{}");
+            ClassWrapperForPoint_3D obj = await Serializer.DeserializeWrapper<ClassWrapperForPoint_3D>(@"{}");
             Assert.True(obj.Point3D == default);
 
-            ClassWrapper_For_Int_Point_3D_String obj1 = Serializer.Deserialize<ClassWrapper_For_Int_Point_3D_String>(@"{}");
+            ClassWrapper_For_Int_Point_3D_String obj1 = await Serializer.DeserializeWrapper<ClassWrapper_For_Int_Point_3D_String>(@"{}");
             Assert.Equal(0, obj1.MyInt);
             Assert.Equal(0, obj1.MyPoint3DStruct.X);
             Assert.Equal(0, obj1.MyPoint3DStruct.Y);
@@ -283,9 +284,9 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void Null_AsArgument_To_ParameterThat_CanBeNull()
+        public async Task Null_AsArgument_To_ParameterThat_CanBeNull()
         {
-            ClassWrapper_For_Int_Point_3D_String obj1 = Serializer.Deserialize<ClassWrapper_For_Int_Point_3D_String>(@"{""MyInt"":1,""MyPoint3DStruct"":{},""MyString"":null}");
+            ClassWrapper_For_Int_Point_3D_String obj1 = await Serializer.DeserializeWrapper<ClassWrapper_For_Int_Point_3D_String>(@"{""MyInt"":1,""MyPoint3DStruct"":{},""MyString"":null}");
             Assert.Equal(1, obj1.MyInt);
             Assert.Equal(0, obj1.MyPoint3DStruct.X);
             Assert.Equal(0, obj1.MyPoint3DStruct.Y);
@@ -294,90 +295,90 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void Null_AsArgument_To_ParameterThat_CanNotBeNull()
+        public async Task Null_AsArgument_To_ParameterThat_CanNotBeNull()
         {
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<ClassWrapper_For_Int_Point_3D_String>(@"{""MyInt"":null,""MyString"":""1""}"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<ClassWrapper_For_Int_Point_3D_String>(@"{""MyPoint3DStruct"":null,""MyString"":""1""}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<ClassWrapper_For_Int_Point_3D_String>(@"{""MyInt"":null,""MyString"":""1""}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<ClassWrapper_For_Int_Point_3D_String>(@"{""MyPoint3DStruct"":null,""MyString"":""1""}"));
         }
 
         [Fact]
-        public void OtherPropertiesAreSet()
+        public async Task OtherPropertiesAreSet()
         {
-            var personClass = Serializer.Deserialize<Person_Class>(Person_Class.s_json);
+            var personClass = await Serializer.DeserializeWrapper<Person_Class>(Person_Class.s_json);
             personClass.Verify();
 
-            var personStruct = Serializer.Deserialize<Person_Struct>(Person_Struct.s_json);
+            var personStruct = await Serializer.DeserializeWrapper<Person_Struct>(Person_Struct.s_json);
             personStruct.Verify();
         }
 
         [Fact]
-        public void ExtraProperties_AreIgnored()
+        public async Task ExtraProperties_AreIgnored()
         {
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{ ""x"":1,""y"":2,""b"":3}");
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{ ""x"":1,""y"":2,""b"":3}");
             Assert.Equal(0, point.X);
             Assert.Equal(0, point.Y);
         }
 
         [Fact]
-        public void ExtraProperties_GoInExtensionData_IfPresent()
+        public async Task ExtraProperties_GoInExtensionData_IfPresent()
         {
-            Point_2D_With_ExtData point = Serializer.Deserialize<Point_2D_With_ExtData>(@"{""X"":1,""y"":2,""b"":3}");
+            Point_2D_With_ExtData point = await Serializer.DeserializeWrapper<Point_2D_With_ExtData>(@"{""X"":1,""y"":2,""b"":3}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.ExtensionData["y"].GetInt32());
             Assert.Equal(3, point.ExtensionData["b"].GetInt32());
         }
 
         [Fact]
-        public void PropertiesNotSet_WhenJSON_MapsToConstructorParameters()
+        public async Task PropertiesNotSet_WhenJSON_MapsToConstructorParameters()
         {
-            var obj = Serializer.Deserialize<Point_CtorsIgnoreJson>(@"{""X"":1,""Y"":2}");
+            var obj = await Serializer.DeserializeWrapper<Point_CtorsIgnoreJson>(@"{""X"":1,""Y"":2}");
             Assert.Equal(40, obj.X); // Would be 1 if property were set directly after object construction.
             Assert.Equal(60, obj.Y); // Would be 2 if property were set directly after object construction.
         }
 
         [Fact]
-        public void IgnoreNullValues_DontSetNull_ToConstructorArguments_ThatCantBeNull()
+        public async Task IgnoreNullValues_DontSetNull_ToConstructorArguments_ThatCantBeNull()
         {
             // Throw JsonException when null applied to types that can't be null. Behavior should align with properties deserialized with setters.
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}"));
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""Point3DStruct"":null}"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Point3DStruct"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""Point3DStruct"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Point3DStruct"":null}"));
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""Int"":null}"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Int"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""Int"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Int"":null}"));
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""ImmutableArray"":null}"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""ImmutableArray"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""ImmutableArray"":null}"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""ImmutableArray"":null}"));
 
             // Throw even when IgnoreNullValues is true for symmetry with property deserialization,
             // until https://github.com/dotnet/runtime/issues/30795 is addressed.
 
             var options = new JsonSerializerOptions { IgnoreNullValues = true };
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""Point3DStruct"":null}", options));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""Point3DStruct"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""Int"":null}", options));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""Int"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
 
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester>(@"{""ImmutableArray"":null}", options));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester>(@"{""ImmutableArray"":null}", options));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<NullArgTester_Mutable>(@"{""Point3DStruct"":null,""Int"":null,""ImmutableArray"":null}", options));
         }
 
         [Fact]
-        public void NumerousSimpleAndComplexParameters()
+        public async Task NumerousSimpleAndComplexParameters()
         {
-            var obj = Serializer.Deserialize<ClassWithConstructor_SimpleAndComplexParameters>(ClassWithConstructor_SimpleAndComplexParameters.s_json);
+            var obj = await Serializer.DeserializeWrapper<ClassWithConstructor_SimpleAndComplexParameters>(ClassWithConstructor_SimpleAndComplexParameters.s_json);
             obj.Verify();
         }
 
         [Fact]
-        public void ClassWithPrimitives_Parameterless()
+        public async Task ClassWithPrimitives_Parameterless()
         {
             var point = new Parameterless_ClassWithPrimitives();
 
@@ -401,7 +402,7 @@ namespace System.Text.Json.Serialization.Tests
 
             string json = JsonSerializer.Serialize(point);
 
-            var deserialized = Serializer.Deserialize<Parameterless_ClassWithPrimitives>(json);
+            var deserialized = await Serializer.DeserializeWrapper<Parameterless_ClassWithPrimitives>(json);
             Assert.Equal(point.FirstInt, deserialized.FirstInt);
             Assert.Equal(point.SecondInt, deserialized.SecondInt);
             Assert.Equal(point.FirstString, deserialized.FirstString);
@@ -422,7 +423,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void ClassWithPrimitives()
+        public async Task ClassWithPrimitives()
         {
             var point = new Parameterized_ClassWithPrimitives_3Args(x: 234235, y: 912874, z: 434934);
 
@@ -442,7 +443,7 @@ namespace System.Text.Json.Serialization.Tests
 
             string json = JsonSerializer.Serialize(point);
 
-            var deserialized = Serializer.Deserialize<Parameterized_ClassWithPrimitives_3Args>(json);
+            var deserialized = await Serializer.DeserializeWrapper<Parameterized_ClassWithPrimitives_3Args>(json);
             Assert.Equal(point.FirstInt, deserialized.FirstInt);
             Assert.Equal(point.SecondInt, deserialized.SecondInt);
             Assert.Equal(point.FirstString, deserialized.FirstString);
@@ -463,7 +464,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void ClassWithPrimitivesPerf()
+        public async Task ClassWithPrimitivesPerf()
         {
             var point = new Parameterized_ClassWithPrimitives_3Args(x: 234235, y: 912874, z: 434934);
 
@@ -483,55 +484,55 @@ namespace System.Text.Json.Serialization.Tests
 
             string json = JsonSerializer.Serialize(point);
 
-            Serializer.Deserialize<Parameterized_ClassWithPrimitives_3Args>(json);
-            Serializer.Deserialize<Parameterized_ClassWithPrimitives_3Args>(json);
+            await Serializer.DeserializeWrapper<Parameterized_ClassWithPrimitives_3Args>(json);
+            await Serializer.DeserializeWrapper<Parameterized_ClassWithPrimitives_3Args>(json);
         }
 
         [Fact]
-        public void TupleDeserializationWorks()
+        public async Task TupleDeserializationWorks()
         {
-            var tuple = Serializer.Deserialize<Tuple<string, double>>(@"{""Item1"":""New York"",""Item2"":32.68}");
+            var tuple = await Serializer.DeserializeWrapper<Tuple<string, double>>(@"{""Item1"":""New York"",""Item2"":32.68}");
             Assert.Equal("New York", tuple.Item1);
             Assert.Equal(32.68, tuple.Item2);
 
-            var tupleWrapper = Serializer.Deserialize<TupleWrapper>(@"{""Tuple"":{""Item1"":""New York"",""Item2"":32.68}}");
+            var tupleWrapper = await Serializer.DeserializeWrapper<TupleWrapper>(@"{""Tuple"":{""Item1"":""New York"",""Item2"":32.68}}");
             tuple = tupleWrapper.Tuple;
             Assert.Equal("New York", tuple.Item1);
             Assert.Equal(32.68, tuple.Item2);
 
-            var tupleList = Serializer.Deserialize<List<Tuple<string, double>>>(@"[{""Item1"":""New York"",""Item2"":32.68}]");
+            var tupleList = await Serializer.DeserializeWrapper<List<Tuple<string, double>>>(@"[{""Item1"":""New York"",""Item2"":32.68}]");
             tuple = tupleList[0];
             Assert.Equal("New York", tuple.Item1);
             Assert.Equal(32.68, tuple.Item2);
         }
 
         [Fact]
-        public void TupleDeserialization_MoreThanSevenItems()
+        public async Task TupleDeserialization_MoreThanSevenItems()
         {
             // Seven is okay
             string json = JsonSerializer.Serialize(Tuple.Create(1, 2, 3, 4, 5, 6, 7));
-            var obj = Serializer.Deserialize<Tuple<int, int, int, int, int, int, int>>(json);
+            var obj = await Serializer.DeserializeWrapper<Tuple<int, int, int, int, int, int, int>>(json);
             Assert.Equal(json, JsonSerializer.Serialize(obj));
 
             // More than seven arguments needs special casing and can be revisted.
             // Newtonsoft.Json fails in the same way.
             json = JsonSerializer.Serialize(Tuple.Create(1, 2, 3, 4, 5, 6, 7, 8));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Tuple<int, int, int, int, int, int, int, int>>(json));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Tuple<int, int, int, int, int, int, int, int>>(json));
 
             // Invalid JSON representing a tuple with more than seven items yields an ArgumentException from the constructor.
             // System.ArgumentException : The last element of an eight element tuple must be a Tuple.
             // We pass the number 8, not a new Tuple<int>(8).
             // Fixing this needs special casing. Newtonsoft behaves the same way.
             string invalidJson = @"{""Item1"":1,""Item2"":2,""Item3"":3,""Item4"":4,""Item5"":5,""Item6"":6,""Item7"":7,""Item1"":8}";
-            Assert.Throws<ArgumentException>(() => Serializer.Deserialize<Tuple<int, int, int, int, int, int, int, int>>(invalidJson));
+            await Assert.ThrowsAsync<ArgumentException>(() => Serializer.DeserializeWrapper<Tuple<int, int, int, int, int, int, int, int>>(invalidJson));
         }
 
         [Fact]
-        public void TupleDeserialization_DefaultValuesUsed_WhenJsonMissing()
+        public async Task TupleDeserialization_DefaultValuesUsed_WhenJsonMissing()
         {
             // Seven items; only three provided.
             string input = @"{""Item2"":""2"",""Item3"":3,""Item6"":6}";
-            var obj = Serializer.Deserialize<Tuple<int, string, int, string, string, int, Point_3D_Struct>>(input);
+            var obj = await Serializer.DeserializeWrapper<Tuple<int, string, int, string, string, int, Point_3D_Struct>>(input);
 
             string serialized = JsonSerializer.Serialize(obj);
             Assert.Contains(@"""Item1"":0", serialized);
@@ -551,11 +552,11 @@ namespace System.Text.Json.Serialization.Tests
             // System.ArgumentException : The last element of an eight element tuple must be a Tuple.
             // We pass the number 8, not a new Tuple<int>(default(int)).
             // Fixing this needs special casing. Newtonsoft behaves the same way.
-            Assert.Throws<ArgumentException>(() => Serializer.Deserialize<Tuple<int, string, int, string, string, int, Point_3D_Struct, int>>(input));
+            await Assert.ThrowsAsync<ArgumentException>(() => Serializer.DeserializeWrapper<Tuple<int, string, int, string, string, int, Point_3D_Struct, int>>(input));
         }
 
         [Fact]
-        public void TupleDeserializationWorks_ClassWithParameterizedCtor()
+        public async Task TupleDeserializationWorks_ClassWithParameterizedCtor()
         {
             string classJson = ClassWithConstructor_SimpleAndComplexParameters.s_json;
 
@@ -570,7 +571,7 @@ namespace System.Text.Json.Serialization.Tests
 
             string complexTupleJson = sb.ToString();
 
-            var complexTuple = Serializer.Deserialize<Tuple<
+            var complexTuple = await Serializer.DeserializeWrapper<Tuple<
                 ClassWithConstructor_SimpleAndComplexParameters,
                 ClassWithConstructor_SimpleAndComplexParameters,
                 ClassWithConstructor_SimpleAndComplexParameters,
@@ -589,7 +590,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void TupleDeserializationWorks_ClassWithParameterlessCtor()
+        public async Task TupleDeserializationWorks_ClassWithParameterlessCtor()
         {
             string classJson = SimpleTestClass.s_json;
 
@@ -604,7 +605,7 @@ namespace System.Text.Json.Serialization.Tests
 
             string complexTupleJson = sb.ToString();
 
-            var complexTuple = Serializer.Deserialize<Tuple<
+            var complexTuple = await Serializer.DeserializeWrapper<Tuple<
                 SimpleTestClass,
                 SimpleTestClass,
                 SimpleTestClass,
@@ -623,26 +624,26 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void NoConstructorHandlingWhenObjectHasConverter()
+        public async Task NoConstructorHandlingWhenObjectHasConverter()
         {
             // Baseline without converter
             string serialized = JsonSerializer.Serialize(new Point_3D(10, 6));
 
-            Point_3D point = Serializer.Deserialize<Point_3D>(serialized);
+            Point_3D point = await Serializer.DeserializeWrapper<Point_3D>(serialized);
             Assert.Equal(10, point.X);
             Assert.Equal(6, point.Y);
             Assert.Equal(50, point.Z);
 
             serialized = JsonSerializer.Serialize(new[] { new Point_3D(10, 6) });
 
-            point = Serializer.Deserialize<Point_3D[]>(serialized)[0];
+            point = (await Serializer.DeserializeWrapper<Point_3D[]>(serialized))[0];
             Assert.Equal(10, point.X);
             Assert.Equal(6, point.Y);
             Assert.Equal(50, point.Z);
 
             serialized = JsonSerializer.Serialize(new WrapperForPoint_3D { Point_3D = new Point_3D(10, 6) });
 
-            point = Serializer.Deserialize<WrapperForPoint_3D>(serialized).Point_3D;
+            point = (await Serializer.DeserializeWrapper<WrapperForPoint_3D>(serialized)).Point_3D;
             Assert.Equal(10, point.X);
             Assert.Equal(6, point.Y);
             Assert.Equal(50, point.Z);
@@ -654,31 +655,31 @@ namespace System.Text.Json.Serialization.Tests
 
             serialized = JsonSerializer.Serialize(new Point_3D(10, 6));
 
-            point = Serializer.Deserialize<Point_3D>(serialized, options);
+            point = await Serializer.DeserializeWrapper<Point_3D>(serialized, options);
             Assert.Equal(4, point.X);
             Assert.Equal(4, point.Y);
             Assert.Equal(4, point.Z);
 
             serialized = JsonSerializer.Serialize(new[] { new Point_3D(10, 6) });
 
-            point = Serializer.Deserialize<Point_3D[]>(serialized, options)[0];
+            point = (await Serializer.DeserializeWrapper<Point_3D[]>(serialized, options))[0];
             Assert.Equal(4, point.X);
             Assert.Equal(4, point.Y);
             Assert.Equal(4, point.Z);
 
             serialized = JsonSerializer.Serialize(new WrapperForPoint_3D { Point_3D = new Point_3D(10, 6) });
 
-            point = Serializer.Deserialize<WrapperForPoint_3D>(serialized, options).Point_3D;
+            point = (await Serializer.DeserializeWrapper<WrapperForPoint_3D>(serialized, options)).Point_3D;
             Assert.Equal(4, point.X);
             Assert.Equal(4, point.Y);
             Assert.Equal(4, point.Z);
         }
 
         [Fact]
-        public void ConstructorHandlingHonorsCustomConverters()
+        public async Task ConstructorHandlingHonorsCustomConverters()
         {
             // Baseline, use internal converters for primitives
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{""X"":2,""Y"":3}");
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{""X"":2,""Y"":3}");
             Assert.Equal(2, point.X);
             Assert.Equal(3, point.Y);
 
@@ -686,15 +687,15 @@ namespace System.Text.Json.Serialization.Tests
             var options = new JsonSerializerOptions();
             options.Converters.Add(new ConverterForInt32());
 
-            point = Serializer.Deserialize<Point_2D>(@"{""X"":2,""Y"":3}", options);
+            point = await Serializer.DeserializeWrapper<Point_2D>(@"{""X"":2,""Y"":3}", options);
             Assert.Equal(25, point.X);
             Assert.Equal(25, point.X);
         }
 
         [Fact]
-        public void CanDeserialize_ObjectWith_Ctor_With_64_Params()
+        public async Task CanDeserialize_ObjectWith_Ctor_With_64_Params()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
                 StringBuilder sb = new StringBuilder();
                 sb.Append("{");
@@ -707,21 +708,21 @@ namespace System.Text.Json.Serialization.Tests
 
                 string input = sb.ToString();
 
-                object obj = Serializer.Deserialize<T>(input);
+                object obj = await Serializer.DeserializeWrapper<T>(input);
                 for (int i = 0; i < 64; i++)
                 {
                     Assert.Equal(i, (int)typeof(T).GetProperty($"Int{i}").GetValue(obj));
                 }
             }
 
-            RunTest<Struct_With_Ctor_With_64_Params>();
-            RunTest<Class_With_Ctor_With_64_Params>();
+            await RunTestAsync<Struct_With_Ctor_With_64_Params>();
+            await RunTestAsync<Class_With_Ctor_With_64_Params>();
         }
 
         [Fact]
-        public void Cannot_Deserialize_ObjectWith_Ctor_With_65_Params()
+        public async Task Cannot_Deserialize_ObjectWith_Ctor_With_65_Params()
         {
-            void RunTest<T>()
+            async Task RunTestAsync<T>()
             {
                 Type type = typeof(T);
 
@@ -747,46 +748,46 @@ namespace System.Text.Json.Serialization.Tests
 
                 string ctorAsString = sb.ToString();
 
-                NotSupportedException ex = Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<T>(input));
+                NotSupportedException ex = await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<T>(input));
                 string strEx = ex.ToString();
                 Assert.Contains(ctorAsString, strEx);
                 Assert.Contains(type.ToString(), strEx);
 
-                ex = Assert.Throws<NotSupportedException>(() => Serializer.Deserialize<T>("{}"));
+                ex = await Assert.ThrowsAsync<NotSupportedException>(() => Serializer.DeserializeWrapper<T>("{}"));
                 strEx = ex.ToString();
                 Assert.Contains(ctorAsString, strEx);
                 Assert.Contains(type.ToString(), strEx);
             }
 
-            RunTest<Class_With_Ctor_With_65_Params>();
-            RunTest<Struct_With_Ctor_With_65_Params>();
+            await RunTestAsync<Class_With_Ctor_With_65_Params>();
+            await RunTestAsync<Struct_With_Ctor_With_65_Params>();
         }
 
         [Fact]
-        public void Deserialize_ObjectWith_Ctor_With_65_Params_IfNull()
+        public async Task Deserialize_ObjectWith_Ctor_With_65_Params_IfNull()
         {
-            Assert.Null(Serializer.Deserialize<Class_With_Ctor_With_65_Params>("null"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Struct_With_Ctor_With_65_Params>("null"));
+            Assert.Null(await Serializer.DeserializeWrapper<Class_With_Ctor_With_65_Params>("null"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Struct_With_Ctor_With_65_Params>("null"));
         }
 
         [Fact]
-        public void Escaped_ParameterNames_Work()
+        public async Task Escaped_ParameterNames_Work()
         {
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{""\u0058"":1,""\u0059"":2}");
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{""\u0058"":1,""\u0059"":2}");
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
         }
 
         [Fact]
-        public void FirstParameterWins()
+        public async Task FirstParameterWins()
         {
-            Point_2D point = Serializer.Deserialize<Point_2D>(@"{""X"":1,""Y"":2,""X"":4}");
+            Point_2D point = await Serializer.DeserializeWrapper<Point_2D>(@"{""X"":1,""Y"":2,""X"":4}");
             Assert.Equal(4, point.X); // Not 1.
             Assert.Equal(2, point.Y);
         }
 
         [Fact]
-        public void SubsequentParameter_GoesToExtensionData()
+        public async Task SubsequentParameter_GoesToExtensionData()
         {
             string json = @"{
                 ""FirstName"":""Jet"",
@@ -797,7 +798,7 @@ namespace System.Text.Json.Serialization.Tests
                 ""Id"":""63cf821d-fd47-4782-8345-576d9228a534""
                 }";
 
-            Parameterized_Person person = Serializer.Deserialize<Parameterized_Person>(json);
+            Parameterized_Person person = await Serializer.DeserializeWrapper<Parameterized_Person>(json);
             Assert.Equal("Jet", person.FirstName);
             Assert.Equal("Doe", person.LastName);
             Assert.Equal("63cf821d-fd47-4782-8345-576d9228a534", person.Id.ToString());
@@ -806,30 +807,30 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void BitVector32_UsesStructDefaultCtor_MultipleParameterizedCtor()
+        public async Task BitVector32_UsesStructDefaultCtor_MultipleParameterizedCtor()
         {
             string serialized = JsonSerializer.Serialize(new BitVector32(1));
-            Assert.Equal(0, Serializer.Deserialize<BitVector32>(serialized).Data);
+            Assert.Equal(0, (await Serializer.DeserializeWrapper<BitVector32>(serialized)).Data);
         }
 
         [Fact]
-        public void HonorExtensionDataGeneric()
+        public async Task HonorExtensionDataGeneric()
         {
-            var obj1 = Serializer.Deserialize<SimpleClassWithParameterizedCtor_GenericDictionary_JsonElementExt>(@"{""key"": ""value""}");
+            var obj1 = await Serializer.DeserializeWrapper<SimpleClassWithParameterizedCtor_GenericDictionary_JsonElementExt>(@"{""key"": ""value""}");
             Assert.Equal("value", obj1.ExtensionData["key"].GetString());
 
-            var obj2 = Serializer.Deserialize<SimpleClassWithParameterizedCtor_GenericDictionary_ObjectExt>(@"{""key"": ""value""}");
+            var obj2 = await Serializer.DeserializeWrapper<SimpleClassWithParameterizedCtor_GenericDictionary_ObjectExt>(@"{""key"": ""value""}");
             Assert.Equal("value", ((JsonElement)obj2.ExtensionData["key"]).GetString());
 
-            var obj3 = Serializer.Deserialize<SimpleClassWithParameterizedCtor_Derived_GenericIDictionary_JsonElementExt>(@"{""key"": ""value""}");
+            var obj3 = await Serializer.DeserializeWrapper<SimpleClassWithParameterizedCtor_Derived_GenericIDictionary_JsonElementExt>(@"{""key"": ""value""}");
             Assert.Equal("value", obj3.ExtensionData["key"].GetString());
 
-            var obj4 = Serializer.Deserialize<SimpleClassWithParameterizedCtor_Derived_GenericIDictionary_ObjectExt>(@"{""key"": ""value""}");
+            var obj4 = await Serializer.DeserializeWrapper<SimpleClassWithParameterizedCtor_Derived_GenericIDictionary_ObjectExt>(@"{""key"": ""value""}");
             Assert.Equal("value", ((JsonElement)obj4.ExtensionData["key"]).GetString());
         }
 
         [Fact]
-        public void ArgumentDeserialization_Honors_JsonPropertyName()
+        public async Task ArgumentDeserialization_Honors_JsonPropertyName()
         {
             Point_MembersHave_JsonPropertyName point = new Point_MembersHave_JsonPropertyName(1, 2);
 
@@ -837,40 +838,40 @@ namespace System.Text.Json.Serialization.Tests
             Assert.Contains(@"""XValue"":1", json);
             Assert.Contains(@"""YValue"":2", json);
 
-            point = Serializer.Deserialize<Point_MembersHave_JsonPropertyName>(json);
+            point = await Serializer.DeserializeWrapper<Point_MembersHave_JsonPropertyName>(json);
             point.Verify();
         }
 
         [Fact]
-        public void ArgumentDeserialization_Honors_JsonPropertyName_CaseInsensitiveWorks()
+        public async Task ArgumentDeserialization_Honors_JsonPropertyName_CaseInsensitiveWorks()
         {
             string json = @"{""XVALUE"":1,""yvalue"":2}";
 
             // Without case insensitivity, there's no match.
-            Point_MembersHave_JsonPropertyName point = Serializer.Deserialize<Point_MembersHave_JsonPropertyName>(json);
+            Point_MembersHave_JsonPropertyName point = await Serializer.DeserializeWrapper<Point_MembersHave_JsonPropertyName>(json);
 
             var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
-            point = Serializer.Deserialize<Point_MembersHave_JsonPropertyName>(json, options);
+            point = await Serializer.DeserializeWrapper<Point_MembersHave_JsonPropertyName>(json, options);
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
         }
 
         [Fact]
-        public void ArgumentDeserialization_Honors_ConverterOnProperty()
+        public async Task ArgumentDeserialization_Honors_ConverterOnProperty()
         {
-            var point = Serializer.Deserialize<Point_MembersHave_JsonConverter>(Point_MembersHave_JsonConverter.s_json);
+            var point = await Serializer.DeserializeWrapper<Point_MembersHave_JsonConverter>(Point_MembersHave_JsonConverter.s_json);
             point.Verify();
         }
 
         [Fact]
-        public void ArgumentDeserialization_Honors_JsonIgnore()
+        public async Task ArgumentDeserialization_Honors_JsonIgnore()
         {
-            var point = Serializer.Deserialize<Point_MembersHave_JsonIgnore>(Point_MembersHave_JsonIgnore.s_json);
+            var point = await Serializer.DeserializeWrapper<Point_MembersHave_JsonIgnore>(Point_MembersHave_JsonIgnore.s_json);
             point.Verify();
         }
 
         [Fact]
-        public void ArgumentDeserialization_UseNamingPolicy_ToMatch()
+        public async Task ArgumentDeserialization_UseNamingPolicy_ToMatch()
         {
             var options = new JsonSerializerOptions
             {
@@ -880,17 +881,17 @@ namespace System.Text.Json.Serialization.Tests
             string json = JsonSerializer.Serialize(new Point_ExtendedPropNames(1, 2), options);
 
             // If we don't use naming policy, then we can't match serialized properties to constructor parameters on deserialization.
-            var point = Serializer.Deserialize<Point_ExtendedPropNames>(json);
+            var point = await Serializer.DeserializeWrapper<Point_ExtendedPropNames>(json);
             Assert.Equal(0, point.XValue);
             Assert.Equal(0, point.YValue);
 
-            point = Serializer.Deserialize<Point_ExtendedPropNames>(json, options);
+            point = await Serializer.DeserializeWrapper<Point_ExtendedPropNames>(json, options);
             Assert.Equal(1, point.XValue);
             Assert.Equal(2, point.YValue);
         }
 
         [Fact]
-        public void ArgumentDeserialization_UseNamingPolicy_ToMatch_CaseInsensitiveWorks()
+        public async Task ArgumentDeserialization_UseNamingPolicy_ToMatch_CaseInsensitiveWorks()
         {
             var options1 = new JsonSerializerOptions
             {
@@ -900,7 +901,7 @@ namespace System.Text.Json.Serialization.Tests
             string json = @"{""x_VaLUE"":1,""Y_vALue"":2}";
 
             // If we don't use case sensitivity, then we can't match serialized properties to constructor parameters on deserialization.
-            Point_ExtendedPropNames point = Serializer.Deserialize<Point_ExtendedPropNames>(json, options1);
+            Point_ExtendedPropNames point = await Serializer.DeserializeWrapper<Point_ExtendedPropNames>(json, options1);
             Assert.Equal(0, point.XValue);
             Assert.Equal(0, point.YValue);
 
@@ -910,37 +911,37 @@ namespace System.Text.Json.Serialization.Tests
                 PropertyNameCaseInsensitive = true,
             };
 
-            point = Serializer.Deserialize<Point_ExtendedPropNames>(json, options2);
+            point = await Serializer.DeserializeWrapper<Point_ExtendedPropNames>(json, options2);
             Assert.Equal(1, point.XValue);
             Assert.Equal(2, point.YValue);
         }
 
         [Fact]
-        public void ArgumentDeserialization_UseNamingPolicy_InvalidPolicyFails()
+        public async Task ArgumentDeserialization_UseNamingPolicy_InvalidPolicyFails()
         {
             var options = new JsonSerializerOptions
             {
                 PropertyNamingPolicy = new NullNamingPolicy()
             };
 
-            Assert.Throws<InvalidOperationException>(() => Serializer.Deserialize<Point_ExtendedPropNames>("{}", options));
+            await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.DeserializeWrapper<Point_ExtendedPropNames>("{}", options));
         }
 
         [Fact]
-        public void ComplexJson_As_LastCtorArg()
+        public async Task ComplexJson_As_LastCtorArg()
         {
-            Point_With_Array obj1 = Serializer.Deserialize<Point_With_Array>(Point_With_Array.s_json);
+            Point_With_Array obj1 = await Serializer.DeserializeWrapper<Point_With_Array>(Point_With_Array.s_json);
             ((ITestClass)obj1).Verify();
 
-            Point_With_Dictionary obj2 = Serializer.Deserialize<Point_With_Dictionary>(Point_With_Dictionary.s_json);
+            Point_With_Dictionary obj2 = await Serializer.DeserializeWrapper<Point_With_Dictionary>(Point_With_Dictionary.s_json);
             ((ITestClass)obj2).Verify();
 
-            Point_With_Object obj3 = Serializer.Deserialize<Point_With_Object>(Point_With_Object.s_json);
+            Point_With_Object obj3 = await Serializer.DeserializeWrapper<Point_With_Object>(Point_With_Object.s_json);
             ((ITestClass)obj3).Verify();
         }
 
         [Fact]
-        public void NumerousPropertiesWork()
+        public async Task NumerousPropertiesWork()
         {
             StringBuilder sb = new StringBuilder();
             sb.Append("{");
@@ -957,14 +958,14 @@ namespace System.Text.Json.Serialization.Tests
 
             string json = sb.ToString();
 
-            var point = Serializer.Deserialize<Point_With_Property>(json);
+            var point = await Serializer.DeserializeWrapper<Point_With_Property>(json);
             Assert.Equal(1, point.X);
             Assert.Equal(2, point.Y);
             Assert.Equal(66, point.Z);
         }
 
         [Fact]
-        public void ArgumentStateNotOverwritten()
+        public async Task ArgumentStateNotOverwritten()
         {
             ClassWithNestedClass obj = new ClassWithNestedClass(myClass: null, myPoint: default);
             ClassWithNestedClass obj1 = new ClassWithNestedClass(myClass: obj, myPoint: new Point_2D_Struct_WithAttribute(1, 2));
@@ -972,7 +973,7 @@ namespace System.Text.Json.Serialization.Tests
 
             string json = JsonSerializer.Serialize(obj2);
 
-            obj2 = Serializer.Deserialize<ClassWithNestedClass>(json);
+            obj2 = await Serializer.DeserializeWrapper<ClassWithNestedClass>(json);
             Assert.Equal(3, obj2.MyPoint.X);
             Assert.Equal(4, obj2.MyPoint.Y);
 
@@ -988,11 +989,11 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void FourArgsWork()
+        public async Task FourArgsWork()
         {
             string json = JsonSerializer.Serialize(new StructWithFourArgs(1, 2, 3, 4));
 
-            var obj = Serializer.Deserialize<StructWithFourArgs>(json);
+            var obj = await Serializer.DeserializeWrapper<StructWithFourArgs>(json);
             Assert.Equal(1, obj.W);
             Assert.Equal(2, obj.X);
             Assert.Equal(3, obj.Y);
@@ -1000,17 +1001,17 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void InvalidJsonFails()
+        public async Task InvalidJsonFails()
         {
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D>("{1"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D>("{x"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D>("{{"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D>("{true"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D>("{1"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D>("{x"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D>("{{"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D>("{true"));
 
             // Also test deserialization of objects with parameterless ctors
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D_Struct>("{1"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D_Struct>("{x"));
-            Assert.Throws<JsonException>(() => Serializer.Deserialize<Point_2D_Struct>("{true"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D_Struct>("{1"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D_Struct>("{x"));
+            await Assert.ThrowsAsync<JsonException>(() => Serializer.DeserializeWrapper<Point_2D_Struct>("{true"));
         }
     }
 }
index 50f7efc..c06db5e 100644 (file)
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
@@ -11,9 +11,9 @@ namespace System.Text.Json.Serialization.Tests
     public abstract partial class ConstructorTests
     {
         [Fact]
-        public void ReadSimpleObjectAsync()
+        public async Task ReadSimpleObjectAsync()
         {
-            async Task RunTest<T>(byte[] testData)
+            async Task RunTestAsync<T>(byte[] testData)
             {
                 using (MemoryStream stream = new MemoryStream(testData))
                 {
@@ -31,34 +31,34 @@ namespace System.Text.Json.Serialization.Tests
             Task[] tasks = new Task[14];
 
             // Simple models can be deserialized.
-            tasks[0] = Task.Run(async () => await RunTest<Parameterized_IndexViewModel_Immutable>(Parameterized_IndexViewModel_Immutable.s_data));
+            tasks[0] = Task.Run(async () => await RunTestAsync<Parameterized_IndexViewModel_Immutable>(Parameterized_IndexViewModel_Immutable.s_data));
             // Complex models can be deserialized.
-            tasks[1] = Task.Run(async () => await RunTest<ClassWithConstructor_SimpleAndComplexParameters>(ClassWithConstructor_SimpleAndComplexParameters.s_data));
-            tasks[2] = Task.Run(async () => await RunTest<Parameterized_Class_With_ComplexTuple>(Parameterized_Class_With_ComplexTuple.s_data));
+            tasks[1] = Task.Run(async () => await RunTestAsync<ClassWithConstructor_SimpleAndComplexParameters>(ClassWithConstructor_SimpleAndComplexParameters.s_data));
+            tasks[2] = Task.Run(async () => await RunTestAsync<Parameterized_Class_With_ComplexTuple>(Parameterized_Class_With_ComplexTuple.s_data));
             // JSON that doesn't bind to ctor args are matched with properties or ignored (as appropriate).
-            tasks[3] = Task.Run(async () => await RunTest<Person_Class>(Person_Class.s_data));
-            tasks[4] = Task.Run(async () => await RunTest<Person_Struct>(Person_Struct.s_data));
+            tasks[3] = Task.Run(async () => await RunTestAsync<Person_Class>(Person_Class.s_data));
+            tasks[4] = Task.Run(async () => await RunTestAsync<Person_Struct>(Person_Struct.s_data));
             // JSON that doesn't bind to ctor args or properties are sent to ext data if avaiable.
-            tasks[5] = Task.Run(async () => await RunTest<Parameterized_Person>(Parameterized_Person.s_data));
-            tasks[6] = Task.Run(async () => await RunTest<Parameterized_Person_ObjExtData>(Parameterized_Person_ObjExtData.s_data));
+            tasks[5] = Task.Run(async () => await RunTestAsync<Parameterized_Person>(Parameterized_Person.s_data));
+            tasks[6] = Task.Run(async () => await RunTestAsync<Parameterized_Person_ObjExtData>(Parameterized_Person_ObjExtData.s_data));
             // Up to 64 ctor args are supported.
-            tasks[7] = Task.Run(async () => await RunTest<Class_With_Ctor_With_64_Params>(Class_With_Ctor_With_64_Params.Data));
+            tasks[7] = Task.Run(async () => await RunTestAsync<Class_With_Ctor_With_64_Params>(Class_With_Ctor_With_64_Params.Data));
             // Arg deserialization honors attributes on matching property.
-            tasks[8] = Task.Run(async () => await RunTest<Point_MembersHave_JsonPropertyName>(Point_MembersHave_JsonPropertyName.s_data));
-            tasks[9] = Task.Run(async () => await RunTest<Point_MembersHave_JsonConverter>(Point_MembersHave_JsonConverter.s_data));
-            tasks[10] = Task.Run(async () => await RunTest<Point_MembersHave_JsonIgnore>(Point_MembersHave_JsonIgnore.s_data));
+            tasks[8] = Task.Run(async () => await RunTestAsync<Point_MembersHave_JsonPropertyName>(Point_MembersHave_JsonPropertyName.s_data));
+            tasks[9] = Task.Run(async () => await RunTestAsync<Point_MembersHave_JsonConverter>(Point_MembersHave_JsonConverter.s_data));
+            tasks[10] = Task.Run(async () => await RunTestAsync<Point_MembersHave_JsonIgnore>(Point_MembersHave_JsonIgnore.s_data));
             // Complex JSON as last argument works
-            tasks[11] = Task.Run(async () => await RunTest<Point_With_Array>(Point_With_Array.s_data));
-            tasks[12] = Task.Run(async () => await RunTest<Point_With_Dictionary>(Point_With_Dictionary.s_data));
-            tasks[13] = Task.Run(async () => await RunTest<Point_With_Object>(Point_With_Object.s_data));
+            tasks[11] = Task.Run(async () => await RunTestAsync<Point_With_Array>(Point_With_Array.s_data));
+            tasks[12] = Task.Run(async () => await RunTestAsync<Point_With_Dictionary>(Point_With_Dictionary.s_data));
+            tasks[13] = Task.Run(async () => await RunTestAsync<Point_With_Object>(Point_With_Object.s_data));
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
         [Fact]
-        public void ReadSimpleObjectWithTrailingTriviaAsync()
+        public async Task ReadSimpleObjectWithTrailingTriviaAsync()
         {
-            async Task RunTest<T>(string testData)
+            async Task RunTestAsync<T>(string testData)
             {
                 byte[] data = Encoding.UTF8.GetBytes(testData + " /* Multi\r\nLine Comment */\t");
                 using (MemoryStream stream = new MemoryStream(data))
@@ -78,34 +78,34 @@ namespace System.Text.Json.Serialization.Tests
             Task[] tasks = new Task[14];
 
             // Simple models can be deserialized.
-            tasks[0] = Task.Run(async () => await RunTest<Parameterized_IndexViewModel_Immutable>(Parameterized_IndexViewModel_Immutable.s_json));
+            tasks[0] = Task.Run(async () => await RunTestAsync<Parameterized_IndexViewModel_Immutable>(Parameterized_IndexViewModel_Immutable.s_json));
             // Complex models can be deserialized.
-            tasks[1] = Task.Run(async () => await RunTest<ClassWithConstructor_SimpleAndComplexParameters>(ClassWithConstructor_SimpleAndComplexParameters.s_json));
-            tasks[2] = Task.Run(async () => await RunTest<Parameterized_Class_With_ComplexTuple>(Parameterized_Class_With_ComplexTuple.s_json));
+            tasks[1] = Task.Run(async () => await RunTestAsync<ClassWithConstructor_SimpleAndComplexParameters>(ClassWithConstructor_SimpleAndComplexParameters.s_json));
+            tasks[2] = Task.Run(async () => await RunTestAsync<Parameterized_Class_With_ComplexTuple>(Parameterized_Class_With_ComplexTuple.s_json));
             // JSON that doesn't bind to ctor args are matched with properties or ignored (as appropriate).
-            tasks[3] = Task.Run(async () => await RunTest<Person_Class>(Person_Class.s_json));
-            tasks[4] = Task.Run(async () => await RunTest<Person_Struct>(Person_Struct.s_json));
+            tasks[3] = Task.Run(async () => await RunTestAsync<Person_Class>(Person_Class.s_json));
+            tasks[4] = Task.Run(async () => await RunTestAsync<Person_Struct>(Person_Struct.s_json));
             // JSON that doesn't bind to ctor args or properties are sent to ext data if avaiable.
-            tasks[5] = Task.Run(async () => await RunTest<Parameterized_Person>(Parameterized_Person.s_json));
-            tasks[6] = Task.Run(async () => await RunTest<Parameterized_Person_ObjExtData>(Parameterized_Person_ObjExtData.s_json));
+            tasks[5] = Task.Run(async () => await RunTestAsync<Parameterized_Person>(Parameterized_Person.s_json));
+            tasks[6] = Task.Run(async () => await RunTestAsync<Parameterized_Person_ObjExtData>(Parameterized_Person_ObjExtData.s_json));
             // Up to 64 ctor args are supported.
-            tasks[7] = Task.Run(async () => await RunTest<Class_With_Ctor_With_64_Params>(Encoding.UTF8.GetString(Class_With_Ctor_With_64_Params.Data)));
+            tasks[7] = Task.Run(async () => await RunTestAsync<Class_With_Ctor_With_64_Params>(Encoding.UTF8.GetString(Class_With_Ctor_With_64_Params.Data)));
             // Arg8deserialization honors attributes on matching property.
-            tasks[8] = Task.Run(async () => await RunTest<Point_MembersHave_JsonPropertyName>(Point_MembersHave_JsonPropertyName.s_json));
-            tasks[9] = Task.Run(async () => await RunTest<Point_MembersHave_JsonConverter>(Point_MembersHave_JsonConverter.s_json));
-            tasks[10] = Task.Run(async () => await RunTest<Point_MembersHave_JsonIgnore>(Point_MembersHave_JsonIgnore.s_json));
+            tasks[8] = Task.Run(async () => await RunTestAsync<Point_MembersHave_JsonPropertyName>(Point_MembersHave_JsonPropertyName.s_json));
+            tasks[9] = Task.Run(async () => await RunTestAsync<Point_MembersHave_JsonConverter>(Point_MembersHave_JsonConverter.s_json));
+            tasks[10] = Task.Run(async () => await RunTestAsync<Point_MembersHave_JsonIgnore>(Point_MembersHave_JsonIgnore.s_json));
             // Complex JSON as last argument works
-            tasks[11] = Task.Run(async () => await RunTest<Point_With_Array>(Point_With_Array.s_json));
-            tasks[12] = Task.Run(async () => await RunTest<Point_With_Dictionary>(Point_With_Dictionary.s_json));
-            tasks[13] = Task.Run(async () => await RunTest<Point_With_Object>(Point_With_Object.s_json));
+            tasks[11] = Task.Run(async () => await RunTestAsync<Point_With_Array>(Point_With_Array.s_json));
+            tasks[12] = Task.Run(async () => await RunTestAsync<Point_With_Dictionary>(Point_With_Dictionary.s_json));
+            tasks[13] = Task.Run(async () => await RunTestAsync<Point_With_Object>(Point_With_Object.s_json));
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
-        public void Cannot_DeserializeAsync_ObjectWith_Ctor_With_65_Params()
+        [Fact]
+        public async Task Cannot_DeserializeAsync_ObjectWith_Ctor_With_65_Params()
         {
-            async Task RunTest<T>()
+            async Task RunTestAsync<T>()
             {
                 StringBuilder sb = new StringBuilder();
                 sb.Append("{");
@@ -141,10 +141,10 @@ namespace System.Text.Json.Serialization.Tests
 
             Task[] tasks = new Task[2];
 
-            tasks[0] = Task.Run(async () => await RunTest<Class_With_Ctor_With_65_Params>());
-            tasks[1] = Task.Run(async () => await RunTest<Struct_With_Ctor_With_65_Params>());
+            tasks[0] = Task.Run(async () => await RunTestAsync<Class_With_Ctor_With_65_Params>());
+            tasks[1] = Task.Run(async () => await RunTestAsync<Struct_With_Ctor_With_65_Params>());
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
         [Fact]
@@ -155,7 +155,7 @@ namespace System.Text.Json.Serialization.Tests
 
             static byte[] GeneratePayload(int i, string value)
             {
-                string whiteSpace = new string(' ', 16 );
+                string whiteSpace = new string(' ', 16);
 
                 StringBuilder sb;
 
index 65099e3..b20b6f5 100644 (file)
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.IO;
@@ -16,55 +16,49 @@ namespace System.Text.Json.Serialization.Tests
         public static DeserializationWrapper StringDeserializer => new StringDeserializerWrapper();
         public static DeserializationWrapper StreamDeserializer => new StreamDeserializerWrapper();
 
-        protected internal abstract T Deserialize<T>(string json, JsonSerializerOptions options = null);
+        protected internal abstract Task<T> DeserializeWrapper<T>(string json, JsonSerializerOptions options = null);
 
-        protected internal abstract object Deserialize(string json, Type type, JsonSerializerOptions options = null);
+        protected internal abstract Task<object> DeserializeWrapper(string json, Type type, JsonSerializerOptions options = null);
 
         private class StringDeserializerWrapper : DeserializationWrapper
         {
-            protected internal override T Deserialize<T>(string json, JsonSerializerOptions options = null)
+            protected internal override Task<T> DeserializeWrapper<T>(string json, JsonSerializerOptions options = null)
             {
-                return JsonSerializer.Deserialize<T>(json, options);
+                return Task.FromResult(JsonSerializer.Deserialize<T>(json, options));
             }
 
-            protected internal override object Deserialize(string json, Type type, JsonSerializerOptions options = null)
+            protected internal override Task<object> DeserializeWrapper(string json, Type type, JsonSerializerOptions options = null)
             {
-                return JsonSerializer.Deserialize(json, type, options);
+                return Task.FromResult(JsonSerializer.Deserialize(json, type, options));
             }
         }
 
         private class StreamDeserializerWrapper : DeserializationWrapper
         {
-            protected internal override T Deserialize<T>(string json, JsonSerializerOptions options = null)
+            protected internal override async Task<T> DeserializeWrapper<T>(string json, JsonSerializerOptions options = null)
             {
                 if (options == null)
                 {
                     options = _optionsWithSmallBuffer;
                 }
 
-                return Task.Run(async () =>
+                using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
                 {
-                    using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
-                    {
-                        return await JsonSerializer.DeserializeAsync<T>(stream, options);
-                    }
-                }).GetAwaiter().GetResult();
+                    return await JsonSerializer.DeserializeAsync<T>(stream, options);
+                }
             }
 
-            protected internal override object Deserialize(string json, Type type, JsonSerializerOptions options = null)
+            protected internal override async Task<object> DeserializeWrapper(string json, Type type, JsonSerializerOptions options = null)
             {
                 if (options == null)
                 {
                     options = _optionsWithSmallBuffer;
                 }
 
-                return Task.Run(async () =>
+                using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
                 {
-                    using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
-                    {
-                        return await JsonSerializer.DeserializeAsync(stream, type, options);
-                    }
-                }).GetAwaiter().GetResult();
+                    return await JsonSerializer.DeserializeAsync(stream, type, options);
+                }
             }
         }
     }
index b4510f1..60c2a84 100644 (file)
@@ -1,7 +1,8 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections.Generic;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
@@ -50,9 +51,9 @@ namespace System.Text.Json.Serialization.Tests
             Assert.Contains(type.ToString(), ex.ToString());
         }
 
-        [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+        [Theory]
         [MemberData(nameof(TypesWithInvalidMembers_WithMembers))]
-        public void TypeWithInvalidMember(Type classType, Type invalidMemberType, string invalidMemberName)
+        public async Task TypeWithInvalidMember(Type classType, Type invalidMemberType, string invalidMemberName)
         {
             static void ValidateException(InvalidOperationException ex, Type classType, Type invalidMemberType, string invalidMemberName)
             {
@@ -63,19 +64,19 @@ namespace System.Text.Json.Serialization.Tests
             }
 
             object obj = Activator.CreateInstance(classType);
-            InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => Serializer.Serialize(obj, classType));
+            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.SerializeWrapper(obj, classType));
             ValidateException(ex, classType, invalidMemberType, invalidMemberName);
 
-            ex = Assert.Throws<InvalidOperationException>(() => Serializer.Serialize(null, classType));
+            ex = await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.SerializeWrapper(null, classType));
             ValidateException(ex, classType, invalidMemberType, invalidMemberName);
 
             ex = Assert.Throws<InvalidOperationException>(() => JsonSerializer.Deserialize("", classType));
             ValidateException(ex, classType, invalidMemberType, invalidMemberName);
         }
 
-        [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+        [Theory]
         [MemberData(nameof(OpenGenericTypes_ToSerialize))]
-        public void SerializeOpenGeneric(Type type)
+        public async Task SerializeOpenGeneric(Type type)
         {
             object obj;
 
@@ -88,24 +89,24 @@ namespace System.Text.Json.Serialization.Tests
                 obj = Activator.CreateInstance(type.MakeGenericType(typeof(string), typeof(int)));
             }
 
-            Assert.Throws<ArgumentException>(() => Serializer.Serialize(obj, type));
+            await Assert.ThrowsAsync<ArgumentException>(() => Serializer.SerializeWrapper(obj, type));
         }
 
-        [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+        [Theory]
         [MemberData(nameof(OpenGenericTypes))]
-        public void SerializeInvalidTypes_NullValue(Type type)
+        public async Task SerializeInvalidTypes_NullValue(Type type)
         {
-            InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => Serializer.Serialize(null, type));
+            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.SerializeWrapper(null, type));
             Assert.Contains(type.ToString(), ex.ToString());
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
-        public void SerializeOpenGeneric_NullableOfT()
+        [Fact]
+        public async Task SerializeOpenGeneric_NullableOfT()
         {
             Type openNullableType = typeof(Nullable<>);
             object obj = Activator.CreateInstance(openNullableType.MakeGenericType(typeof(int)));
 
-            InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => Serializer.Serialize(obj, openNullableType));
+            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => Serializer.SerializeWrapper(obj, openNullableType));
             Assert.Contains(openNullableType.ToString(), ex.ToString());
         }
 
index 3129e1e..00cb5ad 100644 (file)
@@ -4,6 +4,7 @@
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Immutable;
+using System.Threading.Tasks;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
@@ -43,32 +44,32 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void PrimitivesAsRootObject()
+        public async Task PrimitivesAsRootObject()
         {
-            string json = Serializer.Serialize<object>(1);
+            string json = await Serializer.SerializeWrapper<object>(1);
             Assert.Equal("1", json);
-            json = Serializer.Serialize(1, typeof(object));
+            json = await Serializer.SerializeWrapper(1, typeof(object));
             Assert.Equal("1", json);
 
-            json = Serializer.Serialize<object>("foo");
+            json = await Serializer.SerializeWrapper<object>("foo");
             Assert.Equal(@"""foo""", json);
-            json = Serializer.Serialize("foo", typeof(object));
+            json = await Serializer.SerializeWrapper("foo", typeof(object));
             Assert.Equal(@"""foo""", json);
 
-            json = Serializer.Serialize<object>(true);
+            json = await Serializer.SerializeWrapper<object>(true);
             Assert.Equal(@"true", json);
-            json = Serializer.Serialize(true, typeof(object));
+            json = await Serializer.SerializeWrapper(true, typeof(object));
             Assert.Equal(@"true", json);
 
-            json = Serializer.Serialize<object>(null);
+            json = await Serializer.SerializeWrapper<object>(null);
             Assert.Equal(@"null", json);
-            json = Serializer.Serialize((object)null, typeof(object));
+            json = await Serializer.SerializeWrapper((object)null, typeof(object));
             Assert.Equal(@"null", json);
 
             decimal pi = 3.1415926535897932384626433833m;
-            json = Serializer.Serialize<object>(pi);
+            json = await Serializer.SerializeWrapper<object>(pi);
             Assert.Equal(@"3.1415926535897932384626433833", json);
-            json = Serializer.Serialize(pi, typeof(object));
+            json = await Serializer.SerializeWrapper(pi, typeof(object));
             Assert.Equal(@"3.1415926535897932384626433833", json);
         }
 
@@ -102,7 +103,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void ArrayAsRootObject()
+        public async Task ArrayAsRootObject()
         {
             const string ExpectedJson = @"[1,true,{""City"":""MyCity""},null,""foo""]";
             const string ReversedExpectedJson = @"[""foo"",null,{""City"":""MyCity""},true,1]";
@@ -113,193 +114,193 @@ namespace System.Text.Json.Serialization.Tests
             address.Initialize();
 
             var array = new object[] { 1, true, address, null, "foo" };
-            string json = Serializer.Serialize(array);
+            string json = await Serializer.SerializeWrapper(array);
             Assert.Equal(ExpectedJson, json);
 
             var dictionary = new Dictionary<string, string> { { "City", "MyCity" } };
             var arrayWithDictionary = new object[] { 1, true, dictionary, null, "foo" };
-            json = Serializer.Serialize(arrayWithDictionary);
+            json = await Serializer.SerializeWrapper(arrayWithDictionary);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(array);
+            json = await Serializer.SerializeWrapper<object>(array);
             Assert.Equal(ExpectedJson, json);
 
             List<object> list = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(list);
+            json = await Serializer.SerializeWrapper(list);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(list);
+            json = await Serializer.SerializeWrapper<object>(list);
             Assert.Equal(ExpectedJson, json);
 
             IEnumerable ienumerable = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(ienumerable);
+            json = await Serializer.SerializeWrapper(ienumerable);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(ienumerable);
+            json = await Serializer.SerializeWrapper<object>(ienumerable);
             Assert.Equal(ExpectedJson, json);
 
             IList ilist = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(ilist);
+            json = await Serializer.SerializeWrapper(ilist);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(ilist);
+            json = await Serializer.SerializeWrapper<object>(ilist);
             Assert.Equal(ExpectedJson, json);
 
             ICollection icollection = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(icollection);
+            json = await Serializer.SerializeWrapper(icollection);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(icollection);
+            json = await Serializer.SerializeWrapper<object>(icollection);
             Assert.Equal(ExpectedJson, json);
 
             IEnumerable<object> genericIEnumerable = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(genericIEnumerable);
+            json = await Serializer.SerializeWrapper(genericIEnumerable);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(genericIEnumerable);
+            json = await Serializer.SerializeWrapper<object>(genericIEnumerable);
             Assert.Equal(ExpectedJson, json);
 
             IList<object> genericIList = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(genericIList);
+            json = await Serializer.SerializeWrapper(genericIList);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(genericIList);
+            json = await Serializer.SerializeWrapper<object>(genericIList);
             Assert.Equal(ExpectedJson, json);
 
             ICollection<object> genericICollection = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(genericICollection);
+            json = await Serializer.SerializeWrapper(genericICollection);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(genericICollection);
+            json = await Serializer.SerializeWrapper<object>(genericICollection);
             Assert.Equal(ExpectedJson, json);
 
             IReadOnlyCollection<object> genericIReadOnlyCollection = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(genericIReadOnlyCollection);
+            json = await Serializer.SerializeWrapper(genericIReadOnlyCollection);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(genericIReadOnlyCollection);
+            json = await Serializer.SerializeWrapper<object>(genericIReadOnlyCollection);
             Assert.Equal(ExpectedJson, json);
 
             IReadOnlyList<object> genericIReadonlyList = new List<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(genericIReadonlyList);
+            json = await Serializer.SerializeWrapper(genericIReadonlyList);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(genericIReadonlyList);
+            json = await Serializer.SerializeWrapper<object>(genericIReadonlyList);
             Assert.Equal(ExpectedJson, json);
 
             ISet<object> iset = new HashSet<object> { 1, true, address, null, "foo" };
-            json = Serializer.Serialize(iset);
+            json = await Serializer.SerializeWrapper(iset);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(iset);
+            json = await Serializer.SerializeWrapper<object>(iset);
             Assert.Equal(ExpectedJson, json);
 
             Stack<object> stack = new Stack<object>(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(stack);
+            json = await Serializer.SerializeWrapper(stack);
             Assert.Equal(ReversedExpectedJson, json);
 
-            json = Serializer.Serialize<object>(stack);
+            json = await Serializer.SerializeWrapper<object>(stack);
             Assert.Equal(ReversedExpectedJson, json);
 
             Queue<object> queue = new Queue<object>(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(queue);
+            json = await Serializer.SerializeWrapper(queue);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(queue);
+            json = await Serializer.SerializeWrapper<object>(queue);
             Assert.Equal(ExpectedJson, json);
 
             HashSet<object> hashset = new HashSet<object>(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(hashset);
+            json = await Serializer.SerializeWrapper(hashset);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(hashset);
+            json = await Serializer.SerializeWrapper<object>(hashset);
             Assert.Equal(ExpectedJson, json);
 
             LinkedList<object> linkedlist = new LinkedList<object>(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(linkedlist);
+            json = await Serializer.SerializeWrapper(linkedlist);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(linkedlist);
+            json = await Serializer.SerializeWrapper<object>(linkedlist);
             Assert.Equal(ExpectedJson, json);
 
             ImmutableArray<object> immutablearray = ImmutableArray.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(immutablearray);
+            json = await Serializer.SerializeWrapper(immutablearray);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(immutablearray);
+            json = await Serializer.SerializeWrapper<object>(immutablearray);
             Assert.Equal(ExpectedJson, json);
 
             IImmutableList<object> iimmutablelist = ImmutableList.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(iimmutablelist);
+            json = await Serializer.SerializeWrapper(iimmutablelist);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(iimmutablelist);
+            json = await Serializer.SerializeWrapper<object>(iimmutablelist);
             Assert.Equal(ExpectedJson, json);
 
             IImmutableStack<object> iimmutablestack = ImmutableStack.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(iimmutablestack);
+            json = await Serializer.SerializeWrapper(iimmutablestack);
             Assert.Equal(ReversedExpectedJson, json);
 
-            json = Serializer.Serialize<object>(iimmutablestack);
+            json = await Serializer.SerializeWrapper<object>(iimmutablestack);
             Assert.Equal(ReversedExpectedJson, json);
 
             IImmutableQueue<object> iimmutablequeue = ImmutableQueue.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(iimmutablequeue);
+            json = await Serializer.SerializeWrapper(iimmutablequeue);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(iimmutablequeue);
+            json = await Serializer.SerializeWrapper<object>(iimmutablequeue);
             Assert.Equal(ExpectedJson, json);
 
             IImmutableSet<object> iimmutableset = ImmutableHashSet.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(iimmutableset);
+            json = await Serializer.SerializeWrapper(iimmutableset);
             foreach (string obj in expectedObjects)
             {
                 Assert.Contains(obj, json);
             }
 
-            json = Serializer.Serialize<object>(iimmutableset);
+            json = await Serializer.SerializeWrapper<object>(iimmutableset);
             foreach (string obj in expectedObjects)
             {
                 Assert.Contains(obj, json);
             }
 
             ImmutableHashSet<object> immutablehashset = ImmutableHashSet.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(immutablehashset);
+            json = await Serializer.SerializeWrapper(immutablehashset);
             foreach (string obj in expectedObjects)
             {
                 Assert.Contains(obj, json);
             }
 
-            json = Serializer.Serialize<object>(immutablehashset);
+            json = await Serializer.SerializeWrapper<object>(immutablehashset);
             foreach (string obj in expectedObjects)
             {
                 Assert.Contains(obj, json);
             }
 
             ImmutableList<object> immutablelist = ImmutableList.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(immutablelist);
+            json = await Serializer.SerializeWrapper(immutablelist);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(immutablelist);
+            json = await Serializer.SerializeWrapper<object>(immutablelist);
             Assert.Equal(ExpectedJson, json);
 
             ImmutableStack<object> immutablestack = ImmutableStack.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(immutablestack);
+            json = await Serializer.SerializeWrapper(immutablestack);
             Assert.Equal(ReversedExpectedJson, json);
 
-            json = Serializer.Serialize<object>(immutablestack);
+            json = await Serializer.SerializeWrapper<object>(immutablestack);
             Assert.Equal(ReversedExpectedJson, json);
 
             ImmutableQueue<object> immutablequeue = ImmutableQueue.CreateRange(new List<object> { 1, true, address, null, "foo" });
-            json = Serializer.Serialize(immutablequeue);
+            json = await Serializer.SerializeWrapper(immutablequeue);
             Assert.Equal(ExpectedJson, json);
 
-            json = Serializer.Serialize<object>(immutablequeue);
+            json = await Serializer.SerializeWrapper<object>(immutablequeue);
             Assert.Equal(ExpectedJson, json);
         }
 
         [Fact]
-        public void SimpleTestClassAsRootObject()
+        public async Task SimpleTestClassAsRootObject()
         {
             // Sanity checks on test type.
             Assert.Equal(typeof(object), typeof(SimpleTestClassWithObject).GetProperty("MyInt16").PropertyType);
@@ -310,20 +311,20 @@ namespace System.Text.Json.Serialization.Tests
             obj.Initialize();
 
             // Verify with actual type.
-            string json = Serializer.Serialize(obj);
+            string json = await Serializer.SerializeWrapper(obj);
             Assert.Contains(@"""MyInt16"":1", json);
             Assert.Contains(@"""MyBooleanTrue"":true", json);
             Assert.Contains(@"""MyInt16Array"":[1]", json);
 
             // Verify with object type.
-            json = Serializer.Serialize<object>(obj);
+            json = await Serializer.SerializeWrapper<object>(obj);
             Assert.Contains(@"""MyInt16"":1", json);
             Assert.Contains(@"""MyBooleanTrue"":true", json);
             Assert.Contains(@"""MyInt16Array"":[1]", json);
         }
 
         [Fact]
-        public void NestedObjectAsRootObject()
+        public async Task NestedObjectAsRootObject()
         {
             void Verify(string json)
             {
@@ -368,43 +369,43 @@ namespace System.Text.Json.Serialization.Tests
 
             var obj = new ObjectWithObjectProperties();
 
-            string json = Serializer.Serialize(obj);
+            string json = await Serializer.SerializeWrapper(obj);
             Verify(json);
 
-            json = Serializer.Serialize<object>(obj);
+            json = await Serializer.SerializeWrapper<object>(obj);
             Verify(json);
         }
 
         [Fact]
-        public void NestedObjectAsRootObjectIgnoreNullable()
+        public async Task NestedObjectAsRootObjectIgnoreNullable()
         {
             // Ensure that null properties are properly written and support ignore.
             var obj = new ObjectWithObjectProperties();
             obj.NullableInt = null;
 
-            string json = Serializer.Serialize(obj);
+            string json = await Serializer.SerializeWrapper(obj);
             Assert.Contains(@"""NullableInt"":null", json);
 
             JsonSerializerOptions options = new JsonSerializerOptions();
             options.IgnoreNullValues = true;
-            json = Serializer.Serialize(obj, options);
+            json = await Serializer.SerializeWrapper(obj, options);
             Assert.DoesNotContain(@"""NullableInt"":null", json);
         }
 
         [Fact]
-        public void StaticAnalysisBaseline()
+        public async Task StaticAnalysisBaseline()
         {
             Customer customer = new Customer();
             customer.Initialize();
             customer.Verify();
 
-            string json = Serializer.Serialize(customer);
+            string json = await Serializer.SerializeWrapper(customer);
             Customer deserializedCustomer = JsonSerializer.Deserialize<Customer>(json);
             deserializedCustomer.Verify();
         }
 
         [Fact]
-        public void StaticAnalysis()
+        public async Task StaticAnalysis()
         {
             Customer customer = new Customer();
             customer.Initialize();
@@ -413,7 +414,7 @@ namespace System.Text.Json.Serialization.Tests
             Person person = customer;
 
             // Generic inference used <TValue> = <Person>
-            string json = Serializer.Serialize(person);
+            string json = await Serializer.SerializeWrapper(person);
 
             Customer deserializedCustomer = JsonSerializer.Deserialize<Customer>(json);
 
@@ -424,7 +425,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void WriteStringWithRuntimeType()
+        public async Task WriteStringWithRuntimeType()
         {
             Customer customer = new Customer();
             customer.Initialize();
@@ -432,7 +433,7 @@ namespace System.Text.Json.Serialization.Tests
 
             Person person = customer;
 
-            string json = Serializer.Serialize(person, person.GetType());
+            string json = await Serializer.SerializeWrapper(person, person.GetType());
 
             Customer deserializedCustomer = JsonSerializer.Deserialize<Customer>(json);
 
@@ -442,7 +443,7 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void StaticAnalysisWithRelationship()
+        public async Task StaticAnalysisWithRelationship()
         {
             UsaCustomer usaCustomer = new UsaCustomer();
             usaCustomer.Initialize();
@@ -454,7 +455,7 @@ namespace System.Text.Json.Serialization.Tests
             Customer customer = usaCustomer;
 
             // Generic inference used <TValue> = <Customer>
-            string json = Serializer.Serialize(customer);
+            string json = await Serializer.SerializeWrapper(customer);
 
             UsaCustomer deserializedCustomer = JsonSerializer.Deserialize<UsaCustomer>(json);
 
@@ -496,18 +497,18 @@ namespace System.Text.Json.Serialization.Tests
         }
 
         [Fact]
-        public void AnonymousType()
+        public async Task AnonymousType()
         {
             const string Expected = @"{""x"":1,""y"":true}";
             var value = new { x = 1, y = true };
 
             // Strongly-typed.
-            string json = Serializer.Serialize(value);
+            string json = await Serializer.SerializeWrapper(value);
             Assert.Equal(Expected, json);
 
             // Boxed.
             object objValue = value;
-            json = Serializer.Serialize(objValue);
+            json = await Serializer.SerializeWrapper(objValue);
             Assert.Equal(Expected, json);
         }
 
index c63f553..ae7ec15 100644 (file)
@@ -225,8 +225,8 @@ namespace System.Text.Json.Serialization.Tests
             Assert.Equal(1, root.ZeroLengthProperty);
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
-        public static void TestJsonPathDoesNotFailOnMultiThreads()
+        [Fact]
+        public static async Task TestJsonPathDoesNotFailOnMultiThreads()
         {
             const int ThreadCount = 8;
             const int ConcurrentTestsCount = 4;
@@ -240,7 +240,7 @@ namespace System.Text.Json.Serialization.Tests
                 tasks[i] = Task.Run(() => TestRefTask());
             }
 
-            Task.WaitAll(tasks);
+            await Task.WhenAll(tasks);
         }
 
         private static void TestIdTask()
index a92b388..9b93326 100644 (file)
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.IO;
@@ -19,96 +19,90 @@ namespace System.Text.Json.Serialization.Tests
         public static SerializationWrapper StreamSerializerWithSmallBuffer => new StreamSerializerWrapperWithSmallBuffer();
         public static SerializationWrapper WriterSerializer => new WriterSerializerWrapper();
 
-        protected internal abstract string Serialize(object value, Type inputType, JsonSerializerOptions options = null);
+        protected internal abstract Task<string> SerializeWrapper(object value, Type inputType, JsonSerializerOptions options = null);
 
-        protected internal abstract string Serialize<T>(T value, JsonSerializerOptions options = null);
+        protected internal abstract Task<string> SerializeWrapper<T>(T value, JsonSerializerOptions options = null);
 
 
         private class SpanSerializerWrapper : SerializationWrapper
         {
-            protected internal override string Serialize(object value, Type inputType, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper(object value, Type inputType, JsonSerializerOptions options = null)
             {
                 byte[] result = JsonSerializer.SerializeToUtf8Bytes(value, inputType, options);
-                return Encoding.UTF8.GetString(result);
+                return Task.FromResult(Encoding.UTF8.GetString(result));
             }
 
-            protected internal override string Serialize<T>(T value, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper<T>(T value, JsonSerializerOptions options = null)
             {
                 byte[] result = JsonSerializer.SerializeToUtf8Bytes<T>(value, options);
-                return Encoding.UTF8.GetString(result);
+                return Task.FromResult(Encoding.UTF8.GetString(result));
             }
         }
 
         private class StringSerializerWrapper : SerializationWrapper
         {
-            protected internal override string Serialize(object value, Type inputType, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper(object value, Type inputType, JsonSerializerOptions options = null)
             {
-                return JsonSerializer.Serialize(value, inputType, options);
+                return Task.FromResult(JsonSerializer.Serialize(value, inputType, options));
             }
 
-            protected internal override string Serialize<T>(T value, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper<T>(T value, JsonSerializerOptions options = null)
             {
-                return JsonSerializer.Serialize(value, options);
+                return Task.FromResult(JsonSerializer.Serialize(value, options));
             }
         }
 
         private class StreamSerializerWrapper : SerializationWrapper
         {
-            protected internal override string Serialize(object value, Type inputType, JsonSerializerOptions options = null)
+            protected internal override async Task<string> SerializeWrapper(object value, Type inputType, JsonSerializerOptions options = null)
             {
-                return Task.Run(async () =>
-                {
-                    using var stream = new MemoryStream();
-                    await JsonSerializer.SerializeAsync(stream, value, inputType, options);
-                    return Encoding.UTF8.GetString(stream.ToArray());
-                }).GetAwaiter().GetResult();
+                using var stream = new MemoryStream();
+                await JsonSerializer.SerializeAsync(stream, value, inputType, options);
+                return Encoding.UTF8.GetString(stream.ToArray());
             }
 
-            protected internal override string Serialize<T>(T value, JsonSerializerOptions options = null)
+            protected internal override async Task<string> SerializeWrapper<T>(T value, JsonSerializerOptions options = null)
             {
-                return Task.Run(async () =>
-                {
-                    using var stream = new MemoryStream();
-                    await JsonSerializer.SerializeAsync<T>(stream, value, options);
-                    return Encoding.UTF8.GetString(stream.ToArray());
-                }).GetAwaiter().GetResult();
+                using var stream = new MemoryStream();
+                await JsonSerializer.SerializeAsync<T>(stream, value, options);
+                return Encoding.UTF8.GetString(stream.ToArray());
             }
         }
 
         private class StreamSerializerWrapperWithSmallBuffer : StreamSerializerWrapper
         {
-            protected internal override string Serialize(object value, Type inputType, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper(object value, Type inputType, JsonSerializerOptions options = null)
             {
                 if (options == null)
                 {
                     options = _optionsWithSmallBuffer;
                 }
 
-                return base.Serialize(value, inputType, options);
+                return base.SerializeWrapper(value, inputType, options);
             }
 
-            protected internal override string Serialize<T>(T value, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper<T>(T value, JsonSerializerOptions options = null)
             {
-                return base.Serialize<T>(value, options);
+                return base.SerializeWrapper<T>(value, options);
             }
         }
 
         private class WriterSerializerWrapper : SerializationWrapper
         {
-            protected internal override string Serialize(object value, Type inputType, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper(object value, Type inputType, JsonSerializerOptions options = null)
             {
                 using MemoryStream stream = new MemoryStream();
                 using var writer = new Utf8JsonWriter(stream);
                 JsonSerializer.Serialize(writer, value, inputType, options);
-                return Encoding.UTF8.GetString(stream.ToArray());
+                return Task.FromResult(Encoding.UTF8.GetString(stream.ToArray()));
             }
 
-            protected internal override string Serialize<T>(T value, JsonSerializerOptions options = null)
+            protected internal override Task<string> SerializeWrapper<T>(T value, JsonSerializerOptions options = null)
             {
                 using MemoryStream stream = new MemoryStream();
                 using var writer = new Utf8JsonWriter(stream);
                 JsonSerializer.Serialize<T>(writer, value, options);
-                return Encoding.UTF8.GetString(stream.ToArray());
+                return Task.FromResult(Encoding.UTF8.GetString(stream.ToArray()));
             }
         }
     }
index 3a46b51..4810dcb 100644 (file)
@@ -1,4 +1,4 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Collections;
@@ -18,14 +18,15 @@ namespace System.Text.Json.Serialization.Tests
     {
         [Fact]
         [ActiveIssue("https://github.com/dotnet/runtime/issues/35927", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoInterpreter))]
+        [ActiveIssue("https://github.com/dotnet/runtime/issues/35927", TestPlatforms.Browser)]
         public static async Task HandleCollectionsAsync()
         {
-            await RunTest<string>();
-            await RunTest<ClassWithKVP>();
-            await RunTest<ImmutableStructWithStrings>();
+            await RunTestAsync<string>();
+            await RunTestAsync<ClassWithKVP>();
+            await RunTestAsync<ImmutableStructWithStrings>();
         }
 
-        private static async Task RunTest<TElement>()
+        private static async Task RunTestAsync<TElement>()
         {
             foreach ((Type, int) pair in CollectionTestData<TElement>())
             {
index d365fc5..1881fc8 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Text.Json.Serialization.Tests
             await Assert.ThrowsAsync<ArgumentNullException>(async () => await JsonSerializer.DeserializeAsync(new MemoryStream(), (Type)null));
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+        [Fact]
         public static async Task ReadSimpleObjectAsync()
         {
             using (MemoryStream stream = new MemoryStream(SimpleTestClass.s_data))
@@ -34,7 +34,7 @@ namespace System.Text.Json.Serialization.Tests
             }
         }
 
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+        [Fact]
         public static async Task ReadSimpleObjectWithTrailingTriviaAsync()
         {
             byte[] data = Encoding.UTF8.GetBytes(SimpleTestClass.s_json + " /* Multi\r\nLine Comment */\t");
index a7bcbda..6862a12 100644 (file)
@@ -485,6 +485,12 @@ namespace System.Text.Json.Tests
         [MemberData(nameof(LargeTestCases))]
         public static void TestJsonReaderLargeUtf8SegmentSizeOne(bool compactData, TestCaseType type, string jsonString)
         {
+            // Skipping really large JSON on Browser to prevent OOM
+            if (PlatformDetection.IsBrowser && (type == TestCaseType.Json40KB || type == TestCaseType.Json400KB || type == TestCaseType.ProjectLockJson))
+            {
+                return;
+            }
+
             ReadFullySegmentSizeOne(compactData, type, jsonString);
         }
 
index 2945aeb..50926d7 100644 (file)
@@ -4,6 +4,7 @@
 using System.Collections.Generic;
 using System.Globalization;
 using System.IO;
+using Microsoft.DotNet.XUnitExtensions;
 using Newtonsoft.Json;
 using Xunit;
 
@@ -1608,7 +1609,7 @@ namespace System.Text.Json.Tests
             }
         }
 
-        [Theory]
+        [ConditionalTheory]
         [InlineData(1)]
         [InlineData(2)]
         [InlineData(4)]
@@ -1625,6 +1626,11 @@ namespace System.Text.Json.Tests
         [InlineData(512)]
         public static void TestDepth(int depth)
         {
+            if (PlatformDetection.IsMonoInterpreter && depth >= 256)
+            {
+                throw new SkipTestException("Takes very long to run on interpreter.");
+            }
+
             foreach (JsonCommentHandling commentHandling in Enum.GetValues(typeof(JsonCommentHandling)))
             {
                 for (int i = 0; i < depth; i++)
index 9d88585..fc3cd91 100644 (file)
@@ -21,8 +21,6 @@
   </ItemGroup>
 
   <ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(RunDisabledWasmTests)' != 'true'">
-    <!-- Builds and runs but fails hard enough to not produce any output XML -->
-    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.Tests.csproj" />
     <!-- Builds currently do not pass -->
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.VisualBasic.Core\tests\Microsoft.VisualBasic.Core.Tests.csproj" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.CodeDom\tests\System.CodeDom.Tests.csproj" />