Add tests for immutable object
authorLayomi Akinrinade <laakinri@microsoft.com>
Thu, 7 May 2020 22:16:37 +0000 (15:16 -0700)
committerLayomi Akinrinade <laakinri@microsoft.com>
Thu, 7 May 2020 22:16:37 +0000 (15:16 -0700)
src/libraries/System.Text.Json/tests/Serialization/CustomConverterTests/CustomConverterTests.HandleNull.cs

index c8ca7e1..19b359f 100644 (file)
@@ -123,6 +123,7 @@ namespace System.Text.Json.Serialization.Tests
             // Serializer throws JsonException if null is assigned to value that can't be null.
             Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<Point_2D_Struct>("null", options));
             Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<ClassWithPoint>(@"{""MyPoint"":null}", options));
+            Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<ImmutableClassWithPoint>(@"{""MyPoint"":null}", options));
             Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<List<Point_2D_Struct>>("[null]", options));
             Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<Dictionary<string, Point_2D_Struct>>(@"{""MyPoint"":null}", options));
         }
@@ -137,6 +138,13 @@ namespace System.Text.Json.Serialization.Tests
             public Point_2D_Struct MyPoint { get; set; }
         }
 
+        private class ImmutableClassWithPoint
+        {
+            public Point_2D_Struct MyPoint { get; }
+
+            public ImmutableClassWithPoint(Point_2D_Struct myPoint) => MyPoint = myPoint;
+        }
+
         [Fact]
         public static void ComplexValueTypeConverter_NullOptIn()
         {