Ejemplo n.º 1
0
        public void Should_not_share_invocations_for_interface_methods_when_one_is_IChangeProxyTarget()
        {
            var interceptor1 = new KeepDataInterceptor();
            var interceptor2 = new KeepDataInterceptor();
            var first        = generator.CreateInterfaceProxyWithTarget <IOne>(new One(), interceptor1);
            var second       = generator.CreateInterfaceProxyWithTargetInterface <IOne>(new OneTwo(), interceptor2);

            Assert.AreNotEqual(first.GetType(), second.GetType(), "proxy types are different");

            first.OneMethod();
            second.OneMethod();

            Assert.IsNotInstanceOf <IChangeProxyTarget>(interceptor1.Invocation);
            Assert.IsInstanceOf <IChangeProxyTarget>(interceptor2.Invocation);
            Assert.AreNotEqual(interceptor1.Invocation.GetType(), interceptor2.Invocation.GetType());
        }
        public void GenericMethod_WithConstraintOnOtherParameter()
        {
            var type = typeof(IInterfaceWithGenericMethodWithDependentConstraint);

            var interceptor = new KeepDataInterceptor();
            var proxy       = (IInterfaceWithGenericMethodWithDependentConstraint)
                              generator.CreateInterfaceProxyWithoutTarget(type, new Type[] { }, interceptor);

            proxy.RegisterType <object, string>();

            var expectedMethod =
                typeof(IInterfaceWithGenericMethodWithDependentConstraint).GetMethod("RegisterType").MakeGenericMethod(
                    typeof(object), typeof(string));

            Assert.AreEqual(expectedMethod, interceptor.Invocation.Method);
        }
Ejemplo n.º 3
0
        public void MethodInfoClosedInGenTypeNongenMethodValueTypeRefType()
        {
            KeepDataInterceptor interceptor = new KeepDataInterceptor();
            GenClassWithGenReturn <int, List <object> > proxy =
                generator.CreateClassProxy <GenClassWithGenReturn <int, List <object> > >(interceptor);

            proxy.DoSomethingT();
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(int));
            Assert.AreEqual(interceptor.Invocation.GetConcreteMethod(),
                            interceptor.Invocation.GetConcreteMethodInvocationTarget().GetBaseDefinition());

            proxy.DoSomethingZ();
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(List <object>));
            Assert.AreEqual(interceptor.Invocation.GetConcreteMethod(),
                            interceptor.Invocation.GetConcreteMethodInvocationTarget().GetBaseDefinition());
        }
        public void InterfaceProxyWithTargetInterface_MethodInvocationTarget_should_be_methodOnTargetType()
        {
            var interceptor = new KeepDataInterceptor();
            var target      = new ServiceImpl();
            var proxy       =
                generator.CreateInterfaceProxyWithTargetInterface(
                    typeof(IService),
                    target,
                    interceptor
                    ) as IService;

            proxy.Sum(2, 2);
            MethodInfo methodOnTarget = target
                                        .GetType()
                                        .GetMethod("Sum", new[] { typeof(int), typeof(int) });

            Assert.AreSame(methodOnTarget, interceptor.Invocation.MethodInvocationTarget);
        }
Ejemplo n.º 5
0
        public void MethodInfoClosedInGenTypeNongenMethodRefTypeRefType()
        {
            KeepDataInterceptor interceptor = new KeepDataInterceptor();
            GenClassWithGenReturn <List <object>, List <object> > proxy = generator.CreateClassProxy <
                GenClassWithGenReturn <List <object>, List <object> >
                >(interceptor);

            proxy.DoSomethingT();
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(List <object>)
                );

            proxy.DoSomethingZ();
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(List <object>)
                );
        }
Ejemplo n.º 6
0
        public void MethodInfoClosedInGenIfcGenMethodRefTypeWithTarget()
        {
            var interceptor = new KeepDataInterceptor();
            GenInterfaceWithGenMethods <List <object> > target =
                new GenInterfaceWithGenMethodsImpl <List <object> >();
            var proxy = generator.CreateInterfaceProxyWithTarget(target, interceptor);

            proxy.DoSomething(1, null);
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(void),
                typeof(int),
                typeof(List <object>)
                );
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethodInvocationTarget(),
                typeof(void),
                typeof(int),
                typeof(List <object>)
                );
            Assert.AreNotEqual(
                interceptor.Invocation.GetConcreteMethod(),
                interceptor.Invocation.GetConcreteMethodInvocationTarget()
                );

            proxy.DoSomething(new List <object>(), new List <object>());
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(void),
                typeof(List <object>),
                typeof(List <object>)
                );
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethodInvocationTarget(),
                typeof(void),
                typeof(List <object>),
                typeof(List <object>)
                );
            Assert.AreNotEqual(
                interceptor.Invocation.GetConcreteMethod(),
                interceptor.Invocation.GetConcreteMethodInvocationTarget()
                );
        }
        public void MethodInfoClosedInGenIfcNongenMethodValueTypeWithTarget()
        {
            var interceptor = new KeepDataInterceptor();
            IGenInterfaceHierarchyBase <int> target = new GenInterfaceHierarchy <int>();
            var proxy =
                generator.CreateInterfaceProxyWithTarget(target, interceptor);

            proxy.Add(0);
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(void), typeof(int));
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethodInvocationTarget(), typeof(void),
                                                       typeof(int));
            Assert.AreNotEqual(interceptor.Invocation.GetConcreteMethod(),
                               interceptor.Invocation.GetConcreteMethodInvocationTarget());

            proxy.Get();
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(int));
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethodInvocationTarget(), typeof(int));
            Assert.AreNotEqual(interceptor.Invocation.GetConcreteMethod(),
                               interceptor.Invocation.GetConcreteMethodInvocationTarget());
        }
Ejemplo n.º 8
0
        public void MethodInfoClosedInGenIfcNongenMethodValueTypeNoTarget()
        {
            var interceptor = new KeepDataInterceptor();
            var proxy       = generator.CreateInterfaceProxyWithoutTarget <
                IGenInterfaceHierarchyBase <int>
                >(interceptor);

            proxy.Get();
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(int)
                );

            proxy.Add(0);
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(void),
                typeof(int)
                );
        }
Ejemplo n.º 9
0
        public void MethodInfoClosedInNongenTypeGenMethod()
        {
            KeepDataInterceptor interceptor = new KeepDataInterceptor();
            OnlyGenMethodsClass proxy       = generator.CreateClassProxy <OnlyGenMethodsClass>(
                interceptor
                );

            proxy.DoSomething(1);
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(int),
                typeof(int)
                );

            proxy.DoSomething(new List <object>());
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(List <object>),
                typeof(List <object>)
                );
        }
Ejemplo n.º 10
0
        public void MethodInfoClosedInNongenIfcGenMethodNoTarget()
        {
            var interceptor = new KeepDataInterceptor();
            var proxy       = generator.CreateInterfaceProxyWithoutTarget <OnlyGenMethodsInterface>(
                interceptor
                );

            proxy.DoSomething(1);
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(int),
                typeof(int)
                );

            proxy.DoSomething(new List <object>());
            GenericTestUtility.CheckMethodInfoIsClosed(
                interceptor.Invocation.GetConcreteMethod(),
                typeof(List <object>),
                typeof(List <object>)
                );
        }
Ejemplo n.º 11
0
        public void MethodInfoClosedInNongenIfcGenMethodWithTarget()
        {
            var interceptor = new KeepDataInterceptor();
            OnlyGenMethodsInterface target = new OnlyGenMethodsInterfaceImpl();
            var proxy =
                generator.CreateInterfaceProxyWithTarget(target, interceptor);

            proxy.DoSomething(1);
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(int), typeof(int));
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethodInvocationTarget(), typeof(int),
                                                       typeof(int));
            Assert.AreNotEqual(interceptor.Invocation.GetConcreteMethod(),
                               interceptor.Invocation.GetConcreteMethodInvocationTarget());

            proxy.DoSomething(new List <object>());
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(List <object>),
                                                       typeof(List <object>));
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethodInvocationTarget(),
                                                       typeof(List <object>), typeof(List <object>));
            Assert.AreNotEqual(interceptor.Invocation.GetConcreteMethod(),
                               interceptor.Invocation.GetConcreteMethodInvocationTarget());
        }
        public void MethodInfoClosedInGenIfcNongenMethodRefTypeWithTarget()
        {
            KeepDataInterceptor interceptor = new KeepDataInterceptor();
            IGenInterfaceHierarchyBase <List <object> > target = new GenInterfaceHierarchy <List <object> >();
            IGenInterfaceHierarchyBase <List <object> > proxy  =
                generator.CreateInterfaceProxyWithTarget <IGenInterfaceHierarchyBase <List <object> > >(target, interceptor);

            proxy.Add(null);
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(void),
                                                       typeof(List <object>));
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethodInvocationTarget(), typeof(void),
                                                       typeof(List <object>));
            Assert.AreNotEqual(interceptor.Invocation.GetConcreteMethod(),
                               interceptor.Invocation.GetConcreteMethodInvocationTarget());

            proxy.Get();
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(List <object>));
            GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethodInvocationTarget(),
                                                       typeof(List <object>));
            Assert.AreNotEqual(interceptor.Invocation.GetConcreteMethod(),
                               interceptor.Invocation.GetConcreteMethodInvocationTarget());
        }
Ejemplo n.º 13
0
        public void InvocationForInterfaceProxyWithTarget()
        {
            KeepDataInterceptor interceptor = new KeepDataInterceptor();

            object proxy = generator.CreateInterfaceProxyWithTarget(
                typeof(IService),
                new ServiceImpl(),
                interceptor
                );

            IService instance = (IService)proxy;

            instance.Sum(20, 25);

            Assert.IsNotNull(interceptor.Invocation);

            Assert.IsNotNull(interceptor.Invocation.Arguments);
            Assert.AreEqual(2, interceptor.Invocation.Arguments.Length);
            Assert.AreEqual(20, interceptor.Invocation.Arguments[0]);
            Assert.AreEqual(25, interceptor.Invocation.Arguments[1]);
            Assert.AreEqual(20, interceptor.Invocation.GetArgumentValue(0));
            Assert.AreEqual(25, interceptor.Invocation.GetArgumentValue(1));
            Assert.AreEqual(45, interceptor.Invocation.ReturnValue);

            Assert.IsNotNull(interceptor.Invocation.Proxy);
            Assert.IsNotInstanceOf <ServiceImpl>(interceptor.Invocation.Proxy);

            Assert.IsNotNull(interceptor.Invocation.InvocationTarget);
            Assert.IsInstanceOf(typeof(ServiceImpl), interceptor.Invocation.InvocationTarget);
            Assert.IsNotNull(interceptor.Invocation.TargetType);
            Assert.AreSame(typeof(ServiceImpl), interceptor.Invocation.TargetType);

            Assert.IsNotNull(interceptor.Invocation.Method);
            Assert.IsNotNull(interceptor.Invocation.MethodInvocationTarget);
            Assert.AreNotSame(
                interceptor.Invocation.Method,
                interceptor.Invocation.MethodInvocationTarget
                );
        }
Ejemplo n.º 14
0
 public void ThrowsWhenProxyingGenericTypeDefNoTarget()
 {
     var interceptor = new KeepDataInterceptor();
     var o           = generator.CreateInterfaceProxyWithoutTarget(typeof(IGenInterfaceHierarchyBase <>), interceptor);
 }
Ejemplo n.º 15
0
 public void ThrowsWhenProxyingGenericTypeDefNoTarget()
 {
     KeepDataInterceptor interceptor = new KeepDataInterceptor();
     object o = generator.CreateClassProxy(typeof(GenClassWithGenReturn <,>), interceptor);
 }