Exemple #1
0
        public void CanCreateProxyWithAdditionalInterfaces()
        {
            IInstanceInterceptor      interceptor = new TransparentProxyInterceptor();
            SingleInterceptableMethod target      = new SingleInterceptableMethod();

            object proxy = interceptor.CreateProxy(typeof(SingleInterceptableMethod), target, typeof(IMyOperations));

            Assert.IsTrue(proxy is IMyOperations);
        }
Exemple #2
0
        public void AssortedParameterKindsAreProperlyHandled()
        {
            var interceptor = new TransparentProxyInterceptor();
            var target      = new AssortedParameterKindsAreProperlyHandledHelper.TypeWithAssertedParameterKinds();

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

            AssortedParameterKindsAreProperlyHandledHelper.PerformTest(proxy);
        }
        public void HandlersCanChangeInputsBeforeTargetIsCalled()
        {
            TransparentProxyInterceptor factory = new TransparentProxyInterceptor();
            PolicySet policies = GetPolicies();

            CanChangeParametersTarget target = new CanChangeParametersTarget();
            IInterceptingProxy proxy = factory.CreateProxy(typeof(CanChangeParametersTarget), target);

            ApplyPolicies(factory, proxy, target, policies);

            CanChangeParametersTarget intercepted = (CanChangeParametersTarget)proxy;
            Assert.AreEqual(0, intercepted.MostRecentInput);
            intercepted.DoSomething(2);
            Assert.AreEqual(4, intercepted.MostRecentInput);
        }
        SignatureTestTarget GetTarget()
        {
            TransparentProxyInterceptor interceptor = new TransparentProxyInterceptor();
            PolicySet           policySet           = GetPolicies();
            SignatureTestTarget target = new SignatureTestTarget();
            IInterceptingProxy  proxy  = interceptor.CreateProxy(typeof(SignatureTestTarget), target);

            foreach (MethodImplementationInfo method in interceptor.GetInterceptableMethods(typeof(SignatureTestTarget), typeof(SignatureTestTarget)))
            {
                HandlerPipeline pipeline = new HandlerPipeline(
                    policySet.GetHandlersFor(method, container));
                proxy.SetPipeline(method.ImplementationMethodInfo, pipeline);
            }
            return((SignatureTestTarget)proxy);
        }
Exemple #5
0
        public void HandlersCanChangeInputsBeforeTargetIsCalled()
        {
            TransparentProxyInterceptor factory = new TransparentProxyInterceptor();
            PolicySet policies = GetPolicies();

            CanChangeParametersTarget target = new CanChangeParametersTarget();
            IInterceptingProxy        proxy  = factory.CreateProxy(typeof(CanChangeParametersTarget), target);

            ApplyPolicies(factory, proxy, target, policies);

            CanChangeParametersTarget intercepted = (CanChangeParametersTarget)proxy;

            Assert.AreEqual(0, intercepted.MostRecentInput);
            intercepted.DoSomething(2);
            Assert.AreEqual(4, intercepted.MostRecentInput);
        }
        public void HandlersCanChangeRefsAfterTargetReturns()
        {
            TransparentProxyInterceptor factory = new TransparentProxyInterceptor();
            PolicySet policies = GetPolicies();


            CanChangeParametersTarget target = new CanChangeParametersTarget();
            IInterceptingProxy proxy = factory.CreateProxy(typeof(CanChangeParametersTarget), target);
            ApplyPolicies(factory, proxy, target, policies);
            CanChangeParametersTarget intercepted = (CanChangeParametersTarget)proxy;
            int output = 3;

            intercepted.DoSomethingElseWithRef(2, ref output);

            Assert.AreEqual((2 + 3 + 5) * 3, output);
        }
Exemple #7
0
        public void HandlersCanChangeRefsAfterTargetReturns()
        {
            TransparentProxyInterceptor factory = new TransparentProxyInterceptor();
            PolicySet policies = GetPolicies();


            CanChangeParametersTarget target = new CanChangeParametersTarget();
            IInterceptingProxy        proxy  = factory.CreateProxy(typeof(CanChangeParametersTarget), target);

            ApplyPolicies(factory, proxy, target, policies);
            CanChangeParametersTarget intercepted = (CanChangeParametersTarget)proxy;
            int output = 3;

            intercepted.DoSomethingElseWithRef(2, ref output);

            Assert.AreEqual((2 + 3 + 5) * 3, output);
        }
        SignatureTestTarget GetTarget()
        {
            TransparentProxyInterceptor interceptor = new TransparentProxyInterceptor();
            PolicySet policySet = GetPolicies();
            SignatureTestTarget target = new SignatureTestTarget();
            IInterceptingProxy proxy = interceptor.CreateProxy(typeof(SignatureTestTarget), target);

            PipelineManager manager = new PipelineManager();
            foreach (MethodImplementationInfo method in interceptor.GetInterceptableMethods(typeof(SignatureTestTarget), typeof(SignatureTestTarget)))
            {
                HandlerPipeline pipeline = new HandlerPipeline(
                    policySet.GetHandlersFor(method, container));
                manager.SetPipeline(method.ImplementationMethodInfo, pipeline);
            }
            proxy.AddInterceptionBehavior(new PolicyInjectionBehavior(manager));

            return (SignatureTestTarget)proxy;
        }