public void SunnyDayLoggingCorrectlyDebugLevel() { ILog log = (ILog)mocks.CreateMock(typeof(ILog)); IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation)); MethodInfo mi = typeof(string).GetMethod("ToString", Type.EmptyTypes); //two additional calls the method are to retrieve the method name on entry/exit... Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any(); Expect.Call(log.IsTraceEnabled).Return(false).Repeat.Any(); Expect.Call(log.IsDebugEnabled).Return(true).Repeat.Any(); log.Debug("Entering ToString"); Expect.Call(methodInvocation.Proceed()).Return(null); log.Debug("Exiting ToString"); mocks.ReplayAll(); TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true); loggingAdvice.LogLevel = LogLevel.Debug; Assert.IsTrue(loggingAdvice.CallIsInterceptorEnabled(methodInvocation, log)); loggingAdvice.CallInvokeUnderLog(methodInvocation, log); mocks.VerifyAll(); }
public void SunnyDayLoggingCorrectlyDebugLevel() { ILog log = A.Fake <ILog>(); IMethodInvocation methodInvocation = A.Fake <IMethodInvocation>(); MethodInfo mi = typeof(string).GetMethod("ToString", Type.EmptyTypes); //two additional calls the method are to retrieve the method name on entry/exit... A.CallTo(() => methodInvocation.Method).Returns(mi); A.CallTo(() => log.IsTraceEnabled).Returns(false); A.CallTo(() => log.IsDebugEnabled).Returns(true); A.CallTo(() => methodInvocation.Proceed()).Returns(null); TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true); loggingAdvice.LogLevel = LogLevel.Debug; Assert.IsTrue(loggingAdvice.CallIsInterceptorEnabled(methodInvocation, log)); loggingAdvice.CallInvokeUnderLog(methodInvocation, log); A.CallTo(() => log.Debug("Entering ToString")).MustHaveHappened(); A.CallTo(() => log.Debug("Exiting ToString")).MustHaveHappened(); }