public void Log_GivenFormattedMessage_ThenMessageShouldBeFormatted() { var subject = new TestableLogger(); const string name = "Fred"; subject.LogInformation("My name is {Name}.", name); Assert.That(subject.LogEntries[0].Message, Is.EqualTo("My name is Fred.")); }
public void Log_GivenLogEntries_ThenAllAreSavedInOutput(LogLevel logLevel, string expected) { var subject = new TestableLogger(); switch (logLevel) { case LogLevel.Critical: subject.LogCritical("Critical error occurred."); break; case LogLevel.Trace: subject.LogTrace("Starting the test."); break; case LogLevel.Debug: subject.LogDebug("Additional information."); break; case LogLevel.Information: subject.LogInformation("Finished test."); break; case LogLevel.Warning: subject.LogWarning("Test results inconclusive."); break; case LogLevel.Error: subject.LogError("An error occurred."); break; default: throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null); } Assert.That(subject.LogEntries.Count, Is.EqualTo(1)); Assert.That(subject.LogEntries[0].LogLevel, Is.EqualTo(logLevel)); Assert.That(subject.LogEntries[0].Message, Is.EqualTo(expected)); }