@@ -89,7 +89,7 @@ public void TryDestructure_Should_Return_False_When_Called_With_Null()
89
89
}
90
90
91
91
[ Fact ]
92
- public void TryDestructure_Should_Handle_TypeToken_As_Ordinal_Property_When_Not_String ( )
92
+ public void TryDestructure_Should_Handle_TypeToken_As_Ordinal_Property_When_Its_Value_Not_String ( )
93
93
{
94
94
var policy = new JsonNetDestructuringPolicy ( ) ;
95
95
var o = new JObject ( new JProperty ( "$type" , 42 ) ) ;
@@ -100,13 +100,30 @@ public void TryDestructure_Should_Handle_TypeToken_As_Ordinal_Property_When_Not_
100
100
sv . Properties [ 0 ] . Value . LiteralValue ( ) . ShouldBe ( 42 ) ;
101
101
}
102
102
103
+ [ Fact ]
104
+ public void TryDestructure_Should_Handle_TypeToken_As_Ordinal_Property_When_Its_Not_JValue ( )
105
+ {
106
+ var policy = new JsonNetDestructuringPolicy ( ) ;
107
+ var o = new JObject ( new JProperty ( "$type" , new JArray ( 1 , 2 , 3 ) ) ) ;
108
+ policy . TryDestructure ( o , new StubFactory ( ) , out var value ) . ShouldBeTrue ( ) ;
109
+ var sv = value . ShouldBeOfType < StructureValue > ( ) ;
110
+ sv . Properties . Count . ShouldBe ( 1 ) ;
111
+ sv . Properties [ 0 ] . Name . ShouldBe ( "$type" ) ;
112
+ var seq = sv . Properties [ 0 ] . Value . ShouldBeOfType < SequenceValue > ( ) ;
113
+ seq . Elements . Count . ShouldBe ( 3 ) ;
114
+ }
115
+
103
116
private sealed class StubFactory : ILogEventPropertyValueFactory
104
117
{
105
118
public LogEventPropertyValue CreatePropertyValue ( object ? value , bool destructureObjects = false )
106
119
{
107
- return ( ( JToken ) value ! ) . Value < int > ( ) == 42
108
- ? ( LogEventPropertyValue ) new ScalarValue ( 42 )
109
- : throw new NotImplementedException ( ) ;
120
+ if ( value is JArray arr && arr . Values < int > ( ) . SequenceEqual ( [ 1 , 2 , 3 ] ) )
121
+ return new SequenceValue ( new [ ] { new ScalarValue ( 1 ) , new ScalarValue ( 2 ) , new ScalarValue ( 3 ) } ) ;
122
+
123
+ if ( value is JToken t && t . Value < int > ( ) == 42 )
124
+ return new ScalarValue ( 42 ) ;
125
+
126
+ throw new NotImplementedException ( ) ;
110
127
}
111
128
}
112
129
}
0 commit comments