public void ProxyImplementsIInterceptingProxy()
        {
            MBROWithOneMethod original = new MBROWithOneMethod();
            MBROWithOneMethod proxy    = new InterceptingRealProxy(original, typeof(MBROWithOneMethod))
                                         .GetTransparentProxy() as MBROWithOneMethod;

            Assert.IsNotNull(proxy as IInterceptingProxy);
        }
Example #2
0
        public void CanCreateProxyWithAdditionalInterfaces()
        {
            MBROWithOneMethod original = new MBROWithOneMethod();
            MBROWithOneMethod proxy    =
                new InterceptingRealProxy(original, typeof(MBROWithOneMethod), typeof(InterfaceOne))
                .GetTransparentProxy() as MBROWithOneMethod;

            Assert.IsTrue(proxy is InterfaceOne);
        }
Example #3
0
        public void CanSuccessfullyInvokeAnAdditionalInterfaceMethodIfAnInterceptorDoesNotForwardTheCall()
        {
            MBROWithOneMethod original = new MBROWithOneMethod();
            InterfaceOne      proxy    =
                new InterceptingRealProxy(original, typeof(MBROWithOneMethod), typeof(InterfaceOne))
                .GetTransparentProxy() as InterfaceOne;
            bool invoked = false;

            ((IInterceptingProxy)proxy).AddInterceptionBehavior(
                new DelegateInterceptionBehavior(
                    (input, getNext) => { invoked = true; return(input.CreateMethodReturn(null)); }));

            proxy.Something();

            Assert.IsTrue(invoked);
        }
Example #4
0
        public void CanInterceptMethodsThroughProxy()
        {
            CallCountInterceptionBehavior interceptor = new CallCountInterceptionBehavior();

            MBROWithOneMethod original    = new MBROWithOneMethod();
            MBROWithOneMethod intercepted = new InterceptingRealProxy(original, typeof(MBROWithOneMethod))
                                            .GetTransparentProxy() as MBROWithOneMethod;

            IInterceptingProxy proxy = (IInterceptingProxy)intercepted;

            proxy.AddInterceptionBehavior(interceptor);

            int result = intercepted.DoSomething(5);

            Assert.AreEqual(5 * 3, result);
            Assert.AreEqual(1, interceptor.CallCount);
        }
Example #5
0
        public void InvokingMethodOnAdditionalInterfaceThrowsIfNotHandledByInterceptor()
        {
            MBROWithOneMethod original = new MBROWithOneMethod();
            InterfaceOne      proxy    =
                new InterceptingRealProxy(original, typeof(MBROWithOneMethod), typeof(InterfaceOne))
                .GetTransparentProxy() as InterfaceOne;

            try
            {
                proxy.Something();
                Assert.Fail("should have thrown");
            }
            catch (InvalidOperationException)
            {
                // expected
            }
        }
        public void CanInterceptMethodsThroughProxy()
        {
            MethodInfo       doSomething = typeof(MBROWithOneMethod).GetMethod("DoSomething");
            CallCountHandler handler     = new CallCountHandler();

            MBROWithOneMethod original    = new MBROWithOneMethod();
            MBROWithOneMethod intercepted = new InterceptingRealProxy(original, typeof(MBROWithOneMethod))
                                            .GetTransparentProxy() as MBROWithOneMethod;

            IInterceptingProxy proxy = (IInterceptingProxy)intercepted;

            proxy.SetPipeline(doSomething, new HandlerPipeline(Seq.Collect <ICallHandler>(handler)));

            int result = intercepted.DoSomething(5);

            Assert.AreEqual(5 * 3, result);
            Assert.AreEqual(1, handler.CallCount);
        }