@@ -28,8 +28,10 @@ internal class HasName
28
28
29
29
public class JsonNetTypesDestructuringTests
30
30
{
31
- [ Fact ]
32
- public void AttributesAreConsultedWhenDestructuring ( )
31
+ [ Theory ]
32
+ [ InlineData ( TypeNameHandling . Auto ) ]
33
+ [ InlineData ( TypeNameHandling . Objects ) ]
34
+ public void AttributesAreConsultedWhenDestructuring ( TypeNameHandling typeNameHandling )
33
35
{
34
36
LogEvent evt = null ! ;
35
37
@@ -51,7 +53,7 @@ public void AttributesAreConsultedWhenDestructuring()
51
53
52
54
string ser = JsonConvert . SerializeObject ( test , new JsonSerializerSettings
53
55
{
54
- TypeNameHandling = TypeNameHandling . Auto
56
+ TypeNameHandling = typeNameHandling
55
57
} ) ;
56
58
var dyn = JsonConvert . DeserializeObject < dynamic > ( ser ) ;
57
59
@@ -67,5 +69,20 @@ public void AttributesAreConsultedWhenDestructuring()
67
69
props [ "E" ] . LiteralValue ( ) . ShouldBeNull ( ) ;
68
70
props [ "ESPN" ] . ShouldBeOfType < DictionaryValue > ( ) ;
69
71
props [ "WSPN" ] . ShouldBeOfType < DictionaryValue > ( ) ;
72
+
73
+ foreach ( var value in props . Values . OfType < StructureValue > ( ) )
74
+ {
75
+ if ( typeNameHandling == TypeNameHandling . Auto )
76
+ value . TypeTag . ShouldBeNull ( ) ;
77
+ else if ( typeNameHandling == TypeNameHandling . Objects )
78
+ value . TypeTag . ShouldNotBeNull ( ) ;
79
+ }
80
+ }
81
+
82
+ [ Fact ]
83
+ public void TryDestructure_Should_Return_False_When_Called_With_Null ( )
84
+ {
85
+ var policy = new JsonNetDestructuringPolicy ( ) ;
86
+ policy . TryDestructure ( null ! , null ! , out _ ) . ShouldBeFalse ( ) ;
70
87
}
71
88
}
0 commit comments