public void LoggerWithLevels_LogEntryWithMessage_ExposedTraceLogTest() { //arrange var requiredDebugLevel = LogLevel.Trace; var loggerMock = new Mock <ILogger>(); loggerMock.Setup(x => x.Trace(It.IsAny <string>())); var loggerWithLevels = new LoggerWithLevels(loggerMock.Object, LogLevel.Trace); LogLevel retrievedLogLevel = LogLevel.Info; string retrievedMessage = string.Empty; loggerWithLevels.LogMessageHandler += (x, y, z) => { retrievedLogLevel = x; retrievedMessage = y; }; var testMessage = Guid.NewGuid().ToString(); //act loggerWithLevels.Log(requiredDebugLevel, testMessage); //assert Assert.AreEqual(requiredDebugLevel, retrievedLogLevel); Assert.AreEqual(testMessage, retrievedMessage); }
public void LoggerWithLevels_LogEntryWithMessageAndException_ExposedFatalLogTest() { //arrange var requiredDebugLevel = LogLevel.Fatal; var loggerMock = new Mock <ILogger>(); loggerMock.Setup(x => x.Fatal(It.IsAny <string>(), It.IsAny <Exception>())); var loggerWithLevels = new LoggerWithLevels(loggerMock.Object, LogLevel.Trace); LogLevel retrievedLogLevel = LogLevel.Info; string retrievedMessage = string.Empty; Exception retrievedException = null; loggerWithLevels.LogMessageHandler += (x, y, z) => { retrievedLogLevel = x; retrievedMessage = y; retrievedException = z; }; var testMessage = Guid.NewGuid().ToString(); var testException = new Exception(Guid.NewGuid().ToString()); //act loggerWithLevels.Log(requiredDebugLevel, testMessage, testException); //assert Assert.AreEqual(requiredDebugLevel, retrievedLogLevel); Assert.AreEqual(testMessage, retrievedMessage); Assert.AreEqual(testException, retrievedException); }
public void LoggerWithLevels_LogEntryWithException_ExposedInfoLog_Test() { //arrange var requiredDebugLevel = LogLevel.Info; var loggerMock = new Mock <ILogger>(); loggerMock.Setup(x => x.Info(It.IsAny <Exception>())); var loggerWithLevels = new LoggerWithLevels(loggerMock.Object, LogLevel.Trace); LogLevel retrievedLogLevel = LogLevel.Error; Exception retrievedException = null; loggerWithLevels.LogMessageHandler += (x, y, z) => { retrievedLogLevel = x; retrievedException = z; }; var testException = new Exception(Guid.NewGuid().ToString()); //act loggerWithLevels.Log(requiredDebugLevel, testException); //assert Assert.AreEqual(requiredDebugLevel, retrievedLogLevel); Assert.AreEqual(testException, retrievedException); }
public void LoggerWithLevels_LogEntryWithMessageAndException_LogWithLevelTest() { //arrange var loggerMock = new Mock <ILogger>(); loggerMock.Setup(x => x.Warn(It.IsAny <string>(), It.IsAny <Exception>())); var loggerWithLevels = new LoggerWithLevels(loggerMock.Object); //act loggerWithLevels.Log(LogLevel.Warn, "message", new Exception("test")); //assert loggerMock.Verify(x => x.Warn(It.IsAny <string>(), It.IsAny <Exception>()), Times.AtLeastOnce); }
public void LoggerWithLevels_LogWithException_LevelLimitationTest() { //arrange var requiredLogLevel = LogLevel.Debug; var loggerMock = new Mock <ILogger>(); loggerMock.Setup(x => x.Warn(It.IsAny <Exception>())); var loggerWithLevels = new LoggerWithLevels(loggerMock.Object, LogLevel.Error); var testException = new Exception(Guid.NewGuid().ToString()); //act loggerWithLevels.Log(requiredLogLevel, testException); //assert loggerMock.Verify(x => x.Warn(It.IsAny <Exception>()), Times.Never); }
public void LoggerWithLevels_LogEntryWithMessage_LevelLimitationWithPropertySetTest() { //arrange var requiredLogLevel = LogLevel.Warn; var loggerMock = new Mock <ILogger>(); loggerMock.Setup(x => x.Warn(It.IsAny <string>())); var loggerWithLevels = new LoggerWithLevels(loggerMock.Object, LogLevel.Error); var testMessage = Guid.NewGuid().ToString(); //act loggerWithLevels.LogLevel = LogLevel.Trace; loggerWithLevels.Log(requiredLogLevel, testMessage); //assert loggerMock.Verify(x => x.Warn(It.IsAny <string>()), Times.AtLeastOnce); }