Skip to content

Commit

Permalink
Add formatter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmid committed Nov 14, 2022
1 parent deac020 commit 0a95b09
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
42 changes: 42 additions & 0 deletions tests/Sherlog.Formatters.Tests/ColorCodeFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using FluentAssertions;
using Xunit;
using static Sherlog.Formatters.ColorCodeFormatter;

namespace Sherlog.Formatters.Tests
{
public class ColorCodeFormatterTests
{
readonly ColorCodeFormatter _formatter;
readonly Logger _logger;

public ColorCodeFormatterTests()
{
_formatter = new ColorCodeFormatter();
_logger = new Logger("TestLogger");
}

[Fact]
public void FormatsStringUsingTraceColors() => _formatter.FormatMessage(_logger, LogLevel.Trace, "test message")
.Should().Be($"{Esc}{CyanBackground}{Esc}{WhiteForeground}test message{Esc}{Reset}");

[Fact]
public void FormatsStringUsingDebugColors() => _formatter.FormatMessage(_logger, LogLevel.Debug, "test message")
.Should().Be($"{Esc}{NoBackground}{Esc}{BlueForeground}test message{Esc}{Reset}");

[Fact]
public void FormatsStringUsingInfoColors() => _formatter.FormatMessage(_logger, LogLevel.Info, "test message")
.Should().Be($"{Esc}{NoBackground}{Esc}{GreenForeground}test message{Esc}{Reset}");

[Fact]
public void FormatsStringUsingWarnColors() => _formatter.FormatMessage(_logger, LogLevel.Warn, "test message")
.Should().Be($"{Esc}{NoBackground}{Esc}{YellowForeground}test message{Esc}{Reset}");

[Fact]
public void FormatsStringUsingErrorColors() => _formatter.FormatMessage(_logger, LogLevel.Error, "test message")
.Should().Be($"{Esc}{RedBackground}{Esc}{WhiteForeground}test message{Esc}{Reset}");

[Fact]
public void FormatsStringUsingFatalColors() => _formatter.FormatMessage(_logger, LogLevel.Fatal, "test message")
.Should().Be($"{Esc}{MagentaBackground}{Esc}{WhiteForeground}test message{Esc}{Reset}");
}
}
17 changes: 3 additions & 14 deletions tests/Sherlog.Formatters.Tests/LogMessageFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@ namespace Sherlog.Formatters.Tests
{
public class LogMessageFormatterTests
{
readonly LogMessageFormatter _formatter;
readonly Logger _logger;

public LogMessageFormatterTests()
{
_formatter = new LogMessageFormatter("[{1}] {0}: {2}");
_logger = new Logger("TestLogger");
}

[Fact]
public void FormatsString()
{
_formatter.FormatMessage(_logger, LogLevel.Debug, "test message")
.Should().Be("[Debug] TestLogger: test message");
}
public void FormatsString() => new LogMessageFormatter("[{1}] {0}: {2}")
.FormatMessage(new Logger("TestLogger"), LogLevel.Debug, "test message")
.Should().Be("[Debug] TestLogger: test message");
}
}

0 comments on commit 0a95b09

Please sign in to comment.