コード例 #1
0
        public void Debug_ShouldReturn_WhenMessageGeneratorIsNull()
        {
            // arrange

            // act
            Sut.Debug(logger, (Func <string>)null);

            // assert
            A.CallTo(logger).MustNotHaveHappened();
            logEntries.Should().BeEmpty();
        }
コード例 #2
0
        public void Debug_ShouldAlwaysPassMessageToLogger()
        {
            // arrange

            // act
            Sut.Debug(logger, "test message");

            // assert
            A.CallTo(() => logger.IsEnabled(A <LogLevel> ._)).MustNotHaveHappened();
            A.CallTo(() => logger.Log(A <LogEntry> ._)).MustHaveHappenedOnceExactly();
            logEntries.Should().BeEquivalentTo(new LogEntry(LogLevel.Debug, "test message"));
        }
コード例 #3
0
        public void Debug_WithLambdaExpression_ShouldNotPassMessageToLogger_WhenLogLevelIsDisabled()
        {
            // arrange
            bool called = false;

            string TestMessageGenerator()
            {
                called = true;
                return("Test message generated");
            }

            A.CallTo(() => logger.IsEnabled(LogLevel.Debug)).Returns(false);

            // act
            Sut.Debug(logger, TestMessageGenerator);

            // assert
            A.CallTo(() => logger.IsEnabled(LogLevel.Debug)).MustHaveHappenedOnceExactly();
            A.CallTo(() => logger.Log(A <LogEntry> ._)).MustNotHaveHappened();
            logEntries.Should().BeEmpty();
            called.Should().BeFalse();
        }
コード例 #4
0
        public void Fatal_WithLambdaExpression_ShouldPassMessageToLogger_WhenLogLevelIsEnabled()
        {
            // arrange
            bool called = false;

            string TestMessageGenerator()
            {
                called = true;
                return("Test message generated");
            }

            A.CallTo(() => logger.IsEnabled(LogLevel.Fatal)).Returns(true);

            // act
            Sut.Fatal(logger, TestMessageGenerator, exception);

            // assert
            A.CallTo(() => logger.IsEnabled(LogLevel.Fatal)).MustHaveHappenedOnceExactly()
            .Then(A.CallTo(() => logger.Log(A <LogEntry> ._)).MustHaveHappenedOnceExactly());
            logEntries.Should().BeEquivalentTo(new LogEntry(LogLevel.Fatal, "Test message generated", exception));
            called.Should().BeTrue();
        }