예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public void Should_not_log_when_level_is_none(
            Func <string> getMessage,
            ICastleLogger castleLogger)
        {
            var logger = new LoggerWithLevels(castleLogger, LogLevel.None);

            logger.Info(getMessage);
            logger.Warn(getMessage);
            logger.Error(getMessage);

            castleLogger.DidNotReceive().Info(getMessage());
        }
예제 #5
0
        public void LoggerWithLevels_LogEntryWithMessage_LogFormatWithLevelTest()
        {//(CultureInfo culture, string message, params object[] objects)
            //arrange
            var loggerMock = new Mock <ILogger>();

            loggerMock.Setup(x => x.Warn(It.IsAny <string>()));
            var loggerWithLevels = new LoggerWithLevels(loggerMock.Object);

            //act
            loggerWithLevels.LogFormat(LogLevel.Warn, CultureInfo.CurrentCulture, "test", new object[0]);
            //assert
            loggerMock.Verify(x => x.Warn(It.IsAny <string>()), Times.AtLeastOnce);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }