예제 #1
0
        public void Info_ShouldReturn_WhenMessageGeneratorIsNull()
        {
            // arrange

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

            // assert
            A.CallTo(logger).MustNotHaveHappened();
            logEntries.Should().BeEmpty();
        }
예제 #2
0
        public void Warn_ShouldAlwaysPassMessageToLogger()
        {
            // arrange

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

            // assert
            A.CallTo(() => logger.IsEnabled(A <LogLevel> ._)).MustNotHaveHappened();
            A.CallTo(() => logger.Log(A <LogEntry> ._)).MustHaveHappenedOnceExactly();
            logEntries.Should().BeEquivalentTo(new LogEntry(LogLevel.Warn, "test message"));
        }
예제 #3
0
        public void Warn_WithLambdaExpression_ShouldNotPassMessageToLogger_WhenLogLevelIsDisabled()
        {
            // arrange
            bool called = false;

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

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

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

            // assert
            A.CallTo(() => logger.IsEnabled(LogLevel.Warn)).MustHaveHappenedOnceExactly();
            A.CallTo(() => logger.Log(A <LogEntry> ._)).MustNotHaveHappened();
            logEntries.Should().BeEmpty();
            called.Should().BeFalse();
        }