Skip to content

Commit

Permalink
Add tests for contract customization per feedback in dotnet#70435
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq committed Jul 1, 2022
1 parent e589996 commit 6162085
Show file tree
Hide file tree
Showing 2 changed files with 321 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,22 @@ public static void TypeInfoKindNoneNumberHandling()
Assert.Equal(testObj.IntProp, deserialized.IntProp);
}

[Theory]
[InlineData(typeof(List<int>), JsonTypeInfoKind.Enumerable)]
[InlineData(typeof(Dictionary<string, int>), JsonTypeInfoKind.Dictionary)]
[InlineData(typeof(object), JsonTypeInfoKind.None)]
[InlineData(typeof(string), JsonTypeInfoKind.None)]
public static void AddingPropertyToNonObjectJsonTypeInfoKindThrows(Type type, JsonTypeInfoKind expectedKind)
{
JsonSerializerOptions options = new();
DefaultJsonTypeInfoResolver resolver = new();
JsonTypeInfo typeInfo = resolver.GetTypeInfo(type, options);
Assert.Equal(expectedKind, typeInfo.Kind);

JsonPropertyInfo property = typeInfo.CreateJsonPropertyInfo(typeof(int), "test");
Assert.Throws<InvalidOperationException>(() => typeInfo.Properties.Add(property));
}

[Fact]
public static void RecursiveTypeNumberHandling()
{
Expand Down
Loading

0 comments on commit 6162085

Please sign in to comment.