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 1414
1515using Destructurama . JsonNet . Tests . Support ;
1616using Newtonsoft . Json ;
17+ using Newtonsoft . Json . Linq ;
1718using Serilog ;
19+ using Serilog . Core ;
1820using Serilog . Events ;
1921using Shouldly ;
2022using Xunit ;
@@ -85,4 +87,26 @@ public void TryDestructure_Should_Return_False_When_Called_With_Null()
8587 var policy = new JsonNetDestructuringPolicy ( ) ;
8688 policy . TryDestructure ( null ! , null ! , out _ ) . ShouldBeFalse ( ) ;
8789 }
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+ }
88112}
You can’t perform that action at this time.
0 commit comments