Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Destructurama.JsonNet.Tests/JsonNetTypesDestructuringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

using Destructurama.JsonNet.Tests.Support;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Shouldly;
using Xunit;
Expand Down Expand Up @@ -85,4 +87,26 @@ public void TryDestructure_Should_Return_False_When_Called_With_Null()
var policy = new JsonNetDestructuringPolicy();
policy.TryDestructure(null!, null!, out _).ShouldBeFalse();
}

[Fact]
public void TryDestructure_Should_Handle_TypeToken_As_Ordinal_Property_When_Not_String()
{
var policy = new JsonNetDestructuringPolicy();
var o = new JObject(new JProperty("$type", 42));
policy.TryDestructure(o, new StubFactory(), out var value).ShouldBeTrue();
var sv = value.ShouldBeOfType<StructureValue>();
sv.Properties.Count.ShouldBe(1);
sv.Properties[0].Name.ShouldBe("$type");
sv.Properties[0].Value.LiteralValue().ShouldBe(42);
}

private sealed class StubFactory : ILogEventPropertyValueFactory
{
public LogEventPropertyValue CreatePropertyValue(object? value, bool destructureObjects = false)
{
return ((JToken)value!).Value<int>() == 42
? (LogEventPropertyValue)new ScalarValue(42)
: throw new NotImplementedException();
}
}
}