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