private void RunFatalLogMessageTests(bool withException)
        {
            LogMessageExpectations logFatalExpectations = GenerateLogExceptionExpectations(withException,
                                                                                           withFormattedMessage: false);

            TargetLoggerMockLoggerSetupProperties targetLoggerSetupProps = TargetLoggerMockLoggerSetupProperties
                                                                           .FatalEnabledWithExpectations(logFatalExpectations);

            Mock <ILog> targetLoggerMock =
                CreateLog4NetLoggerMock(targetLoggerSetupProps);

            Log4NetLogger stakhanoviseLogger =
                new Log4NetLogger(targetLoggerMock.Object);

            if (withException)
            {
                stakhanoviseLogger.Fatal(logFatalExpectations.ExpectedMessage, logFatalExpectations.ExpectedException);
            }
            else
            {
                stakhanoviseLogger.Fatal(logFatalExpectations.ExpectedMessage);
            }

            targetLoggerMock.Verify();
        }
Ejemplo n.º 2
0
        public void Log4NetLogger_LoggingTest()
        {
            string    message       = "Error Message";
            Exception ex            = new Exception();
            string    messageFormat = "Message Format: message: {0}, exception: {1}";

            ILog log = new Log4NetLogger(GetType());

            Assert.IsNotNull(log);

            log.Debug(message);
            log.Debug(message, ex);
            log.DebugFormat(messageFormat, message, ex.Message);

            log.Error(message);
            log.Error(message, ex);
            log.ErrorFormat(messageFormat, message, ex.Message);

            log.Fatal(message);
            log.Fatal(message, ex);
            log.FatalFormat(messageFormat, message, ex.Message);

            log.Info(message);
            log.Info(message, ex);
            log.InfoFormat(messageFormat, message, ex.Message);

            log.Warn(message);
            log.Warn(message, ex);
            log.WarnFormat(messageFormat, message, ex.Message);
        }
Ejemplo n.º 3
0
        public void When_logging_using_fatal()
        {
            _logger.Fatal("Hi");
            _mockedLogger.Verify(l => l.Fatal("Hi"), Times.Once);

            var ex = new InvalidOperationException();

            _logger.Fatal("Ooops", ex);
            _mockedLogger.Verify(l => l.Fatal("Ooops", ex), Times.Once);
        }
Ejemplo n.º 4
0
        public void CallingMethods()
        {
            var logMock = new LogMock();
            var logger  = new Log4NetLogger(logMock);
            var b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            logMock.debug.Should().Be(1);
            logMock.debugException.Should().Be(1);
            logMock.debugFormat.Should().Be(1);
            logMock.info.Should().Be(1);
            logMock.infoException.Should().Be(1);
            logMock.infoFormat.Should().Be(1);
            logMock.warn.Should().Be(1);
            logMock.warnException.Should().Be(1);
            logMock.warnFormat.Should().Be(1);
            logMock.error.Should().Be(1);
            logMock.errorException.Should().Be(1);
            logMock.errorFormat.Should().Be(1);
            logMock.fatal.Should().Be(1);
            logMock.fatalException.Should().Be(1);
            logMock.isDebugEnabled.Should().Be.GreaterThan(1);
            logMock.isInfoEnabled.Should().Be.GreaterThan(1);
            logMock.isWarnEnabled.Should().Be.GreaterThan(1);
            logMock.isErrorEnabled.Should().Be.GreaterThan(1);
            logMock.isFatalEnabled.Should().Be.GreaterThan(1);
        }
Ejemplo n.º 5
0
        public void CallingMethods()
        {
            var logMock = new LogMock();
            var logger  = new Log4NetLogger(logMock);
            var b       = logger.IsDebugEnabled;

            b = logger.IsErrorEnabled;
            b = logger.IsFatalEnabled;
            b = logger.IsInfoEnabled;
            b = logger.IsWarnEnabled;

            logger.Debug(null);
            logger.Debug(null, null);
            logger.DebugFormat(null, null);

            logger.Error(null);
            logger.Error(null, null);
            logger.ErrorFormat(null, null);

            logger.Warn(null);
            logger.Warn(null, null);
            logger.WarnFormat(null, null);

            logger.Info(null);
            logger.Info(null, null);
            logger.InfoFormat(null, null);

            logger.Fatal(null);
            logger.Fatal(null, null);

            Assert.That(logMock.debug, Is.EqualTo(1));
            Assert.That(logMock.debugException, Is.EqualTo(1));
            Assert.That(logMock.debugFormat, Is.EqualTo(1));
            Assert.That(logMock.info, Is.EqualTo(1));
            Assert.That(logMock.infoException, Is.EqualTo(1));
            Assert.That(logMock.infoFormat, Is.EqualTo(1));
            Assert.That(logMock.warn, Is.EqualTo(1));
            Assert.That(logMock.warnException, Is.EqualTo(1));
            Assert.That(logMock.warnFormat, Is.EqualTo(1));
            Assert.That(logMock.error, Is.EqualTo(1));
            Assert.That(logMock.errorException, Is.EqualTo(1));
            Assert.That(logMock.errorFormat, Is.EqualTo(1));
            Assert.That(logMock.fatal, Is.EqualTo(1));
            Assert.That(logMock.fatalException, Is.EqualTo(1));
            Assert.That(logMock.isDebugEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isInfoEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isWarnEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isErrorEnabled, Is.GreaterThan(1));
            Assert.That(logMock.isFatalEnabled, Is.GreaterThan(1));
        }
Ejemplo n.º 6
0
        public void WriteToConsoleTest()
        {
            Log4NetLogger logger = new Log4NetLogger();

            logger.Fatal("Fatal message");
            logger.Error("Error message");
            logger.Info("Info message");
            logger.Debug("Debug message");
        }
 public void FatalShouldForwardsMessageToInnerFatal()
 {
     var message = "somemessage";
       var mockLog = new Mock<log4net.ILog>();
       mockLog.Setup(x => x.Fatal(message)).Verifiable();
       ILog tested = new Log4NetLogger(mockLog.Object);
       tested.Fatal(message);
       mockLog.Verify();
 }
Ejemplo n.º 8
0
        public void DefaultLogger_FatalLog_MessageExposedTest()
        {
            //Arrange
            var messages = new List <Tuple <LogLevel, string, Exception> >();
            var logger   = new Log4NetLogger("Test");

            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.Fatal(testMessage);
            logger.Fatal(testException);
            logger.Fatal(testMessage, testException);
            //Assert
            Assert.AreEqual(3, messages.Count);
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Fatal, testMessage, null), messages[0], "Log entry with message was not exposed correctly.");
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Fatal, string.Empty, testException), messages[1], "Log entry with exception was not exposed correctly.");
            Assert.AreEqual(new Tuple <LogLevel, string, Exception>(LogLevel.Fatal, testMessage, testException), messages[2], "Log entry with message and exception was not exposed correctly.");
        }
        public void FatalShouldForwardsMessageToInnerFatal()
        {
            var message = "somemessage";
            var mockLog = new Mock <log4net.ILog>();

            mockLog.Setup(x => x.Fatal(message)).Verifiable();
            ILog tested = new Log4NetLogger(mockLog.Object);

            tested.Fatal(message);
            mockLog.Verify();
        }
        public void FormattedFatalShouldForwardsMessageToInnerFatalFormat()
        {
            var format   = "formatted message";
            var args     = new object[] { "arg1", "arg2" };
            var provider = new Mock <IFormatProvider>().Object;
            var mockLog  = new Mock <log4net.ILog>();

            mockLog.Setup(x => x.FatalFormat(provider, format, args)).Verifiable();
            ILog tested = new Log4NetLogger(mockLog.Object);

            tested.Fatal(provider, format, args);
            mockLog.Verify();
        }
Ejemplo n.º 11
0
        public void Fatal_LambdaMessage()
        {
            // Prepare
            const string message = "Simple Message";

            logger.SetupGet(o => o.IsFatalEnabled).Returns(() => true);
            logger.Setup(o => o.Fatal(message)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Fatal(() => message);

            // Assert
            logger.VerifyAll();
        }
Ejemplo n.º 12
0
        public void Fatal_NoMessage()
        {
            // Prepare
            const string message = "Simple Message";

            logger.SetupGet(o => o.IsFatalEnabled).Returns(() => false);
            logger.Setup(o => o.Fatal(message)).Callback(() => counterCall++).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Fatal(message);

            // Assert
            Assert.AreEqual(counterCall, 0);
        }
Ejemplo n.º 13
0
        public void Fatal_MessageWithException()
        {
            // Prepare
            const string message = "Exception occurred";
            var          ex      = new Exception(message);

            logger.SetupGet(o => o.IsFatalEnabled).Returns(() => true);
            logger.Setup(o => o.Fatal(message, ex)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Fatal(message, ex);

            // Assert
            logger.VerifyAll();
        }
Ejemplo n.º 14
0
        public void WriteToFileTest()
        {
            Log4NetLogger logger = new Log4NetLogger();

            string filePath = logger.LogFilePath;

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            string message = "This is Test Message";

            logger.Fatal(message);
            logger.Shutdown();
            Assert.IsTrue(File.ReadAllText(filePath).Contains(message));
        }
Ejemplo n.º 15
0
		public void CallingMethods()
		{
			var logMock = new LogMock();
			var logger = new Log4NetLogger(logMock);
			var b = logger.IsDebugEnabled;
			b = logger.IsErrorEnabled;
			b = logger.IsFatalEnabled;
			b = logger.IsInfoEnabled;
			b = logger.IsWarnEnabled;
			
			logger.Debug(null);
			logger.Debug(null, null);
			logger.DebugFormat(null, null);
			
			logger.Error(null);
			logger.Error(null, null);
			logger.ErrorFormat(null, null);
			
			logger.Warn(null);
			logger.Warn(null, null);
			logger.WarnFormat(null, null);
		
			logger.Info(null);
			logger.Info(null, null);
			logger.InfoFormat(null, null);

			logger.Fatal(null);
			logger.Fatal(null, null);

			logMock.debug.Should().Be(1);
			logMock.debugException.Should().Be(1);
			logMock.debugFormat.Should().Be(1);
			logMock.info.Should().Be(1);
			logMock.infoException.Should().Be(1);
			logMock.infoFormat.Should().Be(1);
			logMock.warn.Should().Be(1);
			logMock.warnException.Should().Be(1);
			logMock.warnFormat.Should().Be(1);
			logMock.error.Should().Be(1);
			logMock.errorException.Should().Be(1);
			logMock.errorFormat.Should().Be(1);
			logMock.fatal.Should().Be(1);
			logMock.fatalException.Should().Be(1);
			logMock.isDebugEnabled.Should().Be.GreaterThan(1);
			logMock.isInfoEnabled.Should().Be.GreaterThan(1);
			logMock.isWarnEnabled.Should().Be.GreaterThan(1);
			logMock.isErrorEnabled.Should().Be.GreaterThan(1);
			logMock.isFatalEnabled.Should().Be.GreaterThan(1);
		}
Ejemplo n.º 16
0
        public void Fatal_NoMessage()
        {
            // Prepare
            const string message = "Simple Message";
            logger.SetupGet(o => o.IsFatalEnabled).Returns(() => false);
            logger.Setup(o => o.Fatal(message)).Callback(() => counterCall++).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Fatal(message);

            // Assert
            Assert.AreEqual(counterCall, 0);
        }
Ejemplo n.º 17
0
        public void Fatal_LambdaMessage()
        {
            // Prepare
            const string message = "Simple Message";
            logger.SetupGet(o => o.IsFatalEnabled).Returns(() => true);
            logger.Setup(o => o.Fatal(message)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Fatal(() => message);

            // Assert
            logger.VerifyAll();
        }
Ejemplo n.º 18
0
        public void Fatal_MessageWithException()
        {
            // Prepare
            const string message = "Exception occurred";
            var ex = new Exception(message);
            logger.SetupGet(o => o.IsFatalEnabled).Returns(() => true);
            logger.Setup(o => o.Fatal(message, ex)).Verifiable();
            log = new Log4NetLogger(logger.Object);

            // Act
            log.Fatal(message, ex);

            // Assert
            logger.VerifyAll();
        }
Ejemplo n.º 19
0
		public void CallingMethods()
		{
			var logMock = new LogMock();
			var logger = new Log4NetLogger(logMock);
			var b = logger.IsDebugEnabled;
			b = logger.IsErrorEnabled;
			b = logger.IsFatalEnabled;
			b = logger.IsInfoEnabled;
			b = logger.IsWarnEnabled;
			
			logger.Debug(null);
			logger.Debug(null, null);
			logger.DebugFormat(null, null);
			
			logger.Error(null);
			logger.Error(null, null);
			logger.ErrorFormat(null, null);
			
			logger.Warn(null);
			logger.Warn(null, null);
			logger.WarnFormat(null, null);
		
			logger.Info(null);
			logger.Info(null, null);
			logger.InfoFormat(null, null);

			logger.Fatal(null);
			logger.Fatal(null, null);

			Assert.That(logMock.debug, Is.EqualTo(1));
			Assert.That(logMock.debugException, Is.EqualTo(1));
			Assert.That(logMock.debugFormat, Is.EqualTo(1));
			Assert.That(logMock.info, Is.EqualTo(1));
			Assert.That(logMock.infoException, Is.EqualTo(1));
			Assert.That(logMock.infoFormat, Is.EqualTo(1));
			Assert.That(logMock.warn, Is.EqualTo(1));
			Assert.That(logMock.warnException, Is.EqualTo(1));
			Assert.That(logMock.warnFormat, Is.EqualTo(1));
			Assert.That(logMock.error, Is.EqualTo(1));
			Assert.That(logMock.errorException, Is.EqualTo(1));
			Assert.That(logMock.errorFormat, Is.EqualTo(1));
			Assert.That(logMock.fatal, Is.EqualTo(1));
			Assert.That(logMock.fatalException, Is.EqualTo(1));
			Assert.That(logMock.isDebugEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isInfoEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isWarnEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isErrorEnabled, Is.GreaterThan(1));
			Assert.That(logMock.isFatalEnabled, Is.GreaterThan(1));
		}
 public void FormattedFatalShouldForwardsMessageToInnerFatalFormat()
 {
     var format = "formatted message";
       var args = new object[] { "arg1", "arg2" };
       var provider = new Mock<IFormatProvider>().Object;
       var mockLog = new Mock<log4net.ILog>();
       mockLog.Setup(x => x.FatalFormat(provider, format, args)).Verifiable();
       ILog tested = new Log4NetLogger(mockLog.Object);
       tested.Fatal(provider, format, args);
       mockLog.Verify();
 }