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

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

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

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

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

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

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

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

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