@@ -28,8 +28,10 @@ internal class HasName
2828
2929public class JsonNetTypesDestructuringTests
3030{
31- [ Fact ]
32- public void AttributesAreConsultedWhenDestructuring ( )
31+ [ Theory ]
32+ [ InlineData ( TypeNameHandling . Auto ) ]
33+ [ InlineData ( TypeNameHandling . Objects ) ]
34+ public void AttributesAreConsultedWhenDestructuring ( TypeNameHandling typeNameHandling )
3335 {
3436 LogEvent evt = null ! ;
3537
@@ -51,7 +53,7 @@ public void AttributesAreConsultedWhenDestructuring()
5153
5254 string ser = JsonConvert . SerializeObject ( test , new JsonSerializerSettings
5355 {
54- TypeNameHandling = TypeNameHandling . Auto
56+ TypeNameHandling = typeNameHandling
5557 } ) ;
5658 var dyn = JsonConvert . DeserializeObject < dynamic > ( ser ) ;
5759
@@ -67,5 +69,20 @@ public void AttributesAreConsultedWhenDestructuring()
6769 props [ "E" ] . LiteralValue ( ) . ShouldBeNull ( ) ;
6870 props [ "ESPN" ] . ShouldBeOfType < DictionaryValue > ( ) ;
6971 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 ( ) ;
7087 }
7188}
0 commit comments