public void Execute_CompositeInterceptor_CallsProceedInExpectedSequence() { int callOrder = 0; var firstInterceptorMock = new Mock <IInterceptor>(); firstInterceptorMock.Setup(i => i.Invoke(It.IsAny <IInvocationInfo>())) .Callback(() => Assert.AreEqual(0, callOrder++)) .Returns <IInvocationInfo>(ii => ii.Proceed()); var secondInterceptorMock = new Mock <IInterceptor>(); secondInterceptorMock.Setup(i => i.Invoke(It.IsAny <IInvocationInfo>())) .Callback(() => Assert.AreEqual(1, callOrder++)) .Returns <IInvocationInfo>(ii => ii.Proceed()); var thirdInterceptorMock = new Mock <IInterceptor>(); thirdInterceptorMock.Setup(i => i.Invoke(It.IsAny <IInvocationInfo>())) .Callback(() => Assert.AreEqual(2, callOrder++)) .Returns <IInvocationInfo>(ii => ii.Proceed()); var invocationMock = new Mock <IInvocationInfo>(); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy <IInterceptor>(() => firstInterceptorMock.Object), new Lazy <IInterceptor>(() => secondInterceptorMock.Object), new Lazy <IInterceptor>(() => thirdInterceptorMock.Object) }); compositeInterceptor.Invoke(invocationMock.Object); }
public void Execute_CompositeInterceptor_CallsProceedInExpectedSequence() { int callOrder = 0; var firstInterceptorMock = new Mock<IInterceptor>(); firstInterceptorMock.Setup(i => i.Invoke(It.IsAny<IInvocationInfo>())) .Callback(() => Assert.Equal(0, callOrder++)) .Returns<IInvocationInfo>(ii => ii.Proceed()); var secondInterceptorMock = new Mock<IInterceptor>(); secondInterceptorMock.Setup(i => i.Invoke(It.IsAny<IInvocationInfo>())) .Callback(() => Assert.Equal(1, callOrder++)) .Returns<IInvocationInfo>(ii => ii.Proceed()); var thirdInterceptorMock = new Mock<IInterceptor>(); thirdInterceptorMock.Setup(i => i.Invoke(It.IsAny<IInvocationInfo>())) .Callback(() => Assert.Equal(2, callOrder++)) .Returns<IInvocationInfo>(ii => ii.Proceed()); var invocationMock = new Mock<IInvocationInfo>(); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy<IInterceptor>(() => firstInterceptorMock.Object), new Lazy<IInterceptor>(() => secondInterceptorMock.Object), new Lazy<IInterceptor>(() => thirdInterceptorMock.Object) }); compositeInterceptor.Invoke(invocationMock.Object); }
public void SingleInterceptorCalled(IInterceptor interceptor, IInvocation invocation) { var sut = new CompositeInterceptor(interceptor); sut.Intercept(invocation); interceptor.Received().Intercept(invocation); }
public void InterceptorsCalledInOrder([Frozen] IInterceptor[] interceptors, CompositeInterceptor sut, IInvocation invocation) { var results = new List <IInterceptor>(); foreach (var i in interceptors) { i.When(x => x.Intercept(invocation)).Do(_ => results.Add(i)); } sut.Intercept(invocation); results.Should().Equal(interceptors); }
public void Execute_CompositeInterceptor_PassesArgumentsToInterceptor() { var firstInterceptorMock = new Mock<IInterceptor>(); var secondInterceptorMock = new Mock<IInterceptor>(); var invocationMock = new Mock<IInvocationInfo>(); var arguments = new object[]{42}; invocationMock.SetupGet(i => i.Arguments).Returns(arguments); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy<IInterceptor>(() => firstInterceptorMock.Object), new Lazy<IInterceptor>(() => secondInterceptorMock.Object), }); compositeInterceptor.Invoke(invocationMock.Object); firstInterceptorMock.Verify(i => i.Invoke(It.Is<IInvocationInfo>(ii => ii.Arguments == arguments))); }
public void Execute_CompositeInterceptor_PassesMethodToInterceptor() { var firstInterceptorMock = new Mock<IInterceptor>(); var secondInterceptorMock = new Mock<IInterceptor>(); var invocationMock = new Mock<IInvocationInfo>(); var method = typeof(IMethodWithNoParameters).GetMethods()[0]; invocationMock.SetupGet(i => i.Method).Returns(method); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy<IInterceptor>(() => firstInterceptorMock.Object), new Lazy<IInterceptor>(() => secondInterceptorMock.Object), }); compositeInterceptor.Invoke(invocationMock.Object); firstInterceptorMock.Verify(i => i.Invoke(It.Is<IInvocationInfo>(ii => ii.Method == method))); }
public void Execute_CompositeInterceptor_PassesProxyToInterceptor() { var firstInterceptorMock = new Mock <IInterceptor>(); var secondInterceptorMock = new Mock <IInterceptor>(); var invocationMock = new Mock <IInvocationInfo>(); IProxy proxy = new Mock <IProxy>().Object; invocationMock.SetupGet(i => i.Proxy).Returns(proxy); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy <IInterceptor>(() => firstInterceptorMock.Object), new Lazy <IInterceptor>(() => secondInterceptorMock.Object), }); compositeInterceptor.Invoke(invocationMock.Object); firstInterceptorMock.Verify(i => i.Invoke(It.Is <IInvocationInfo>(ii => ii.Proxy == proxy))); }
public void Execute_CompositeInterceptor_PassesArgumentsToInterceptor() { var firstInterceptorMock = new Mock <IInterceptor>(); var secondInterceptorMock = new Mock <IInterceptor>(); var invocationMock = new Mock <IInvocationInfo>(); var arguments = new object[] { 42 }; invocationMock.SetupGet(i => i.Arguments).Returns(arguments); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy <IInterceptor>(() => firstInterceptorMock.Object), new Lazy <IInterceptor>(() => secondInterceptorMock.Object), }); compositeInterceptor.Invoke(invocationMock.Object); firstInterceptorMock.Verify(i => i.Invoke(It.Is <IInvocationInfo>(ii => ii.Arguments == arguments))); }
public void Execute_CompositeInterceptor_PassesMethodToInterceptor() { var firstInterceptorMock = new Mock <IInterceptor>(); var secondInterceptorMock = new Mock <IInterceptor>(); var invocationMock = new Mock <IInvocationInfo>(); var method = typeof(IMethodWithNoParameters).GetMethods()[0]; invocationMock.SetupGet(i => i.Method).Returns(method); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy <IInterceptor>(() => firstInterceptorMock.Object), new Lazy <IInterceptor>(() => secondInterceptorMock.Object), }); compositeInterceptor.Invoke(invocationMock.Object); firstInterceptorMock.Verify(i => i.Invoke(It.Is <IInvocationInfo>(ii => ii.Method == method))); }
public void ShouldCallAddedInterceptorsOnConsume() { var sourceMessage = new ConsumedMessage(null, new MessageProperties(), new byte[0]); var firstMessage = new ConsumedMessage(null, new MessageProperties(), new byte[0]); var secondMessage = new ConsumedMessage(null, new MessageProperties(), new byte[0]); var first = Substitute.For <IProduceConsumeInterceptor>(); var second = Substitute.For <IProduceConsumeInterceptor>(); first.OnConsume(secondMessage).Returns(firstMessage); second.OnConsume(sourceMessage).Returns(secondMessage); var compositeInterceptor = new CompositeInterceptor(); compositeInterceptor.Add(first); compositeInterceptor.Add(second); Assert.Equal(firstMessage, compositeInterceptor.OnConsume(sourceMessage)); }
public void ShouldCallAddedInterceptorsOnProduce() { var sourceMessage = new RawMessage(new MessageProperties(), new byte[0]); var firstMessage = new RawMessage(new MessageProperties(), new byte[0]); var secondMessage = new RawMessage(new MessageProperties(), new byte[0]); var first = NewMock <IProduceConsumeInterceptor>(); var second = NewMock <IProduceConsumeInterceptor>(); first.Expect(x => x.OnProduce(sourceMessage)).Return(firstMessage); second.Expect(x => x.OnProduce(firstMessage)).Return(secondMessage); var compositeInterceptor = new CompositeInterceptor(); compositeInterceptor.Add(first); compositeInterceptor.Add(second); Assert.AreEqual(secondMessage, compositeInterceptor.OnProduce(sourceMessage)); }
public void Execute_CompositeInterceptor_PassesProxyToInterceptor() { var firstInterceptorMock = new Mock<IInterceptor>(); var secondInterceptorMock = new Mock<IInterceptor>(); var invocationMock = new Mock<IInvocationInfo>(); IProxy proxy = new Mock<IProxy>().Object; invocationMock.SetupGet(i => i.Proxy).Returns(proxy); var compositeInterceptor = new CompositeInterceptor(new[] { new Lazy<IInterceptor>(() => firstInterceptorMock.Object), new Lazy<IInterceptor>(() => secondInterceptorMock.Object), }); compositeInterceptor.Invoke(invocationMock.Object); firstInterceptorMock.Verify(i => i.Invoke(It.Is<IInvocationInfo>(ii => ii.Proxy == proxy))); }
public InterceptorRegistrator(IServiceRegister serviceRegister) { this.serviceRegister = serviceRegister; compositeInterceptor = new CompositeInterceptor(); }
public InterceptorRegistrator(IServiceRegister serviceRegister) { this.serviceRegister = serviceRegister; compositeInterceptor = new CompositeInterceptor(); }
public void ThrowsOnNullInvocation(CompositeInterceptor sut) { sut.Invoking(s => s.Intercept(null)) .ShouldThrow <ArgumentNullException>(); }
public void SutIsInterceptor(CompositeInterceptor sut) { sut.Should().BeAssignableTo <IInterceptor>(); }