public void MethodWithReferenceTypeReturnValue_InterceptorMustBeAbleToChangeReturnValue() { const string ExpectedString = "HelloWorldIntercepted"; const string InterceptorAppends = "Intercepted"; var argument1 = new OverrideToString("Hello"); var argument2 = new OverrideToString("World"); var fakeInterceptor = new Mock <IDynamicInterceptor>(); fakeInterceptor .Setup(x => x.Intercept(It.IsAny <IInvocation>())) .Callback <IInvocation>( invocation => { invocation.Proceed(); invocation.ReturnValue = ((string)invocation.ReturnValue) + InterceptorAppends; }); using (IKernel kernel = new StandardKernel()) { kernel.Bind <IDynamicInterceptorManager>().To <DynamicInterceptorManager>(); kernel.Bind <IDynamicInterceptorCollection>().ToConstant(new FakeDynamicInterceptorCollection(fakeInterceptor.Object)); var instance = kernel.Get <IntegrationWithReturnValue>(); instance.CombineToStrings(argument1, argument2) .Should().Be(ExpectedString); } }
public void MethodWithReferenceTypeReturnValue_NoInterceptor_MustReturnOriginalMethodReturnValue() { const string ExpectedString = "HelloWorld"; var argument1 = new OverrideToString("Hello"); var argument2 = new OverrideToString("World"); using (IKernel kernel = new StandardKernel()) { kernel.Bind <IDynamicInterceptorManager>().To <DynamicInterceptorManager>(); kernel.Bind <IDynamicInterceptorCollection>().ToConstant(new FakeDynamicInterceptorCollection()); var instance = kernel.Get <IntegrationWithReturnValue>(); instance.CombineToStrings(argument1, argument2) .Should().Be(ExpectedString); } }
public void MethodWithReferenceTypeReturnValue_InterceptorMustBeAbleToChangeReturnValue() { const string ExpectedString = "HelloWorldIntercepted"; const string InterceptorAppends = "Intercepted"; var argument1 = new OverrideToString("Hello"); var argument2 = new OverrideToString("World"); var fakeInterceptor = new Mock<IDynamicInterceptor>(); fakeInterceptor .Setup(x => x.Intercept(It.IsAny<IInvocation>())) .Callback<IInvocation>( invocation => { invocation.Proceed(); invocation.ReturnValue = ((string)invocation.ReturnValue) + InterceptorAppends; }); using (IKernel kernel = new StandardKernel()) { kernel.Bind<IDynamicInterceptorManager>().To<DynamicInterceptorManager>(); kernel.Bind<IDynamicInterceptorCollection>().ToConstant(new FakeDynamicInterceptorCollection(fakeInterceptor.Object)); var instance = kernel.Get<IntegrationWithReturnValue>(); instance.CombineToStrings(argument1, argument2) .Should().Be(ExpectedString); } }
public void MethodWithReferenceTypeReturnValue_NoInterceptor_MustReturnOriginalMethodReturnValue() { const string ExpectedString = "HelloWorld"; var argument1 = new OverrideToString("Hello"); var argument2 = new OverrideToString("World"); using (IKernel kernel = new StandardKernel()) { kernel.Bind<IDynamicInterceptorManager>().To<DynamicInterceptorManager>(); kernel.Bind<IDynamicInterceptorCollection>().ToConstant(new FakeDynamicInterceptorCollection()); var instance = kernel.Get<IntegrationWithReturnValue>(); instance.CombineToStrings(argument1, argument2) .Should().Be(ExpectedString); } }