Move collection tests to dedicated class + more clean up
authorLayomi Akinrinade <laakinri@microsoft.com>
Fri, 1 May 2020 17:21:21 +0000 (10:21 -0700)
committerLayomi Akinrinade <laakinri@microsoft.com>
Sat, 2 May 2020 02:46:23 +0000 (19:46 -0700)
19 files changed:
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterFactory.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoOfT.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Concurrent.Write.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Concurrent.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Generic.Read.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Generic.Write.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Immutable.Read.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Immutable.Write.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.NonGeneric.Read.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.NonGeneric.Write.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.ObjectModel.Read.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.ObjectModel.Write.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Specialized.Read.cs
src/libraries/System.Text.Json/tests/Serialization/CollectionTests/CollectionTests.Specialized.Write.cs
src/libraries/System.Text.Json/tests/Serialization/TestClasses/TestClasses.ImmutableCollections.cs
src/libraries/System.Text.Json/tests/Serialization/Value.ReadTests.cs

index c9dcd97118d59d40db47acc1c44af17b569bfe04..391a5710204b80f0965dd7ce0b7a8b178bdc83cc 100644 (file)
@@ -58,7 +58,7 @@ namespace System.Text.Json.Serialization.Converters
                     }
                     break;
                 default:
-                    Debug.Fail("We shouldn't be here if there are more than 4 parameters.");
+                    Debug.Fail("More than 4 params: we should be in override for LargeObjectWithParameterizedConstructorConverter.");
                     throw new InvalidOperationException();
             }
 
@@ -98,7 +98,7 @@ namespace System.Text.Json.Serialization.Converters
                             arguments.Arg3 = ((JsonParameterInfo<TArg3>)parameterInfo).TypedDefaultValue!;
                             break;
                         default:
-                            Debug.Fail("We shouldn't be here if there are more than 4 parameters.");
+                            Debug.Fail("More than 4 params: we should be in override for LargeObjectWithParameterizedConstructorConverter.");
                             throw new InvalidOperationException();
                     }
                 }
index 9634310ebf10fa16907e8d5f0b53d63a591dfc0f..7842a0b8b7b3b0404b65ae5081e16f57d34f1a14 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Text.Json.Serialization.Converters
 
             if (!state.SupportContinuation && !shouldReadPreservedReferences)
             {
-                // Fast path that avoids maintaining state variables and dealing with preserved references.
+                // Fast path that avoids maintaining state variables.
 
                 ReadOnlySpan<byte> originalSpan = reader.OriginalSpan;
 
@@ -72,7 +72,7 @@ namespace System.Text.Json.Serialization.Converters
             }
             else
             {
-                // Slower path that supports continuation and preserved references.
+                // Slower path that supports continuation.
 
                 if (state.Current.ObjectState == StackFrameObjectState.None)
                 {
index a485c3539d947d5e5ee456e89d4f7bda27804e8f..4a26cdaab2d80acdeba9017a483dc32bc04d223b 100644 (file)
@@ -40,11 +40,15 @@ namespace System.Text.Json.Serialization
 
         internal override JsonPropertyInfo CreateJsonPropertyInfo()
         {
+            Debug.Fail("We should never get here.");
+
             throw new InvalidOperationException();
         }
 
         internal override JsonParameterInfo CreateJsonParameterInfo()
         {
+            Debug.Fail("We should never get here.");
+
             throw new InvalidOperationException();
         }
 
@@ -68,8 +72,7 @@ namespace System.Text.Json.Serialization
             JsonSerializerOptions options,
             ref ReadStack state)
         {
-            // We should never get here.
-            Debug.Assert(false);
+            Debug.Fail("We should never get here.");
 
             throw new InvalidOperationException();
         }
@@ -80,8 +83,7 @@ namespace System.Text.Json.Serialization
             JsonSerializerOptions options,
             ref WriteStack state)
         {
-            // We should never get here.
-            Debug.Assert(false);
+            Debug.Fail("We should never get here.");
 
             throw new InvalidOperationException();
         }
@@ -94,8 +96,7 @@ namespace System.Text.Json.Serialization
             JsonSerializerOptions options,
             ref WriteStack state)
         {
-            // We should never get here.
-            Debug.Assert(false);
+            Debug.Fail("We should never get here.");
 
             throw new InvalidOperationException();
         }
index 7ced542e17fffa0f4b3a81ded62f9aef7e646873..863590f3b5f2befeaa1042f94d4b58be51c73aba 100644 (file)
@@ -11,6 +11,8 @@ namespace System.Text.Json
     /// <summary>
     /// Represents a strongly-typed property to prevent boxing and to create a direct delegate to the getter\setter.
     /// </summary>
+    /// <typeparamref name="T"/> is the <see cref="JsonConverter{T}.TypeToConvert"/> for either the property's converter,
+    /// or a type's converter, if the current instance is a <see cref="JsonClassInfo.PropertyInfoForClassInfo"/>.
     internal sealed class JsonPropertyInfo<T> : JsonPropertyInfo
     {
         public Func<object, T>? Get { get; private set; }
index d41ebadcf7b9d19eb9be7b5015515929c2a1b425..edb6aebf97bd03b84e9c1e24e7f7cb57c33ba63c 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Text.Json
             if (state.Current.ObjectState < StackFrameObjectState.ReadAheadNameOrEndObject)
             {
                 // Read the first metadata property name.
-                if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadNameOrEndObject))
+                if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadNameOrEndObject))
                 {
                     return false;
                 }
@@ -100,14 +100,14 @@ namespace System.Text.Json
 
             if (state.Current.ObjectState == StackFrameObjectState.ReadAheadRefValue)
             {
-                if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefValue))
+                if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefValue))
                 {
                     return false;
                 }
             }
             else if (state.Current.ObjectState == StackFrameObjectState.ReadAheadIdValue)
             {
-                if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadIdValue))
+                if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadIdValue))
                 {
                     return false;
                 }
@@ -153,7 +153,7 @@ namespace System.Text.Json
 
             if (state.Current.ObjectState == StackFrameObjectState.ReadAheadRefEndObject)
             {
-                if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefEndObject))
+                if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefEndObject))
                 {
                     return false;
                 }
@@ -174,7 +174,7 @@ namespace System.Text.Json
 
             if (state.Current.ObjectState == StackFrameObjectState.ReadAheadValuesName)
             {
-                if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesName))
+                if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesName))
                 {
                     return false;
                 }
@@ -202,7 +202,7 @@ namespace System.Text.Json
 
             if (state.Current.ObjectState == StackFrameObjectState.ReadAheadValuesStartArray)
             {
-                if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesStartArray))
+                if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesStartArray))
                 {
                     return false;
                 }
@@ -222,8 +222,10 @@ namespace System.Text.Json
         }
 
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        private static bool ReadAheadMetadataAndSetState(ref Utf8JsonReader reader, ref ReadStack state, StackFrameObjectState nextState)
+        private static bool TryReadAheadMetadataAndSetState(ref Utf8JsonReader reader, ref ReadStack state, StackFrameObjectState nextState)
         {
+            // If we can't read here, the read will be completed at the root API by asking the stream for more data.
+            // Set the state so we know where to resume on re-entry.
             state.Current.ObjectState = nextState;
             return reader.Read();
         }
index cb78774b831d19a672b772824a8f46df2d97b3b7..2e42fc674197a56a6c10110f9fc7ba2cc8e4511e 100644 (file)
@@ -7,7 +7,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void Write_ConcurrentCollection()
index cb7947ae640570be48a3b288922d3a24495c2219..b4976ba357d28d5e4f4aa2082487f8dddefc1a3f 100644 (file)
@@ -7,7 +7,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void Read_ConcurrentCollection()
index 0d44ddf9550359e0da33c7b66337769577d3e02e..2d72329f494806f08b6ca864ed2e4df4b8bb3ec3 100644 (file)
@@ -8,7 +8,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void ReadListOfList()
index 0da0392f5ddd5cefc7687760a393dd6a297e9917..e408f09b0e7fd069ce48385827305b44274d3ec7 100644 (file)
@@ -8,7 +8,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void WriteListOfList()
index b02c1e0b995fe4d6c8e63fa98286e8d854bae3b9..6330c1dede6a47953bb3ef44082a33a727d6d8dc 100644 (file)
@@ -5,12 +5,11 @@
 using System.Collections.Generic;
 using System.Collections.Immutable;
 using System.Linq;
-using System.Text.Json.Tests;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void ReadImmutableArrayOfImmutableArray()
index 3a7be82e8bd5f9921695d279342544f8e8524d38..8fa60e5aeb2e2a17c14f38ed0f57cc346eea067d 100644 (file)
@@ -4,12 +4,11 @@
 
 using System.Collections.Generic;
 using System.Collections.Immutable;
-using System.Text.Json.Tests;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void WriteImmutableArrayOfImmutableArray()
index 4d758ad69ec3f9843828df0f950755c422a376c7..3455a3e38f32b7aca463982948cca4b894e63165 100644 (file)
@@ -8,7 +8,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void ReadGenericIEnumerableOfIEnumerable()
index 32f75c4a160a47228d0c152247780ce13157a6d7..b21ae5d177fb39ced61f5e2a46f6f246d043d7b3 100644 (file)
@@ -8,7 +8,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void WriteIEnumerableOfIEnumerable()
index 722b5f27e95031ded96e6d569e3e70cb1e278d25..b37c12d1724ffad797253dfc88a2434828d3ae9a 100644 (file)
@@ -7,7 +7,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void Read_ObjectModelCollection()
index d1559ef1f9a028c45e99823b6bcec748aebd2d03..e8916e4744e0704580089b6eb7d58ea9ca5a301d 100644 (file)
@@ -8,7 +8,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void Write_ObjectModelCollection()
index 57c6902471071e2a7c4f74e2390a4a8e2bb2b6f3..28625c909848dced832d10276ac7c0cad25dcf55 100644 (file)
@@ -7,7 +7,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void Read_SpecializedCollection()
index 2b88bbbff7c8105ac42072c4e178d58174df41d8..74240e7541dbc0edf40abbb8666b36fff5a869c5 100644 (file)
@@ -7,7 +7,7 @@ using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
 {
-    public static partial class ValueTests
+    public static partial class CollectionTests
     {
         [Fact]
         public static void Write_SpecializedCollection()
index e28c63d43df5270dbfc4721542cc8a5edd574756..8296225d4855da07068b4d43d822d30e9b3455b5 100644 (file)
@@ -5,7 +5,6 @@
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Immutable;
-using System.Linq;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests
index 1f495efa27c39771380c22277ef29587ec657a7d..030c464e42b92abcbf994b4341576f10d7637942 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Globalization;
+using System.Runtime.CompilerServices;
 using Xunit;
 
 namespace System.Text.Json.Serialization.Tests