Exemple #1
0
        public void InterceptorCreatesProxyInstance()
        {
            IInstanceInterceptor   interceptor = new InterfaceInterceptor();
            ImplementsInterfaceOne target      = new ImplementsInterfaceOne();

            IInterceptingProxy proxy = interceptor.CreateProxy(typeof(IInterfaceOne), target);

            IInterfaceOne intercepted = (IInterfaceOne)proxy;

            intercepted.TargetMethod();

            Assert.IsTrue(target.TargetMethodCalled);
        }
Exemple #2
0
        public void GeneratedProxyCallsInterceptionBehaviors()
        {
            IInstanceInterceptor   interceptor = new InterfaceInterceptor();
            ImplementsInterfaceOne target      = new ImplementsInterfaceOne();

            IInterceptingProxy            proxy = interceptor.CreateProxy(typeof(IInterfaceOne), target);
            CallCountInterceptionBehavior interceptionBehavior = new CallCountInterceptionBehavior();

            proxy.AddInterceptionBehavior(interceptionBehavior);

            IInterfaceOne intercepted = (IInterfaceOne)proxy;

            intercepted.TargetMethod();
            intercepted.TargetMethod();
            intercepted.TargetMethod();

            Assert.AreEqual(3, interceptionBehavior.CallCount);
        }
Exemple #3
0
        public void GeneratedProxyCallsHandlers()
        {
            IInstanceInterceptor   interceptor = new InterfaceInterceptor();
            ImplementsInterfaceOne target      = new ImplementsInterfaceOne();

            IInterceptingProxy proxy   = interceptor.CreateProxy(typeof(IInterfaceOne), target);
            CallCountHandler   handler = new CallCountHandler();

            proxy.SetPipeline(typeof(IInterfaceOne).GetMethod("TargetMethod"),
                              new HandlerPipeline(new ICallHandler[] { handler }));

            IInterfaceOne intercepted = (IInterfaceOne)proxy;

            intercepted.TargetMethod();
            intercepted.TargetMethod();
            intercepted.TargetMethod();

            Assert.AreEqual(3, handler.CallCount);
        }
 public IInterfaceOne mirrorOne(IInterfaceOne value)
 {
     return value;
 }
Exemple #5
0
 public UsingImplentation(IInterfaceOne one, IInterfaceTwo two)
 {
     this.one = one;
     this.two = two;
 }
Exemple #6
0
 public InterfaceOneInterceptor(IInterfaceOne target)
 {
     this.target = target;
     pipelines   = new PipelineManager();
 }
 public IInterfaceOne mirrorOne(IInterfaceOne value)
 {
     return(value);
 }