public void CanGenerateProxyForClosedGeneric() { IInstanceInterceptor interceptor = new InterfaceInterceptor(); GenericImplementationOne <DateTime> target = new GenericImplementationOne <DateTime>(); IInterceptingProxy proxy = interceptor.CreateProxy(typeof(IGenericOne <DateTime>), target); CallCountHandler handler = new CallCountHandler(); proxy.SetPipeline(typeof(IGenericOne <DateTime>).GetMethod("DoSomething"), new HandlerPipeline(new ICallHandler[] { handler })); IGenericOne <DateTime> intercepted = (IGenericOne <DateTime>)proxy; DateTime now = DateTime.Now; DateTime result = intercepted.DoSomething(now); Assert.AreEqual(now, result); Assert.IsTrue(target.DidSomething); }
public void CanGenerateProxyForClosedGeneric() { IInstanceInterceptor interceptor = new InterfaceInterceptor(); GenericImplementationOne <DateTime> target = new GenericImplementationOne <DateTime>(); IInterceptingProxy proxy = interceptor.CreateProxy(typeof(IGenericOne <DateTime>), target); CallCountInterceptionBehavior interceptionBehavior = new CallCountInterceptionBehavior(); proxy.AddInterceptionBehavior(interceptionBehavior); IGenericOne <DateTime> intercepted = (IGenericOne <DateTime>)proxy; DateTime now = DateTime.Now; DateTime result = intercepted.DoSomething(now); Assert.AreEqual(now, result); Assert.IsTrue(target.DidSomething); Assert.AreEqual(1, interceptionBehavior.CallCount); }