public void ShouldOnlySubscribeToUnderlyingEndpointResponsesOnce() { IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint2 = A.Fake<IServiceEndpoint>(); IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient2 = A.Fake<IServiceEndpointClient>(); IObservable<IResponse> observable1 = A.Fake<IObservable<IResponse>>(); IObservable<IResponse> observable2 = A.Fake<IObservable<IResponse>>(); IObserver<IResponse> observer1 = A.Fake<IObserver<IResponse>>(); IObserver<IResponse> observer2 = A.Fake<IObserver<IResponse>>(); IRequest request = A.Fake<IRequest>(); A.CallTo(() => serviceEndpointClient1.CanHandle(request)).Returns(true); A.CallTo(() => serviceEndpointClient2.CanHandle(request)).Returns(true); A.CallTo(() => serviceEndpointClient1.GetResponses(request)).Returns(observable1); A.CallTo(() => serviceEndpointClient2.GetResponses(request)).Returns(observable2); IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1, serviceEndpointClient2 }, new[] { serviceEndpoint1, serviceEndpoint2 }); IObservable<IResponse> responses = serviceBus.GetResponses(request); IDisposable sub1 = responses.Subscribe(observer1); IDisposable sub2 = responses.Subscribe(observer2); A.CallTo(() => serviceEndpointClient1.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => serviceEndpointClient2.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => observable1.Subscribe(A<IObserver<IResponse>>._)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => observable2.Subscribe(A<IObserver<IResponse>>._)).MustHaveHappened(Repeated.Exactly.Once); sub1.Dispose(); sub2.Dispose(); }
public void ShouldSendRequestsToCorrectEndpoints() { IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint2 = A.Fake<IServiceEndpoint>(); IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient2 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient3 = A.Fake<IServiceEndpointClient>(); IRequest request = A.Fake<IRequest>(); A.CallTo(() => serviceEndpointClient1.CanHandle(request)).Returns(true); A.CallTo(() => serviceEndpointClient2.CanHandle(request)).Returns(false); A.CallTo(() => serviceEndpointClient3.CanHandle(request)).Returns(true); IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1, serviceEndpointClient2, serviceEndpointClient3 }, new[] { serviceEndpoint1, serviceEndpoint2 }); IDisposable sub1 = serviceBus.GetResponses(request).Subscribe(A.Fake<IObserver<IResponse>>()); A.CallTo(() => serviceEndpointClient1.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => serviceEndpointClient2.GetResponses(request)).MustNotHaveHappened(); A.CallTo(() => serviceEndpointClient3.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Once); IDisposable sub2 = serviceBus.GetResponses<IResponse>(request).Subscribe(A.Fake<IObserver<IResponse>>()); A.CallTo(() => serviceEndpointClient1.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Twice); A.CallTo(() => serviceEndpointClient2.GetResponses(request)).MustNotHaveHappened(); A.CallTo(() => serviceEndpointClient3.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Twice); sub1.Dispose(); sub2.Dispose(); }
public void ShouldSetRequestIdsOnRequestsWhenUsingDefaultRequestCorrelationProvider() { const string requestId = "MyOwnRequestId"; IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint2 = A.Fake<IServiceEndpoint>(); IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient2 = A.Fake<IServiceEndpointClient>(); IObservable<IResponse> observable1 = A.Fake<IObservable<IResponse>>(); IObservable<IResponse> observable2 = A.Fake<IObservable<IResponse>>(); IObserver<IResponse> observer1 = A.Fake<IObserver<IResponse>>(); IObserver<IResponse> observer2 = A.Fake<IObserver<IResponse>>(); IRequest request1 = A.Fake<IRequest>(); IRequest request2 = A.Fake<IRequest>(); request2.RequestId = requestId; A.CallTo(() => serviceEndpointClient1.CanHandle(request1)).Returns(true); A.CallTo(() => serviceEndpointClient2.CanHandle(request2)).Returns(true); A.CallTo(() => serviceEndpointClient1.GetResponses(request1)).Returns(observable1); A.CallTo(() => serviceEndpointClient2.GetResponses(request2)).Returns(observable2); IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1, serviceEndpointClient2 }, new[] { serviceEndpoint1, serviceEndpoint2 }); IObservable<IResponse> responses1 = serviceBus.GetResponses(request1); IObservable<IResponse> responses2 = serviceBus.GetResponses(request2); IDisposable sub1 = responses1.Subscribe(observer1); IDisposable sub2 = responses2.Subscribe(observer2); Assert.That(!string.IsNullOrEmpty(request1.RequestId), "RequestId not set on request"); Assert.That(!string.IsNullOrEmpty(request1.RequesterId), "RequesterId not set on request"); Assert.That(request2.RequestId, Is.EqualTo(requestId), "Custom RequestId was overriden"); Assert.That(!string.IsNullOrEmpty(request2.RequesterId), "RequesterId not set on request"); Assert.That(request1.RequesterId, Is.EqualTo(request2.RequesterId), "RequesterId should the same on both requests"); sub1.Dispose(); sub2.Dispose(); }
public void ShouldReturnResponsesFromUnderlyingEndpoints() { IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>(); IServiceEndpoint serviceEndpoint2 = A.Fake<IServiceEndpoint>(); IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>(); IServiceEndpointClient serviceEndpointClient2 = A.Fake<IServiceEndpointClient>(); IObservable<IResponse> observable1 = A.Fake<IObservable<IResponse>>(); IObservable<IResponse> observable2 = A.Fake<IObservable<IResponse>>(); IObserver<IResponse> observer1 = A.Fake<IObserver<IResponse>>(); IObserver<IResponse> observer2 = A.Fake<IObserver<IResponse>>(); IRequest request = A.Fake<IRequest>(); A.CallTo(() => serviceEndpointClient1.GetResponses(request)).Returns(observable1); A.CallTo(() => serviceEndpointClient2.GetResponses(request)).Returns(observable2); A.CallTo(() => serviceEndpointClient1.CanHandle(request)).Returns(true); A.CallTo(() => serviceEndpointClient2.CanHandle(request)).Returns(true); IObserver<IResponse> internalObserver1 = null; IObserver<IResponse> internalObserver2 = null; A.CallTo(() => observable1.Subscribe(A<IObserver<IResponse>>._)).Invokes(call => internalObserver1 = call.GetArgument<IObserver<IResponse>>(0)); A.CallTo(() => observable2.Subscribe(A<IObserver<IResponse>>._)).Invokes(call => internalObserver2 = call.GetArgument<IObserver<IResponse>>(0)); IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1, serviceEndpointClient2 }, new[] { serviceEndpoint1, serviceEndpoint2 }); IObservable<IResponse> responses = serviceBus.GetResponses(request); IDisposable sub1 = responses.Subscribe(observer1); IDisposable sub2 = responses.Subscribe(observer2); Assert.That(internalObserver1, Is.Not.Null); Assert.That(internalObserver2, Is.Not.Null); // ensure id's on responses match those set on the request IResponse response1 = A.Fake<IResponse>(); IResponse response2 = A.Fake<IResponse>(); response1.RequestId = request.RequestId; response2.RequestId = request.RequestId; response1.RequesterId = request.RequesterId; response2.RequesterId = request.RequesterId; internalObserver1.OnNext(response1); internalObserver2.OnNext(response2); A.CallTo(() => observer1.OnNext(response1)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => observer2.OnNext(response1)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => observer1.OnNext(response1)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => observer2.OnNext(response2)).MustHaveHappened(Repeated.Exactly.Once); sub1.Dispose(); sub2.Dispose(); }