public void GetProviderFrameworksByUkprnShouldLogWhenFrameworkDetailsNotAsExpected() { var ukprn = 1L; var searchResponse = new Mock <ISearchResponse <ProviderFrameworkDto> >(); 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 <ProviderFrameworkDto>, 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.GetFrameworksByProviderUkprn(ukprn)); var message = $"httpStatusCode was {(int)HttpStatusCode.Ambiguous} when querying provider frameworks for ukprn [{ukprn}]"; _log.Verify(x => x.Log(Microsoft.Extensions.Logging.LogLevel.Warning, It.IsAny <EventId>(), It.Is <FormattedLogValues>(a => a.ToString() == message), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >()), Times.Once); }
public void GetProviderFrameworksByUkprn() { var ukprn = 1L; var searchResponseForFrameworkDtos = new Mock <ISearchResponse <ProviderFrameworkDto> >(); var apiCallForFrameworkDtos = new Mock <IApiCallDetails>(); var searchResponseForFrameworks = new Mock <ISearchResponse <ProviderFramework> >(); var apiCallForFrameworks = new Mock <IApiCallDetails>(); searchResponseForFrameworkDtos.Setup(x => x.Documents).Returns(new List <ProviderFrameworkDto> { new ProviderFrameworkDto() }); var providerFrameworks = new List <ProviderFramework> { new ProviderFramework { FrameworkId = "321-3-1" }, new ProviderFramework { FrameworkId = "322-3-1" }, new ProviderFramework { FrameworkId = "323-3-1" }, }; searchResponseForFrameworks.Setup(x => x.Documents).Returns(providerFrameworks); apiCallForFrameworkDtos.SetupGet(x => x.HttpStatusCode).Returns((int)HttpStatusCode.OK); searchResponseForFrameworkDtos.SetupGet(x => x.ApiCall).Returns(apiCallForFrameworkDtos.Object); apiCallForFrameworks.SetupGet(x => x.HttpStatusCode).Returns((int)HttpStatusCode.OK); searchResponseForFrameworks.SetupGet(x => x.ApiCall).Returns(apiCallForFrameworks.Object); _elasticClient.Setup(x => x.Search(It.IsAny <Func <SearchDescriptor <ProviderFrameworkDto>, ISearchRequest> >(), It.IsAny <string>())).Returns(searchResponseForFrameworkDtos.Object); _elasticClient.Setup(x => x.Search(It.IsAny <Func <SearchDescriptor <ProviderFramework>, ISearchRequest> >(), It.IsAny <string>())).Returns(searchResponseForFrameworks.Object); var repo = new ProviderRepository( _elasticClient.Object, _log.Object, Mock.Of <IConfigurationSettings>(), Mock.Of <IProviderLocationSearchProvider>(), Mock.Of <IProviderMapping>(), _queryHelper.Object, _mockActiveFrameworkChecker.Object, _mockPaginationHelper.Object); var result = repo.GetFrameworksByProviderUkprn(ukprn); Assert.AreEqual(result.Count(), providerFrameworks.Count); _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.Never); }