コード例 #1
0
        public void CanInterceptVoidNoArgMethods()
        {
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();

            instance.MethodOne();
            Assert.IsTrue(instance.OneWasCalled);
        }
コード例 #2
0
        public void ThrowingFromInterceptedMethodStillRunsAllHandlers()
        {
            MethodInfo           thrower  = typeof(ClassWithDefaultCtor).GetMethod("NotImplemented");
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();
            IInterceptingProxy   pm       = (IInterceptingProxy)instance;

            CallCountHandler     handler     = new CallCountHandler();
            PostCallCountHandler postHandler = new PostCallCountHandler();
            HandlerPipeline      pipeline    = new HandlerPipeline(new ICallHandler[] { postHandler, handler });

            pm.SetPipeline(thrower, pipeline);

            try
            {
                instance.NotImplemented();
                Assert.Fail("Should have thrown before getting here");
            }
            catch (NotImplementedException)
            {
                // We're expecting this one
            }

            Assert.AreEqual(1, handler.CallCount);
            Assert.AreEqual(1, postHandler.CallsCompleted);
        }
コード例 #3
0
        public void CanAddInterceptionBehaviorsToPipeline()
        {
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();
            IInterceptingProxy   pm       = (IInterceptingProxy)instance;

            CallCountInterceptionBehavior interceptor = new CallCountInterceptionBehavior();

            pm.AddInterceptionBehavior(interceptor);
        }
コード例 #4
0
        public void CanInterceptMethodWithGenericReturnTypeForValueTypeGenericParameter()
        {
            PostCallCountHandler handler = new PostCallCountHandler();
            ClassWithDefaultCtor instance
                = WireupHelper.GetInterceptedInstance <ClassWithDefaultCtor>("MethodWithGenericReturnType", handler);
            int value = instance.MethodWithGenericReturnType(5);

            Assert.AreEqual(5, value);
            Assert.AreEqual(1, handler.CallsCompleted);
        }
コード例 #5
0
        public void CanInterceptMethodsWithParameters()
        {
            PostCallCountHandler handler  = new PostCallCountHandler();
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptedInstance <ClassWithDefaultCtor>("AddUp", handler);

            string result = instance.AddUp(5, 12);

            Assert.AreEqual("17", result);
            Assert.AreEqual(1, handler.CallsCompleted);
        }
コード例 #6
0
        public void CanInterceptMethodsThatReturnReferenceTypes()
        {
            PostCallCountHandler handler  = new PostCallCountHandler();
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptedInstance <ClassWithDefaultCtor>("GimmeName", handler);

            string result = instance.GimmeName();

            Assert.AreEqual("name", result);
            Assert.AreEqual(1, handler.CallsCompleted);
        }
コード例 #7
0
        public void CanInterceptMethodsThatHaveReturnValues()
        {
            PostCallCountHandler handler  = new PostCallCountHandler();
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptedInstance <ClassWithDefaultCtor>("CalculateAnswer", handler);

            int result = instance.CalculateAnswer();

            Assert.AreEqual(42, result);
            Assert.AreEqual(1, handler.CallsCompleted);
        }
コード例 #8
0
        public void CanInterceptMethodsWithRefParameters()
        {
            PostCallCountHandler handler  = new PostCallCountHandler();
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptedInstance <ClassWithDefaultCtor>("MethodWithRefParameters", handler);

            string s      = "abc";
            int    result = instance.MethodWithRefParameters(5, ref s, 10);

            Assert.AreEqual(15, result);
            Assert.AreEqual("abc hooray!", s);
            Assert.AreEqual(1, handler.CallsCompleted);
        }
コード例 #9
0
        public void CanAddHandlersToPipeline()
        {
            MethodInfo           methodOne = typeof(ClassWithDefaultCtor).GetMethod("MethodOne");
            ClassWithDefaultCtor instance  = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();
            IInterceptingProxy   pm        = (IInterceptingProxy)instance;

            CallCountHandler handler = new CallCountHandler();

            HandlerPipeline pipeline = new HandlerPipeline(new CallCountHandler[] { handler });

            pm.SetPipeline(methodOne, pipeline);
        }
コード例 #10
0
        public void CanInterceptMethodsWithOutParameters()
        {
            PostCallCountHandler handler  = new PostCallCountHandler();
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptedInstance <ClassWithDefaultCtor>("OutParams", handler);

            int plusOne;
            int timesTwo;

            instance.OutParams(5, out plusOne, out timesTwo);

            Assert.AreEqual(5 + 1, plusOne);
            Assert.AreEqual(5 * 2, timesTwo);
            Assert.AreEqual(1, handler.CallsCompleted);
        }
コード例 #11
0
        public void CallingMethodInvokesHandlers()
        {
            MethodInfo           methodOne = typeof(ClassWithDefaultCtor).GetMethod("MethodOne");
            ClassWithDefaultCtor instance  = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();
            IInterceptingProxy   pm        = (IInterceptingProxy)instance;

            CallCountHandler     handler     = new CallCountHandler();
            PostCallCountHandler postHandler = new PostCallCountHandler();
            HandlerPipeline      pipeline    = new HandlerPipeline(new ICallHandler[] { postHandler, handler });

            pm.SetPipeline(methodOne, pipeline);

            instance.MethodOne();

            Assert.AreEqual(1, handler.CallCount);
            Assert.AreEqual(1, postHandler.CallsCompleted);
        }
コード例 #12
0
        public void InterceptingClassImplementsIInterceptingProxy()
        {
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();

            Assert.IsTrue(instance is IInterceptingProxy);
        }
コード例 #13
0
        public void InterceptingClassCallsBaseClassConstructor()
        {
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();

            Assert.IsTrue(instance.CtorWasCalled);
        }
コード例 #14
0
        public void CanCreateInterceptingClassOverClassWithDefaultConstructor()
        {
            ClassWithDefaultCtor instance = WireupHelper.GetInterceptingInstance <ClassWithDefaultCtor>();

            Assert.AreNotSame(typeof(ClassWithDefaultCtor), instance.GetType());
        }