Adds tests for missing object and collection properties in S.T.J.S (#34559)
authorMarcus Turewicz <24448509+marcusturewicz@users.noreply.github.com>
Mon, 6 Apr 2020 17:27:59 +0000 (03:27 +1000)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2020 17:27:59 +0000 (12:27 -0500)
src/libraries/System.Text.Json/tests/Serialization/PropertyVisibilityTests.cs

index d7b4791..4127189 100644 (file)
@@ -82,6 +82,24 @@ namespace System.Text.Json.Serialization.Tests
             Assert.Null(obj.Class);
         }
 
+        [Fact]
+        public static void MissingObjectProperty()
+        {
+            ClassWithMissingObjectProperty obj
+                = JsonSerializer.Deserialize<ClassWithMissingObjectProperty>(@"{ ""Object"": {} }");
+
+            Assert.Null(obj.Collection);
+        }
+
+        [Fact]
+        public static void MissingCollectionProperty()
+        {
+            ClassWithMissingCollectionProperty obj
+                = JsonSerializer.Deserialize<ClassWithMissingCollectionProperty>(@"{ ""Collection"": [] }");
+
+            Assert.Null(obj.Object);
+        }
+
         private class ClassWithPublicGetterAndPrivateSetter
         {
             public NestedClass Class { get; private set; }
@@ -271,7 +289,15 @@ namespace System.Text.Json.Serialization.Tests
             public ClassWithIgnoredUnsupportedBigInteger MyClass { get; set; }
         }
 
-        // Todo: https://github.com/dotnet/runtime/issues/32348
+        public class ClassWithMissingObjectProperty
+        {
+            public object[] Collection { get; set; }
+        }
+
+        public class ClassWithMissingCollectionProperty
+        {
+            public object Object { get; set; }
+        }
 
         public class ClassWithPrivateSetterAndGetter
         {