Exemplo n.º 1
0
        public void ShouldCompleteGetResponseWhenOneResponseReturned()
        {
            IServiceEndpoint serviceEndpoint1 = A.Fake<IServiceEndpoint>();
            IServiceEndpointClient serviceEndpointClient1 = A.Fake<IServiceEndpointClient>();
            
            IRequest request = A.Fake<IRequest>();
            var response = A.Fake<IResponse>();
            var subject = new Subject<IResponse>();
            var requestCorrelationProvider = A.Fake<IRequestCorrelationProvider>();

            A.CallTo(() => requestCorrelationProvider.AreCorrelated(request, response)).Returns(true);
            A.CallTo(() => serviceEndpointClient1.CanHandle(request)).Returns(true);
            A.CallTo(() => serviceEndpointClient1.GetResponses(request)).Returns(subject);

            IServiceBus serviceBus = new ServiceBus(new[] { serviceEndpointClient1 }, new[] { serviceEndpoint1  }, requestCorrelationProvider);

            var observer = A.Fake<IObserver<IResponse>>();
            IDisposable sub1 = serviceBus.GetResponse<IResponse>(request).Subscribe(observer);

            A.CallTo(() => serviceEndpointClient1.GetResponses(request)).MustHaveHappened(Repeated.Exactly.Once);

            subject.OnNext(response);

            A.CallTo(() => observer.OnNext(response)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => observer.OnCompleted()).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => observer.OnError(A<Exception>._)).MustNotHaveHappened();
            
            sub1.Dispose();
        }