public async Task GetLocalAuthoritiesByFundingStreamId_WhenAuthoritiesProvidedForProviderVersionId_OkesultsReturned() { // Arrange string authorityFacet = "authority"; string providerVersionIdFacet = "providerVersionId"; string aFacetValue1 = "Kent"; string aFacetValue2 = "Essex"; string providerVersionId = "dsg-2020-07-03"; SearchResults <ProvidersIndex> authorityResults = new SearchResults <ProvidersIndex> { Facets = new List <Facet> { new Facet { Name = authorityFacet, FacetValues = new List <FacetValue>() { new FacetValue { Name = aFacetValue1 }, new FacetValue { Name = aFacetValue2 } } } } }; SearchResults <ProvidersIndex> providerVersionResults = new SearchResults <ProvidersIndex> { Facets = new List <Facet> { new Facet { Name = providerVersionIdFacet, FacetValues = new List <FacetValue> { new FacetValue { Name = providerVersionId } } } } }; ISearchRepository <ProvidersIndex> searchRepository = CreateSearchRepository(); searchRepository .Search(string.Empty, Arg.Is <SearchParameters>(x => x.Facets.Any(x => x.Contains(authorityFacet)))) .Returns(authorityResults); searchRepository .Search(string.Empty, Arg.Is <SearchParameters>(x => x.Facets.Any(x => x.Contains(providerVersionIdFacet)))) .Returns(providerVersionResults); searchRepository .Search(string.Empty, Arg.Is <SearchParameters>(x => x.Facets == null || !x.Facets.Any())) .Returns(new SearchResults <ProvidersIndex>()); CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(_ => _.ForFundingStreamId("fundingStreamId")); currentProviderVersion.ProviderVersionId = providerVersionId; IProviderVersionsMetadataRepository providerVersionsMetadataRepository = CreateProviderVersionMetadataRepository(); providerVersionsMetadataRepository.GetCurrentProviderVersion(Arg.Any <string>()) .Returns(currentProviderVersion); IProviderVersionSearchService providerService = CreateProviderVersionSearchService(searchRepository: searchRepository, providerVersionMetadataRepository: providerVersionsMetadataRepository); // Act IActionResult notFoundRequest = await providerService.GetLocalAuthoritiesByFundingStreamId("fundingStreamId"); // Assert notFoundRequest .Should() .BeOfType <OkObjectResult>(); ((IEnumerable <string>)((OkObjectResult)notFoundRequest).Value).Should().Contain(aFacetValue1); ((IEnumerable <string>)((OkObjectResult)notFoundRequest).Value).Should().Contain(aFacetValue2); }
private async Task <CurrentProviderVersion> GetCurrentProviderVersion(string fundingStreamId) => await _providerVersionsMetadataRepositoryPolicy.ExecuteAsync(() => _providerVersionsMetadataRepository.GetCurrentProviderVersion(fundingStreamId));
public async Task GetLocalAuthoritiesByFundingStreamId_WhenFundingStreamIdFacetNotProvided_NotFoundResultReturned() { // Arrange string authorityFacet = "authority"; string providerVersionIdFacet = "providerVersionId"; SearchResults <ProvidersIndex> authorityResults = new SearchResults <ProvidersIndex> { Facets = new List <Facet> { new Facet { Name = authorityFacet, FacetValues = new List <FacetValue>() } } }; SearchResults <ProvidersIndex> providerVersionResults = new SearchResults <ProvidersIndex> { Facets = new List <Facet> { new Facet { Name = providerVersionIdFacet, FacetValues = new List <FacetValue>() } } }; ISearchRepository <ProvidersIndex> searchRepository = CreateSearchRepository(); searchRepository .Search(string.Empty, Arg.Is <SearchParameters>(x => x.Facets.Any(x => x.Contains(authorityFacet)))) .Returns(authorityResults); searchRepository .Search(string.Empty, Arg.Is <SearchParameters>(x => x.Facets.Any(x => x.Contains(providerVersionIdFacet)))) .Returns(providerVersionResults); searchRepository .Search(string.Empty, Arg.Is <SearchParameters>(x => x.Facets == null || !x.Facets.Any())) .Returns(new SearchResults <ProvidersIndex>()); CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(_ => _.ForFundingStreamId("fundingStreamId")); IProviderVersionsMetadataRepository providerVersionsMetadataRepository = CreateProviderVersionMetadataRepository(); providerVersionsMetadataRepository.GetCurrentProviderVersion(Arg.Any <string>()) .Returns(currentProviderVersion); IProviderVersionSearchService providerService = CreateProviderVersionSearchService(searchRepository: searchRepository, providerVersionMetadataRepository: providerVersionsMetadataRepository); // Act IActionResult notFoundRequest = await providerService.GetLocalAuthoritiesByFundingStreamId("fundingStreamId"); // Assert notFoundRequest .Should() .BeOfType <NotFoundResult>(); }