public void Log_GivenErrorException_ThenExceptionIsSet() { var subject = new TestableLogger(); var exception = new Exception(TestData.WellKnownString); subject.LogError(exception, "An error occurred!"); Assert.That(subject.LogEntries[0].Exception, Is.EqualTo(exception)); }
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)); }