public void ShouldAttemptToSendResponseToAllEndpointsWhenExceptionsAreThrown() { IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint2 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint3 = A.Fake<IServiceEndpoint>(); IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient2 = A.Fake<IServiceEndpointClient>(); IRequest request = A.Fake<IRequest>(); IResponse response = A.Fake<IResponse>(); A.CallTo(() => serviceEndpoint1.CanHandle(A<IResponse>._)).Returns(true); A.CallTo(() => serviceEndpoint2.CanHandle(A<IResponse>._)).Returns(true); A.CallTo(() => serviceEndpoint3.CanHandle(A<IResponse>._)).Returns(true); Exception originalException = new Exception("Something went wrong"); A.CallTo(() => serviceEndpoint2.ReplyAsync(request, response)).Throws(originalException); IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1, serviceEndpointClient2 }, new[] { serviceEndpoint1, serviceEndpoint2, serviceEndpoint3 }); AggregateException aggregateException = null; try { serviceBus.ReplyAsync(request, response); } catch (AggregateException ex) { aggregateException = ex; Console.WriteLine(ex); } Assert.That(aggregateException != null, "No aggregate exception was thrown"); Assert.That(aggregateException.InnerExceptions.Any(e => e.InnerException == originalException), "Aggregate exception did not contain original exception"); A.CallTo(() => serviceEndpoint1.ReplyAsync(request, response)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => serviceEndpoint2.ReplyAsync(request, response)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => serviceEndpoint3.ReplyAsync(request, response)).MustHaveHappened(Repeated.Exactly.Once); }
public void ShouldSendResponsesToCorrectEndpoints() { IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint2 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint3 = A.Fake<IServiceEndpoint>(); IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient2 = A.Fake<IServiceEndpointClient>(); IRequest request = A.Fake<IRequest>(); IResponse response = A.Fake<IResponse>(); A.CallTo(() => serviceEndpoint1.CanHandle(response)).Returns(true); A.CallTo(() => serviceEndpoint2.CanHandle(response)).Returns(false); A.CallTo(() => serviceEndpoint3.CanHandle(response)).Returns(true); IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1, serviceEndpointClient2 }, new[] { serviceEndpoint1, serviceEndpoint2, serviceEndpoint3 }); serviceBus.ReplyAsync(request, response); A.CallTo(() => serviceEndpoint1.ReplyAsync(request, response)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => serviceEndpoint2.ReplyAsync(request, response)).MustNotHaveHappened(); A.CallTo(() => serviceEndpoint3.ReplyAsync(request, response)).MustHaveHappened(Repeated.Exactly.Once); }