public void GetAllProvidersThrowExceptionInvalidStatusCode() { var searchResponse = new Mock <ISearchResponse <ProviderDocument> >(); var apiCall = new Mock <IApiCallDetails>(); apiCall.SetupGet(x => x.HttpStatusCode).Returns((int)HttpStatusCode.Ambiguous); searchResponse.SetupGet(x => x.ApiCall).Returns(apiCall.Object); var countResponse = new Mock <ICountResponse>(); countResponse.SetupGet(x => x.Count).Returns(1); _elasticClient.Setup(x => x.Search(It.IsAny <Func <SearchDescriptor <ProviderDocument>, ISearchRequest> >(), It.IsAny <string>())).Returns(searchResponse.Object); var repo = new ProviderRepository( _elasticClient.Object, Mock.Of <IConfigurationSettings>(), _log.Object); _elasticClient.Setup(x => x.Count(It.IsAny <Func <CountDescriptor <Provider>, ICountRequest> >(), It.IsAny <string>())).Returns(countResponse.Object); Assert.Throws <ApplicationException>(() => repo.GetAllProviders()); }
public void GetAllProvidersShouldLogWhenInvalidStatusCode() { var searchResponse = new Mock <ISearchResponse <Provider> >(); var apiCall = new Mock <IApiCallDetails>(); apiCall.SetupGet(x => x.HttpStatusCode).Returns((int)HttpStatusCode.Ambiguous); searchResponse.SetupGet(x => x.ApiCall).Returns(apiCall.Object); _elasticClient.Setup(x => x.Search(It.IsAny <Func <SearchDescriptor <Provider>, ISearchRequest> >(), It.IsAny <string>())).Returns(searchResponse.Object); var repo = new ProviderRepository( _elasticClient.Object, _log.Object, Mock.Of <IConfigurationSettings>(), Mock.Of <IProviderLocationSearchProvider>(), Mock.Of <IProviderMapping>(), _queryHelper.Object, _mockActiveFrameworkChecker.Object, _mockPaginationHelper.Object); Assert.Throws <ApplicationException>(() => repo.GetAllProviders()); _log.Verify(x => x.Log(Microsoft.Extensions.Logging.LogLevel.Warning, It.IsAny <EventId>(), It.IsAny <FormattedLogValues>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once); }