Skip to content

Commit

Permalink
Add tests to increase code coverage (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Jan 22, 2024
1 parent 2690785 commit 9809a17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Destructurama.JsonNet.Tests/JsonNetTypesDestructuringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ internal class HasName

public class JsonNetTypesDestructuringTests
{
[Fact]
public void AttributesAreConsultedWhenDestructuring()
[Theory]
[InlineData(TypeNameHandling.Auto)]
[InlineData(TypeNameHandling.Objects)]
public void AttributesAreConsultedWhenDestructuring(TypeNameHandling typeNameHandling)
{
LogEvent evt = null!;

Expand All @@ -51,7 +53,7 @@ public void AttributesAreConsultedWhenDestructuring()

string ser = JsonConvert.SerializeObject(test, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
TypeNameHandling = typeNameHandling
});
var dyn = JsonConvert.DeserializeObject<dynamic>(ser);

Expand All @@ -67,5 +69,20 @@ public void AttributesAreConsultedWhenDestructuring()
props["E"].LiteralValue().ShouldBeNull();
props["ESPN"].ShouldBeOfType<DictionaryValue>();
props["WSPN"].ShouldBeOfType<DictionaryValue>();

foreach (var value in props.Values.OfType<StructureValue>())
{
if (typeNameHandling == TypeNameHandling.Auto)
value.TypeTag.ShouldBeNull();
else if (typeNameHandling == TypeNameHandling.Objects)
value.TypeTag.ShouldNotBeNull();
}
}

[Fact]
public void TryDestructure_Should_Return_False_When_Called_With_Null()
{
var policy = new JsonNetDestructuringPolicy();
policy.TryDestructure(null!, null!, out _).ShouldBeFalse();
}
}
1 change: 1 addition & 0 deletions src/Destructurama.JsonNet/Destructurama.JsonNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
<InternalsVisibleTo Include="Destructurama.JsonNet.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000fe215af9b769897395aac526ca6744222fcf543787b16f58980844d6c49f65bbf0a62502d69646c58f14a8a29ba60d43c85a2a5ef1ed103c9a0e18d6491e4b0bafd2c25e290028d19203d4366ae5651aafd48abaf485588fd6a25fbe23c2c9a644a24337a041966b09cbb73dc3a080bf79564d15a26e97c1bff4f345ee256a9" />
<InternalsVisibleTo Include="Benchmarks, PublicKey=00240000048000009400000006020000002400005253413100040000010001000fe215af9b769897395aac526ca6744222fcf543787b16f58980844d6c49f65bbf0a62502d69646c58f14a8a29ba60d43c85a2a5ef1ed103c9a0e18d6491e4b0bafd2c25e290028d19203d4366ae5651aafd48abaf485588fd6a25fbe23c2c9a644a24337a041966b09cbb73dc3a080bf79564d15a26e97c1bff4f345ee256a9" />
</ItemGroup>

Expand Down

1 comment on commit 9809a17

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.01.

Benchmark suite Current: 9809a17 Previous: 2690785 Ratio
Benchmarks.JsonNetBenchmarks.Destructure 2415.1199449392466 ns (± 7.0006673296372055) 2264.9336573282876 ns (± 8.485789488010608) 1.07

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.