From 5ec8c1810a4b0d5a603b30aa904baddd0b47f5e9 Mon Sep 17 00:00:00 2001 From: Weihan Li Date: Thu, 1 Aug 2024 00:53:47 +0800 Subject: [PATCH] update test case and fix some formatting --- .../tests/Common/PropertyVisibilityTests.cs | 9 +++++++-- .../Serialization/PropertyVisibilityTests.cs | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Text.Json/tests/Common/PropertyVisibilityTests.cs b/src/libraries/System.Text.Json/tests/Common/PropertyVisibilityTests.cs index bd46878470d6d..c619e5be4d0aa 100644 --- a/src/libraries/System.Text.Json/tests/Common/PropertyVisibilityTests.cs +++ b/src/libraries/System.Text.Json/tests/Common/PropertyVisibilityTests.cs @@ -2168,7 +2168,12 @@ public async Task IgnoreConditionWhenWritingDefault_WinsOver_IgnoreReadOnlyField [Fact] public async Task JsonIgnoreCondition_WhenWriting() { - var json = await Serializer.SerializeWrapper(new JsonIgnoreCondition_WhenReadingWritingTestModel{ Age = 10, Name = "Mike" }); + var options = new JsonSerializerOptions { IgnoreReadOnlyProperties = true }; + var json = await Serializer.SerializeWrapper + ( + new JsonIgnoreCondition_WhenReadingWritingTestModel { Age = 10, Name = "Mike" }, + options + ); Assert.Equal("""{"Age":10}""", json); } @@ -2182,7 +2187,7 @@ public async Task JsonIgnoreCondition_WhenReading() } public class JsonIgnoreCondition_WhenReadingWritingTestModel - { + { [JsonIgnore(Condition = JsonIgnoreCondition.WhenReading)] public int Age { get; set; } [JsonIgnore(Condition = JsonIgnoreCondition.WhenWriting)] diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/PropertyVisibilityTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/PropertyVisibilityTests.cs index 21b0792d84dda..21f220509ad36 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/PropertyVisibilityTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Tests/Serialization/PropertyVisibilityTests.cs @@ -129,7 +129,7 @@ public override async Task HonorJsonPropertyName_PrivateGetter() Assert.Equal(MySmallEnum.AnotherValue, obj.GetProxy()); // JsonInclude for private members not supported in source gen - await Assert.ThrowsAsync(async() => await Serializer.SerializeWrapper(obj)); + await Assert.ThrowsAsync(async () => await Serializer.SerializeWrapper(obj)); } [Fact] @@ -331,7 +331,8 @@ public override async Task ClassWithIgnoredAndPrivateMembers_DoesNotIncludeIgnor [JsonSerializable(typeof(IDiamondInterfaceHierarchyWithNamingConflict.IJoinInterface), TypeInfoPropertyName = "IDiamondInterfaceHierarchyWithNamingConflictIJoinInterface")] [JsonSerializable(typeof(IDiamondInterfaceHierarchyWithNamingConflictUsingAttribute.IJoinInterface), TypeInfoPropertyName = "IDiamondInterfaceHierarchyWithNamingConflictUsingAttributeIJoinInterface")] [JsonSerializable(typeof(CollectionWithPrivateElementType))] - [JsonSerializable(typeof(DictionaryWithPrivateKeyAndValueType))][JsonSerializable(typeof(ClassWithIgnoredAndPrivateMembers))] + [JsonSerializable(typeof(DictionaryWithPrivateKeyAndValueType))] + [JsonSerializable(typeof(ClassWithIgnoredAndPrivateMembers))] [JsonSerializable(typeof(ClassWithInternalJsonIncludeProperties))] [JsonSerializable(typeof(ClassWithIgnoredAndPrivateMembers))] [JsonSerializable(typeof(ClassUsingIgnoreWhenWritingDefaultAttribute))]