Beispiel #1
0
        public void CanInterceptMethods()
        {
            CallCountHandler         h1          = new CallCountHandler();
            VirtualMethodInterceptor interceptor = new VirtualMethodInterceptor();
            Type proxyType = interceptor.CreateProxyType(typeof(TwoOverrideableMethods));

            TwoOverrideableMethods instance =
                (TwoOverrideableMethods)Activator.CreateInstance(proxyType);

            SetPipeline(instance, "DoSomething", h1);

            instance.DoSomething();

            Assert.IsTrue(instance.DidSomething);
            Assert.AreEqual(1, h1.CallCount);
        }
Beispiel #2
0
        public void CanInterceptMethods()
        {
            CallCountHandler         h1          = new CallCountHandler();
            VirtualMethodInterceptor interceptor = new VirtualMethodInterceptor();
            Type proxyType = interceptor.CreateProxyType(typeof(TwoOverrideableMethods));

            TwoOverrideableMethods instance =
                (TwoOverrideableMethods)Activator.CreateInstance(proxyType);
            PipelineManager manager = new PipelineManager();

            ((IInterceptingProxy)instance).AddInterceptionBehavior(new PolicyInjectionBehavior(manager));
            SetPipeline(manager, instance, "DoSomething", h1);

            instance.DoSomething();

            Assert.IsTrue(instance.DidSomething);
            Assert.AreEqual(1, h1.CallCount);
        }