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); }
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); }