public async Task GetCurrentProviderMetadataForAllFundingStreams_FetchesTheMetadataForAllCurrentProviderVersions() { string fundingStreamId1 = NewRandomString(); string providerVersionId1 = NewRandomString(); int? providerSnapshotId1 = NewRandomNumber(); CurrentProviderVersion currentProviderVersion1 = NewCurrentProviderVersion(_ => _.ForFundingStreamId(fundingStreamId1) .WithProviderVersionId(providerVersionId1) .WithProviderSnapshotId(providerSnapshotId1)); string fundingStreamId2 = NewRandomString(); string providerVersionId2 = NewRandomString(); int? providerSnapshotId2 = NewRandomNumber(); CurrentProviderVersion currentProviderVersion2 = NewCurrentProviderVersion(_ => _.ForFundingStreamId(fundingStreamId2) .WithProviderVersionId(providerVersionId2) .WithProviderSnapshotId(providerSnapshotId2)); CurrentProviderVersionMetadata expectedMetadata1 = _mapper.Map <CurrentProviderVersionMetadata>(currentProviderVersion1); CurrentProviderVersionMetadata expectedMetadata2 = _mapper.Map <CurrentProviderVersionMetadata>(currentProviderVersion2); GivenAllCurrentProviderVersions(currentProviderVersion1, currentProviderVersion2); IActionResult result = await WhenGetCurrentProviderMetadataForAllFundingStreams(); IEnumerable <CurrentProviderVersionMetadata> actualMetadata = result .Should() .BeOfType <OkObjectResult>() .Which .Value.As <IEnumerable <CurrentProviderVersionMetadata> >(); actualMetadata.Count().Should().Be(2); actualMetadata.Single(x => x.FundingStreamId == fundingStreamId1) .Should().BeEquivalentTo(expectedMetadata1); actualMetadata.Single(x => x.FundingStreamId == fundingStreamId2) .Should().BeEquivalentTo(expectedMetadata2); }
public void SholdMapCurrentProviderVersionToCurrentProviderVersionMetadata() { // Arrange string fundingStreamId = NewRandomString(); CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(_ => _.ForFundingStreamId(fundingStreamId)); MapperConfiguration config = new MapperConfiguration(c => c.AddProfile <ProviderVersionsMappingProfile>()); IMapper mapper = config.CreateMapper(); // Act CurrentProviderVersionMetadata metadata = mapper.Map <CurrentProviderVersionMetadata>(currentProviderVersion); // Assert metadata .FundingStreamId .Should() .Be(fundingStreamId); metadata .ProviderVersionId .Should() .Be(currentProviderVersion.ProviderVersionId); metadata .ProviderSnapshotId .Should() .Be(currentProviderVersion.ProviderSnapshotId); }
public async Task UpsertCurrentProviderVersionDelegatesToCosmos() { CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(); HttpStatusCode expectedStatusCode = NewRandomStatusCode(); GivenTheCosmosStatusCodeForTheUpsert(currentProviderVersion, expectedStatusCode); HttpStatusCode actualStatusCode = await WhenTheCurrentProviderVersionIsUpserted(currentProviderVersion); actualStatusCode .Should() .Be(expectedStatusCode); }
public async Task <IActionResult> GetLocalAuthoritiesByFundingStreamId(string fundingStreamId) { CurrentProviderVersion currentProviderVersion = await GetCurrentProviderVersion(fundingStreamId); if (currentProviderVersion == null) { _logger.Error("Unable to search current provider for funding stream. " + $"No current provider version information located for {fundingStreamId}"); return(new NotFoundResult()); } return(await GetLocalAuthoritiesByProviderVersionId(currentProviderVersion.ProviderVersionId)); }
public async Task GetCurrentProvidersForFundingStream_FetchesAllProvidersForTheCurrentProviderVersion() { string fundingStreamId = NewRandomString(); string providerVersionId = NewRandomString(); CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(_ => _.WithProviderVersionId(providerVersionId)); IActionResult expectedAllProvidersResults = NewActionResult(); GivenTheCurrentProviderVersionForFundingStream(fundingStreamId, currentProviderVersion); AndTheProvidersResponseForTheProviderVersion(providerVersionId, expectedAllProvidersResults); IActionResult result = await WhenTheCurrentFundingStreamProvidersAreQueried(fundingStreamId); result .Should() .BeSameAs(expectedAllProvidersResults); }
public async Task <IActionResult> GetCurrentProvidersForFundingStream(string fundingStreamId) { Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId)); CurrentProviderVersion currentProviderVersion = await GetCurrentProviderVersion(fundingStreamId); if (currentProviderVersion == null) { LogError("Unable to get all current providers for funding stream. " + $"No current provider version information located for {fundingStreamId}"); return(new NotFoundResult()); } return(await _providerVersionService.GetAllProviders(currentProviderVersion.ProviderVersionId)); }
public async Task SearchCurrentProviderVersionsForFundingStream_SearchesInTheCurrentProviderVersion() { string fundingStreamId = NewRandomString(); string providerVersionId = NewRandomString(); SearchModel search = new SearchModel(); CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(_ => _.WithProviderVersionId(providerVersionId)); IActionResult expectedSearchResult = NewActionResult(); GivenTheCurrentProviderVersionForFundingStream(fundingStreamId, currentProviderVersion); AndTheSearchResponseForTheProviderVersionId(providerVersionId, search, expectedSearchResult); IActionResult result = await WhenTheCurrentProviderVersionForFundingStreamIsSearched(fundingStreamId, search); result .Should() .BeSameAs(expectedSearchResult); }
public async Task <IActionResult> GetCurrentProviderMetadataForFundingStream(string fundingStreamId) { Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId)); CurrentProviderVersion currentProviderVersion = await GetCurrentProviderVersion(fundingStreamId); if (currentProviderVersion == null) { LogError("Unable to get the current provider for funding stream. " + $"No current provider version information located for {fundingStreamId}"); return(new NotFoundResult()); } CurrentProviderVersionMetadata metadata = _mapper.Map <CurrentProviderVersionMetadata>(currentProviderVersion); return(new OkObjectResult(metadata)); }
public async Task <IActionResult> SearchCurrentProviderVersionsForFundingStream(string fundingStreamId, SearchModel search) { Guard.ArgumentNotNull(search, nameof(search)); Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId)); CurrentProviderVersion currentProviderVersion = await GetCurrentProviderVersion(fundingStreamId); if (currentProviderVersion == null) { LogError("Unable to search current provider for funding stream. " + $"No current provider version information located for {fundingStreamId}"); return(new NotFoundResult()); } return(await _providerVersionSearchPolicy.ExecuteAsync(() => _providerVersionSearch.SearchProviders(currentProviderVersion.ProviderVersionId, search))); }
public async Task <IActionResult> GetCurrentProviderForFundingStream(string fundingStreamId, string providerId) { Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId)); Guard.IsNullOrWhiteSpace(providerId, nameof(providerId)); CurrentProviderVersion currentProviderVersion = await GetCurrentProviderVersion(fundingStreamId); if (currentProviderVersion == null) { LogError("Unable to get current provider for funding stream. " + $"No current provider version information located for {fundingStreamId}"); return(new NotFoundResult()); } return(await _providerVersionSearchPolicy.ExecuteAsync(() => _providerVersionSearch.GetProviderById(currentProviderVersion.ProviderVersionId, providerId))); }
public async Task GetCurrentProviderVersionMatchesByTheFundingStreamId() { string fundingStreamId = NewRandomString(); CurrentProviderVersion currentProviderVersionOne = NewCurrentProviderVersion(); CurrentProviderVersion currentProviderVersionTwo = NewCurrentProviderVersion(); CurrentProviderVersion currentProviderVersionThree = NewCurrentProviderVersion(_ => _.ForFundingStreamId(fundingStreamId)); CurrentProviderVersion currentProviderVersionFour = NewCurrentProviderVersion(); GivenTheCosmosContents(currentProviderVersionOne, currentProviderVersionTwo, currentProviderVersionThree, currentProviderVersionFour); CurrentProviderVersion actualCurrentProviderVersion = await WhenTheCurrentProviderVersionIsQueried(fundingStreamId); actualCurrentProviderVersion .Should() .BeSameAs(currentProviderVersionThree); }
public async Task GetCurrentProviderMetadataForFundingStream_FetchesTheMetadataForCurrentProviderVersion() { string fundingStreamId = NewRandomString(); string providerVersionId = NewRandomString(); int? providerSnapshotId = NewRandomNumber(); CurrentProviderVersion currentProviderVersion = NewCurrentProviderVersion(_ => _.ForFundingStreamId(fundingStreamId) .WithProviderVersionId(providerVersionId) .WithProviderSnapshotId(providerSnapshotId)); GivenTheCurrentProviderVersionForFundingStream(fundingStreamId, currentProviderVersion); IActionResult result = await WhenGetCurrentProviderMetadataForFundingStream(fundingStreamId); CurrentProviderVersionMetadata actualMetadata = result .Should() .BeOfType <OkObjectResult>() .Which .Value.As <CurrentProviderVersionMetadata>(); actualMetadata.FundingStreamId.Should().Be(fundingStreamId); actualMetadata.ProviderVersionId.Should().Be(providerVersionId); actualMetadata.ProviderSnapshotId.Should().Be(providerSnapshotId); }
private void GivenTheCurrentProviderVersionForFundingStream(string fundingStreamId, CurrentProviderVersion currentProviderVersion) { _providerVersionsMetadata.Setup(_ => _.GetCurrentProviderVersion(fundingStreamId)) .ReturnsAsync(currentProviderVersion); }
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>(); }
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 <HttpStatusCode> WhenTheCurrentProviderVersionIsUpserted(CurrentProviderVersion currentProviderVersion) => await _repository.UpsertCurrentProviderVersion(currentProviderVersion);
public async Task <HttpStatusCode> UpsertCurrentProviderVersion(CurrentProviderVersion currentProviderVersion) { Guard.ArgumentNotNull(currentProviderVersion, nameof(currentProviderVersion)); return(await _cosmos.UpsertAsync(currentProviderVersion)); }