Skip to content

Commit

Permalink
Additional unit tests (scope renderer)
Browse files Browse the repository at this point in the history
  • Loading branch information
daningalla committed Aug 31, 2022
1 parent c95b563 commit 18565ba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/Formatting/IntegralFormattingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.Extensions.Logging;
using Shouldly;
using Vertical.SpectreLogger.Tests.Infrastructure;
using Xunit;

namespace Vertical.SpectreLogger.Tests.Formatting
{
public class IntegralFormattingTests
{
[Fact]
public void FormatDecimal_ReturnsExpected()
{
RendererTestHarness.Capture(
cfg => cfg.ConfigureProfile(LogLevel.Information, p => p.OutputTemplate="{Message}"),
logger => logger.LogInformation("Double: {Value:F2}", 1d))
.ShouldBe("Double: [magenta3_2]1.00[/]");
}
}
}
40 changes: 40 additions & 0 deletions test/Rendering/ScopeValuesRendererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@ public class ScopeValuesRendererTests

output.ShouldBe(expected);
}

[Fact]
public void RenderUsesContentBetween()
{
var output = RendererTestHarness.Capture(config => config.ConfigureProfile(LogLevel.Information,
profile =>
{
profile.OutputTemplate = "{Scopes}{Message}";
profile.ConfigureOptions<ScopeValuesRenderer.Options>(options =>
options.ContentBetween = ">");
}),
logger =>
{
using var scope1 = logger.BeginScope("First");
using var scope2 = logger.BeginScope("Second");
logger.LogInformation("test");
});

output.ShouldBe("[gold3_1]First[/]>[gold3_1]Second[/] => test");
}

[Fact]
public void RenderUsesContentAfter()
{
var output = RendererTestHarness.Capture(config => config.ConfigureProfile(LogLevel.Information,
profile =>
{
profile.OutputTemplate = "{Scopes}{Message}";
profile.ConfigureOptions<ScopeValuesRenderer.Options>(options =>
options.ContentAfter = ">");
}),
logger =>
{
using var scope1 = logger.BeginScope("First");
using var scope2 = logger.BeginScope("Second");
logger.LogInformation("test");
});

output.ShouldBe("[gold3_1]First[/] => [gold3_1]Second[/]>test");
}

public static IEnumerable<object[]> Theories => new[]
{
Expand Down

0 comments on commit 18565ba

Please sign in to comment.