public void InterfaceProxyWithTarget_MethodInvocationTarget_should_be_null() { var interceptor = new KeepDataInterceptor(); var proxy = generator.CreateInterfaceProxyWithoutTarget<IService>(interceptor); proxy.Sum(2, 2); Assert.IsNull(interceptor.Invocation.MethodInvocationTarget); }
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(typeof(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); }
public void InvocationForConcreteClassProxy() { KeepDataInterceptor interceptor = new KeepDataInterceptor(); object proxy = generator.CreateClassProxy(typeof (ServiceClass), interceptor); ServiceClass instance = (ServiceClass) 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.IsInstanceOf(typeof (ServiceClass), interceptor.Invocation.Proxy); Assert.IsNotNull(interceptor.Invocation.InvocationTarget); Assert.IsInstanceOf(typeof (ServiceClass), interceptor.Invocation.InvocationTarget); Assert.IsNotNull(interceptor.Invocation.TargetType); Assert.AreSame(typeof (ServiceClass), interceptor.Invocation.TargetType); Assert.IsNotNull(interceptor.Invocation.Method); Assert.IsNotNull(interceptor.Invocation.MethodInvocationTarget); Assert.AreSame(interceptor.Invocation.Method, interceptor.Invocation.MethodInvocationTarget.GetBaseDefinition()); }
public void ClassProxy_MethodInvocationTarget_should_be_base_Method_for_interface_methods_implemented_virtually() { var interceptor = new KeepDataInterceptor(); var proxy = generator.CreateClassProxy(typeof(ClassWithVirtualInterface), new[] { typeof(ISimpleInterface) }, interceptor) as ISimpleInterface; proxy.Do(); var methodOnClass = typeof(ClassWithVirtualInterface).GetMethod("Do", Type.EmptyTypes); Assert.AreSame(methodOnClass, interceptor.Invocation.MethodInvocationTarget); }
public void ClassProxy_MethodInvocationTarget_should_be_base_Method_for_interface_methods_implemented_non_virtually() { var interceptor = new KeepDataInterceptor(); var proxy = generator.CreateClassProxy(typeof(One), new[] { typeof(IOne) }, interceptor) as IOne; proxy.OneMethod(); var methodOnInterface = typeof(One).GetMethod("OneMethod", Type.EmptyTypes); Assert.AreSame(methodOnInterface, interceptor.Invocation.MethodInvocationTarget); }
public void ClassProxy_MethodInvocationTarget_should_be_base_Method() { var interceptor = new KeepDataInterceptor(); var proxy = generator.CreateClassProxy<ServiceClass>(interceptor); proxy.Sum(2, 2); var methodOnClass = typeof(ServiceClass).GetMethod("Sum", new[] { typeof(int), typeof(int) }); Assert.AreSame(methodOnClass, interceptor.Invocation.MethodInvocationTarget); }
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); }
public void Should_share_invocations_for_interface_methods() { var interceptor1 = new KeepDataInterceptor(); var interceptor2 = new KeepDataInterceptor(); var first = generator.CreateInterfaceProxyWithTarget<IOne>(new One(), interceptor1); var second = generator.CreateInterfaceProxyWithTarget<IOne>(new OneTwo(), interceptor2); Assert.AreNotEqual(first.GetType(), second.GetType(), "proxy types are different"); first.OneMethod(); second.OneMethod(); Assert.AreEqual(interceptor1.Invocation.GetType(), interceptor2.Invocation.GetType()); }
public void GenericMethod_WithConstraintOnSurroundingTypeParameter () { Type type = typeof (IGenericInterfaceWithGenericMethodWithDependentConstraint<object>); KeepDataInterceptor interceptor = new KeepDataInterceptor (); IGenericInterfaceWithGenericMethodWithDependentConstraint<object> proxy = (IGenericInterfaceWithGenericMethodWithDependentConstraint<object>) generator.CreateInterfaceProxyWithoutTarget(type, new Type[] { }, interceptor); proxy.RegisterType<string> (); MethodInfo expectedMethod = typeof (IGenericInterfaceWithGenericMethodWithDependentConstraint<object>).GetMethod ("RegisterType").MakeGenericMethod (typeof (string)); Assert.AreEqual (expectedMethod, interceptor.Invocation.Method); }
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); }
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 ThrowsWhenProxyingGenericTypeDefNoTarget() { var interceptor = new KeepDataInterceptor(); Assert.Throws<GeneratorException>(() => generator.CreateInterfaceProxyWithoutTarget(typeof(IGenInterfaceHierarchyBase<>), interceptor) ); }
public void ThrowsWhenProxyingGenericTypeDefNoTarget() { KeepDataInterceptor interceptor = new KeepDataInterceptor(); Assert.Throws<GeneratorException>(delegate { generator.CreateClassProxy(typeof(GenClassWithGenReturn<,>), interceptor); }); }
public void MethodInfoClosedInGenTypeGenMethodValueType() { KeepDataInterceptor interceptor = new KeepDataInterceptor(); GenClassWithGenMethods<int> proxy = generator.CreateClassProxy<GenClassWithGenMethods<int>>(interceptor); proxy.DoSomething(1); GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof (int), typeof (int)); Assert.AreEqual(interceptor.Invocation.GetConcreteMethod(), interceptor.Invocation.GetConcreteMethodInvocationTarget()); proxy.DoSomething(new List<object>()); GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof (int), typeof (List<object>)); Assert.AreEqual(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()); }
public void ChangeProxyTarget_should_not_affect_invocation_target() { var first = new ChangeProxyTargetInterceptor(new OneTwo()); var second = new KeepDataInterceptor(); var proxy = generator.CreateInterfaceProxyWithTargetInterface<IOne>(new One(), first, second); proxy.OneMethod(); Assert.AreEqual(typeof(One), second.Invocation.InvocationTarget.GetType()); }
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 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 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)); }
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>)); }
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>)); }
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>)); }
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()); }
public void ThrowsWhenProxyingGenericTypeDefNoTarget() { KeepDataInterceptor interceptor = new KeepDataInterceptor(); object o = generator.CreateClassProxy(typeof (GenClassWithGenReturn<,>), interceptor); }
public void ThrowsWhenProxyingGenericTypeDefNoTarget() { var interceptor = new KeepDataInterceptor(); var o = generator.CreateInterfaceProxyWithoutTarget(typeof(IGenInterfaceHierarchyBase<>), interceptor); }
public void ClassProxyForGeneric_MethodInvocationTarget_should_be_proxyMethod() { var interceptor = new KeepDataInterceptor(); var proxy = (IChangeTracking)generator.CreateClassProxy<GenClassWithExplicitImpl<int>>(interceptor); Assert.IsTrue(proxy.IsChanged); Assert.IsNotNull(interceptor.Invocation.MethodInvocationTarget); }
public void CanCreateProxyOfInterfaceWithOutParameter() { var interceptor = new KeepDataInterceptor(); var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IWithRefOut), interceptor); Assert.IsNotNull(proxy); }
public void MethodInfoClosedInGenIfcGenMethodValueTypeNoTarget() { KeepDataInterceptor interceptor = new KeepDataInterceptor(); GenInterfaceWithGenMethods<int> proxy = generator.CreateInterfaceProxyWithoutTarget<GenInterfaceWithGenMethods<int>>(interceptor); proxy.DoSomething(1, 1); GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(void), typeof(int), typeof(int)); proxy.DoSomething(new List<object>(), 1); GenericTestUtility.CheckMethodInfoIsClosed(interceptor.Invocation.GetConcreteMethod(), typeof(void), typeof(List<object>), typeof(int)); }