Exemplo n.º 1
0
        public void NoOpLogger_DisableErrorLog_MessageNotExposedTest()
        {
            //Arrange
            var messages = new List <Tuple <LogLevel, string, Exception> >();
            var logger   = new NoOpLogger("Test");

            logger.IsErrorEnabled     = false;
            logger.LogMessageHandler += (x, y, z) => messages.Add(new Tuple <LogLevel, string, Exception>(x, y, z));
            var testMessage   = "Test message";
            var testException = new Exception("Test");

            //Act
            logger.Error(testMessage);
            logger.Error(testException);
            logger.Error(testMessage, testException);
            //Assert
            Assert.AreEqual(0, messages.Count);
        }
Exemplo n.º 2
0
        public void NoOpLogger_ErrorLog_MessageExposedTest()
        {
            //Arrange
            var messages = new List <Tuple <LogLevel, string, Exception> >();
            var logger   = new NoOpLogger("Test");

            logger.IsErrorEnabled     = true;
            logger.LogMessageHandler += (x, y, z) => messages.Add(new Tuple <LogLevel, string, Exception>(x, y, z));
            var testMessage   = "Test message";
            var testException = new Exception("Test");

            //Act
            logger.Error(testMessage);
            logger.Error(testException);
            logger.Error(testMessage, testException);
            //Assert
            Assert.AreEqual(3, messages.Count);
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Error, testMessage, null), messages[0], "Log entry with message was not exposed correctly.");
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Error, string.Empty, testException), messages[1], "Log entry with exception was not exposed correctly.");
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Error, testMessage, testException), messages[2], "Log entry with message and exception was not exposed correctly.");
        }