File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
src/Destructurama.JsonNet.Tests Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 14
14
15
15
using Destructurama . JsonNet . Tests . Support ;
16
16
using Newtonsoft . Json ;
17
+ using Newtonsoft . Json . Linq ;
17
18
using Serilog ;
19
+ using Serilog . Core ;
18
20
using Serilog . Events ;
19
21
using Shouldly ;
20
22
using Xunit ;
@@ -85,4 +87,26 @@ public void TryDestructure_Should_Return_False_When_Called_With_Null()
85
87
var policy = new JsonNetDestructuringPolicy ( ) ;
86
88
policy . TryDestructure ( null ! , null ! , out _ ) . ShouldBeFalse ( ) ;
87
89
}
90
+
91
+ [ Fact ]
92
+ public void TryDestructure_Should_Handle_TypeToken_As_Ordinal_Property_When_Not_String ( )
93
+ {
94
+ var policy = new JsonNetDestructuringPolicy ( ) ;
95
+ var o = new JObject ( new JProperty ( "$type" , 42 ) ) ;
96
+ policy . TryDestructure ( o , new StubFactory ( ) , out var value ) . ShouldBeTrue ( ) ;
97
+ var sv = value . ShouldBeOfType < StructureValue > ( ) ;
98
+ sv . Properties . Count . ShouldBe ( 1 ) ;
99
+ sv . Properties [ 0 ] . Name . ShouldBe ( "$type" ) ;
100
+ sv . Properties [ 0 ] . Value . LiteralValue ( ) . ShouldBe ( 42 ) ;
101
+ }
102
+
103
+ private sealed class StubFactory : ILogEventPropertyValueFactory
104
+ {
105
+ public LogEventPropertyValue CreatePropertyValue ( object ? value , bool destructureObjects = false )
106
+ {
107
+ return ( ( JToken ) value ! ) . Value < int > ( ) == 42
108
+ ? ( LogEventPropertyValue ) new ScalarValue ( 42 )
109
+ : throw new NotImplementedException ( ) ;
110
+ }
111
+ }
88
112
}
You can’t perform that action at this time.
0 commit comments