コード例 #1
0
        public void SunnyDayLoggingAllOptionalInformationCorrectly()
        {
            ILog log = A.Fake <ILog>();
            IMethodInvocation methodInvocation = A.Fake <IMethodInvocation>();

            MethodInfo mi = typeof(Dog).GetMethod("Bark");

            //two additional calls the method are to retrieve the method name on entry/exit...
            A.CallTo(() => methodInvocation.Method).Returns(mi);
            int[]    luckyNumbers = new int[] { 1, 2, 3 };
            object[] args         = new object[] { "hello", luckyNumbers };

            A.CallTo(() => methodInvocation.Arguments).Returns(args);
            A.CallTo(() => log.IsTraceEnabled).Returns(true);
            A.CallTo(() => methodInvocation.Proceed()).Returns(4);

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);

            loggingAdvice.LogExecutionTime    = true;
            loggingAdvice.LogMethodArguments  = true;
            loggingAdvice.LogUniqueIdentifier = true;

            loggingAdvice.CallInvokeUnderLog(methodInvocation, log);

            A.CallTo(() => log.Trace(A <string> .That.StartsWith("Entering Bark"))).MustHaveHappened();
            A.CallTo(() => log.Trace(A <string> .That.StartsWith("Exiting Bark"))).MustHaveHappened();
        }
コード例 #2
0
        public void SunnyDayLoggingCorrectly()
        {
            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(true).Repeat.Any();
            log.Trace("Entering ToString");

            Expect.Call(methodInvocation.Proceed()).Return(null);

            log.Trace("Exiting ToString");

            mocks.ReplayAll();

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);

            loggingAdvice.CallInvokeUnderLog(methodInvocation, log);

            mocks.VerifyAll();
        }
コード例 #3
0
        public void ExceptionPathStillLogsCorrectly()
        {
            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(true);

            Exception e = new ArgumentException("bad value");

            A.CallTo(() => methodInvocation.Proceed()).Throws(e);

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);

            try
            {
                loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
                Assert.Fail("Must have propagated the IllegalArgumentException.");
            }
            catch (ArgumentException)
            {
            }

            A.CallTo(() => log.Trace("Entering ToString")).MustHaveHappened();
            A.CallTo(() => log.Trace("Exception thrown in ToString, ToString", e)).MustHaveHappened();
        }
コード例 #4
0
        public void SunnyDayLoggingCorrectly()
        {
            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(true);
            A.CallTo(() => methodInvocation.Proceed()).Returns(null);

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);

            loggingAdvice.CallInvokeUnderLog(methodInvocation, log);

            A.CallTo(() => log.Trace("Entering ToString")).MustHaveHappened();
            A.CallTo(() => log.Trace("Exiting ToString")).MustHaveHappened();
        }
コード例 #5
0
        public void ExceptionPathStillLogsCorrectly()
        {
            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(true).Repeat.Any();
            log.Trace("Entering...");

            LastCall.On(log).IgnoreArguments();

            Exception e = new ArgumentException("bad value");

            Expect.Call(methodInvocation.Proceed()).Throw(e);

            log.Trace("Exception...", e);
            LastCall.On(log).IgnoreArguments();

            mocks.ReplayAll();

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);

            try
            {
                loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
                Assert.Fail("Must have propagated the IllegalArgumentException.");
            }
            catch (ArgumentException)
            {
            }

            mocks.VerifyAll();
        }
コード例 #6
0
        public void SunnyDayLoggingAllOptionalInformationCorrectly()
        {
            ILog log = (ILog)mocks.CreateMock(typeof(ILog));
            IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation));

            MethodInfo mi = typeof(Dog).GetMethod("Bark");

            //two additional calls the method are to retrieve the method name on entry/exit...
            Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any();
            int[]    luckyNumbers = new int[] { 1, 2, 3 };
            object[] args         = new object[] { "hello", luckyNumbers };


            Expect.Call(methodInvocation.Arguments).Return(args);

            Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
            log.Trace("Entering...");
            LastCall.IgnoreArguments();

            Expect.Call(methodInvocation.Proceed()).Return(4);

            log.Trace("Exiting...");
            LastCall.IgnoreArguments();

            mocks.ReplayAll();

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);

            loggingAdvice.LogExecutionTime    = true;
            loggingAdvice.LogMethodArguments  = true;
            loggingAdvice.LogUniqueIdentifier = true;

            loggingAdvice.CallInvokeUnderLog(methodInvocation, log);

            mocks.VerifyAll();
        }
コード例 #7
0
        public void SunnyDayLoggingCorrectly()
        {
            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(true).Repeat.Any();
            log.Trace("Entering ToString");

            Expect.Call(methodInvocation.Proceed()).Return(null);

            log.Trace("Exiting ToString");

            mocks.ReplayAll();

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
            loggingAdvice.CallInvokeUnderLog(methodInvocation, log);

            mocks.VerifyAll();

        }
コード例 #8
0
        public void SunnyDayLoggingAllOptionalInformationCorrectly()
        {
            ILog log = (ILog)mocks.CreateMock(typeof(ILog));
            IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation));

            MethodInfo mi = typeof(Dog).GetMethod("Bark");
            //two additional calls the method are to retrieve the method name on entry/exit...
            Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any();
            int[] luckyNumbers = new int[] { 1, 2, 3 };
            object[] args = new object[] { "hello", luckyNumbers };


            Expect.Call(methodInvocation.Arguments).Return(args);

            Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
            log.Trace("Entering...");
            LastCall.IgnoreArguments();

            Expect.Call(methodInvocation.Proceed()).Return(4);

            log.Trace("Exiting...");
            LastCall.IgnoreArguments();

            mocks.ReplayAll();

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
            loggingAdvice.LogExecutionTime = true;
            loggingAdvice.LogMethodArguments = true;
            loggingAdvice.LogUniqueIdentifier = true;

            loggingAdvice.CallInvokeUnderLog(methodInvocation, log);

            mocks.VerifyAll();
        }
コード例 #9
0
        public void ExceptionPathStillLogsCorrectly()
        {
            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(true).Repeat.Any();
            log.Trace("Entering...");

            LastCall.On(log).IgnoreArguments();

            Exception e = new ArgumentException("bad value");
            Expect.Call(methodInvocation.Proceed()).Throw(e);

            log.Trace("Exception...", e);
            LastCall.On(log).IgnoreArguments();

            mocks.ReplayAll();

            TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
            try
            {
                loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
                Assert.Fail("Must have propagated the IllegalArgumentException.");
            }
            catch (ArgumentException)
            {

            }

            mocks.VerifyAll();

        }