Exemplo n.º 1
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);
        }
        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);
        }