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 c9dcd97..391a571 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 9634310..7842a0b 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 a485c35..4a26cda 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 7ced542..863590f 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 d41ebad..edb6aeb 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 cb78774..2e42fc6 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 cb7947a..b4976ba 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 0d44ddf..2d72329 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 0da0392..e408f09 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 b02c1e0..6330c1d 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 3a7be82..8fa60e5 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 4d758ad..3455a3e 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 32f75c4..b21ae5d 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 722b5f2..b37c12d 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 d1559ef..e8916e4 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 57c6902..28625c9 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 2b88bbb..74240e7 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 1f495ef..030c464 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