public void Same_Interface_on_proxy_with_target_interface_and_mixin_should_forward_to_target() { var target = new ServiceImpl(); var mixin = new AlwaysThrowsServiceImpl(); var proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof (IService), target, MixIn(mixin)); Assert.DoesNotThrow(() => (proxy as IService).Sum(2, 2)); }
public void InterfaceProxyWithTargetInterface_MethodInvocationTarget_should_be_updated_when_target_changes() { MethodInfo invocationTarget1 = null; MethodInfo invocationTarget2 = null; var target1 = new AlwaysThrowsServiceImpl(); var target2 = new ServiceImpl(); MethodInfo methodOnTarget1 = target1.GetType().GetMethod("Sum", new[] { typeof(int), typeof(int) }); MethodInfo methodOnTarget2 = target2.GetType().GetMethod("Sum", new[] { typeof(int), typeof(int) }); var proxy = generator.CreateInterfaceProxyWithTargetInterface( typeof(IService), target1, new WithCallbackInterceptor(i => { invocationTarget1 = i.MethodInvocationTarget; i.Proceed(); }), new ChangeTargetInterceptor(target2), new WithCallbackInterceptor(i => { invocationTarget2 = i.MethodInvocationTarget; i.Proceed(); })) as IService; proxy.Sum(2, 2); Assert.AreNotEqual(invocationTarget1, invocationTarget2); Assert.AreSame(methodOnTarget1, invocationTarget1); Assert.AreSame(methodOnTarget2, invocationTarget2); }
public void Same_Interface_on_target_and_mixin_should_forward_to_target() { var target = new ServiceImpl(); var mixin = new AlwaysThrowsServiceImpl(); var proxy = generator.CreateInterfaceProxyWithTarget(typeof (IService), Type.EmptyTypes, target, MixIn(mixin)) as IService; Assert.DoesNotThrow(() => proxy.Sum(1, 2)); }
public void Same_Interface_on_proxy_with_target_interface_and_mixin_should_forward_to_target() { var target = new ServiceImpl(); var mixin = new AlwaysThrowsServiceImpl(); var proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IService), target, MixIn(mixin)); Assert.DoesNotThrow(() => (proxy as IService).Sum(2, 2)); }
public void Same_Interface_on_target_and_mixin_should_forward_to_target() { var target = new ServiceImpl(); var mixin = new AlwaysThrowsServiceImpl(); var proxy = generator.CreateInterfaceProxyWithTarget(typeof(IService), Type.EmptyTypes, target, MixIn(mixin)) as IService; Assert.DoesNotThrow(() => proxy.Sum(1, 2)); }
public void Same_Interface_on_proxy_withouth_target_and_mixin_should_forward_to_null_target() { var interceptor = new WithCallbackInterceptor(i => { Assert.IsNull(i.InvocationTarget); i.ReturnValue = 0; }); var mixin = new AlwaysThrowsServiceImpl(); var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof (IService), Type.EmptyTypes, MixIn(mixin), interceptor); Assert.DoesNotThrow(() => (proxy as IService).Sum(2, 2)); }
public void Same_Interface_on_proxy_withouth_target_and_mixin_should_forward_to_null_target() { var interceptor = new WithCallbackInterceptor(i => { Assert.IsNull(i.InvocationTarget); i.ReturnValue = 0; }); var mixin = new AlwaysThrowsServiceImpl(); var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IService), Type.EmptyTypes, MixIn(mixin), interceptor); Assert.DoesNotThrow(() => (proxy as IService).Sum(2, 2)); }