Skip to content

Commit

Permalink
Add more tests (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Jan 22, 2024
1 parent 9809a17 commit 40d7ff6
Showing 1 changed file with 24 additions and 0 deletions.
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();
}
}
}

0 comments on commit 40d7ff6

Please sign in to comment.