Skip to content

Commit

Permalink
Add tests for contract customization per feedback in dotnet#70435 (do…
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq committed Jul 1, 2022
1 parent 32670bd commit 4935319
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 4935319

Please sign in to comment.