public async Task NotifySearchRequestEventAsync_should_send_httpRequest_to_one_subscribers_and_not_publish_saved() { _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None); var expectedUri = new Uri("http://test:1234/CreateSearchRequest/id"); _httpHandlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.AbsoluteUri == expectedUri.AbsoluteUri // to this uri ), ItExpr.IsAny <CancellationToken>() ); _searchRquestEventPublisherMock.Verify( x => x.PublishSearchRequestSaved( It.IsAny <SearchRequestSavedEvent>()), Times.Never); }
public async Task NotifySearchRequestEventAsync_should_publish_failed_if_http_throw_exception() { _searchRequestOptionsMock.Setup(x => x.Value).Returns( new SearchRequestAdaptorOptions().AddWebHook("test", "http://test.org")); _httpHandlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ).Throws(new Exception("mock http throw exception")); _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None); _httpHandlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ); _searchRquestEventPublisherMock.Verify( x => x.PublishSearchRequestFailed( It.IsAny <SearchRequestEvent>(), It.IsAny <string>()), Times.Once); }
public async Task NotifySearchRequestEventAsync_should_publish_rejected_if_http_return_non_success() { _searchRequestOptionsMock.Setup(x => x.Value).Returns( new SearchRequestAdaptorOptions().AddWebHook("test", "http://test.org")); _httpHandlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("bad request!"), }) .Verifiable(); _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None); _httpHandlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ); _searchRquestEventPublisherMock.Verify( x => x.PublishSearchRequestRejected( It.IsAny <SearchRequestEvent>(), It.IsAny <List <ValidationResult> >()), Times.Once); }
public void NotifySearchRequestEventAsync_should_throw_exception_when_searchREquestOrdered_is_null() { _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); Assert.ThrowsAsync <ArgumentNullException>(() => _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, null, CancellationToken.None)); }
public async Task NotifySearchRequestEventAsync_should_throw_exception_if_invalid_url_setting() { _searchRequestOptionsMock.Setup(x => x.Value).Returns( new SearchRequestAdaptorOptions().AddWebHook("test", "invalidUrl")); _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); Assert.ThrowsAsync <Exception>( async() => await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None)); }
public async Task NotifySearchRequestEventAsync_update_should_send_httpRequest_to_one_subscribers_and_publish_saved() { _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); _fakeSearchRequestOrdered.Action = BcGov.Fams3.SearchApi.Contracts.Person.RequestAction.UPDATE; _httpHandlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject( new SearchRequestSavedEvent() { SearchRequestId = Guid.NewGuid(), Action = BcGov.Fams3.SearchApi.Contracts.Person.RequestAction.UPDATE, SearchRequestKey = "fileId", RequestId = "requestId", ProviderProfile = new SearchRequest.Adaptor.Publisher.Models.ProviderProfile() { Name = "AgencyName" } })), }) .Verifiable(); await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None); var expectedUri = new Uri("http://test:1234/UpdateSearchRequest/id"); _httpHandlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post && req.RequestUri.AbsoluteUri == expectedUri.AbsoluteUri // to this uri ), ItExpr.IsAny <CancellationToken>() ); _searchRquestEventPublisherMock.Verify( x => x.PublishSearchRequestSaved( It.IsAny <SearchRequestSavedEvent>()), Times.Once); }
public async Task NotifySearchRequestEventAsync_should_throw_exception_if_http_throw_exception() { _searchRequestOptionsMock.Setup(x => x.Value).Returns( new SearchRequestAdaptorOptions().AddWebHook("test", "http://test.org")); _httpHandlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ).Throws(new Exception("mock http throw exception")); _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); Assert.ThrowsAsync <Exception>(async() => await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None)); }
public async Task NotifySearchRequestEventAsync_should_publish_failed_if_invalid_url_setting() { _searchRequestOptionsMock.Setup(x => x.Value).Returns( new SearchRequestAdaptorOptions().AddWebHook("test", "invalidUrl")); _sut = new WebHookSearchRequestNotifier(_httpClient, _searchRequestOptionsMock.Object, _loggerMock.Object, _searchRquestEventPublisherMock.Object); await _sut.NotifySearchRequestEventAsync( _fakeSearchRequestOrdered.RequestId, _fakeSearchRequestOrdered, CancellationToken.None); _httpHandlerMock.Protected().Verify( "SendAsync", Times.Exactly(0), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ); _searchRquestEventPublisherMock.Verify( x => x.PublishSearchRequestFailed( It.IsAny <SearchRequestEvent>(), It.IsAny <string>()), Times.Once); }