public void InterfaceProxyWithTarget_MethodInvocationTarget_should_be_methodOnTargetType() { var interceptor = new KeepDataInterceptor(); var target = new ServiceImpl(); var proxy = generator.CreateInterfaceProxyWithTarget<IService>(target, interceptor); proxy.Sum(2, 2); MethodInfo methodOnTarget = target.GetType().GetMethod("Sum", new[] { typeof(int), typeof(int) }); Assert.AreSame(methodOnTarget, interceptor.Invocation.MethodInvocationTarget); }
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); }