Skip to content

Commit 40d7ff6

Browse files
authored
Add more tests (#33)
1 parent 9809a17 commit 40d7ff6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Destructurama.JsonNet.Tests/JsonNetTypesDestructuringTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
using Destructurama.JsonNet.Tests.Support;
1616
using Newtonsoft.Json;
17+
using Newtonsoft.Json.Linq;
1718
using Serilog;
19+
using Serilog.Core;
1820
using Serilog.Events;
1921
using Shouldly;
2022
using 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
}

0 commit comments

Comments
 (0)