public void GetPublishedProviderResultByVersionId_GivenVersionFoundButResultCanbnotBeFound_ReturnsNull() { //Arrange string id = "id-1"; string entityId = "entity-id-1"; PublishedAllocationLineResultVersion version = new PublishedAllocationLineResultVersion { PublishedProviderResultId = entityId, FeedIndexId = id }; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultVersionForFeedIndexId(Arg.Is(id)) .Returns(version); publishedProviderResultsRepository .GetPublishedProviderResultForId(Arg.Is(entityId)) .Returns((PublishedProviderResult)null); PublishedResultsService publishedResultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act PublishedProviderResult result = publishedResultsService.GetPublishedProviderResultByVersionId(id); //Assert result .Should() .BeNull(); }
public async Task GetPublishedProviderResultWithHistoryByAllocationResultId_GivenResultFoundButNoHistory_ResturnsNull() { //Arrange string allocationResultId = "12345"; string query = $"select c from c where c.documentType = 'PublishedAllocationLineResultVersion' and c.deleted = false and c.content.entityId = '{allocationResultId}'"; PublishedProviderResult publishedProviderResult = new PublishedProviderResult { ProviderId = "1111" }; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); IVersionRepository <PublishedAllocationLineResultVersion> versionRepository = CreatePublishedProviderResultsVersionRepository(); versionRepository .GetVersions(Arg.Is(query), Arg.Is("1111")) .Returns((IEnumerable <PublishedAllocationLineResultVersion>)null); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository, publishedProviderResultsVersionRepository: versionRepository); //Act PublishedProviderResultWithHistory result = await service.GetPublishedProviderResultWithHistoryByAllocationResultId(allocationResultId); //Assert result .Should() .BeNull(); }
public async Task ReIndexAllocationNotificationFeeds_GivenNoPublishedProviderResultsFound_LogsWarning() { //Arrange Message message = new Message(); IEnumerable <PublishedProviderResult> results = Enumerable.Empty <PublishedProviderResult>(); IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(results); ILogger logger = CreateLogger(); PublishedResultsService resultsService = CreateResultsService(logger, publishedProviderResultsRepository: repository); //Act await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert logger .Received() .Warning(Arg.Is("No published provider results were found to index.")); logger .Received(1) .Information($"{nameof(resultsService.ReIndexAllocationNotificationFeeds)} initiated by: 'system'"); }
public async Task ReIndexAllocationNotificationFeeds_GivenMessageWithUserDetails_LogsInitiated() { //Arrange string userName = "******"; Message message = new Message(); message.UserProperties["user-id"] = "123"; message.UserProperties["user-name"] = userName; IEnumerable <PublishedProviderResult> results = Enumerable.Empty <PublishedProviderResult>(); IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(results); ILogger logger = CreateLogger(); PublishedResultsService resultsService = CreateResultsService(logger, publishedProviderResultsRepository: repository); //Act await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert logger .Received(1) .Information($"{nameof(resultsService.ReIndexAllocationNotificationFeeds)} initiated by: '{userName}'"); }
public async Task GetPublishedProviderResultsBySpecificationId_GivenNoProviderResultsFound_ReturnsEmptyList() { //arrange IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act IActionResult actionResult = await resultsService.GetPublishedProviderResultsBySpecificationId(request); //Assert actionResult .Should() .BeOfType <OkObjectResult>(); }
public void GetPublishedProviderResultVersionById_GivenVersionWasFound_ReturnsVersion() { //Arrange string feedIndexId = "id-1"; PublishedAllocationLineResultVersion publishedAllocationLineResultVersion = new PublishedAllocationLineResultVersion(); IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultVersionForFeedIndexId(Arg.Is(feedIndexId)) .Returns(publishedAllocationLineResultVersion); PublishedResultsService publishedResultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act PublishedAllocationLineResultVersion result = publishedResultsService.GetPublishedProviderResultVersionById(feedIndexId); //Assert result .Should() .NotBeNull(); result .Should() .Be(publishedAllocationLineResultVersion); }
public async Task GetPublishedProviderResultWithHistoryByAllocationResultId_GivenResultAndHistory_ResturnsResult() { //Arrange string allocationResultId = "12345"; PublishedProviderResult publishedProviderResult = new PublishedProviderResult { ProviderId = "1111", FundingStreamResult = new PublishedFundingStreamResult { AllocationLineResult = new PublishedAllocationLineResult { } } }; IEnumerable <PublishedAllocationLineResultVersion> history = new[] { new PublishedAllocationLineResultVersion(), new PublishedAllocationLineResultVersion(), new PublishedAllocationLineResultVersion() }; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); IVersionRepository <PublishedAllocationLineResultVersion> versionRepository = CreatePublishedProviderResultsVersionRepository(); versionRepository .GetVersions(Arg.Is(allocationResultId), Arg.Is("1111")) .Returns(history); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository, publishedProviderResultsVersionRepository: versionRepository); //Act PublishedProviderResultWithHistory result = await service.GetPublishedProviderResultWithHistoryByAllocationResultId(allocationResultId); //Assert result .Should() .NotBeNull(); result .PublishedProviderResult .Should() .NotBeNull(); result .History .Count() .Should() .Be(3); }
public async Task GetPublishedProviderResultByAllocationResultId_GivenVersionAndFoundInHistory_ReturnsResult() { //Arrange string allocationResultId = "12345"; int version = 5; PublishedProviderResult publishedProviderResult = new PublishedProviderResult { FundingStreamResult = new PublishedFundingStreamResult { AllocationLineResult = new PublishedAllocationLineResult { Current = new PublishedAllocationLineResultVersion { Version = 2 } } } }; PublishedAllocationLineResultVersion publishedAllocationLineResultVersion = new PublishedAllocationLineResultVersion { Version = 5 }; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); IVersionRepository <PublishedAllocationLineResultVersion> versionRepository = CreatePublishedProviderResultsVersionRepository(); versionRepository .GetVersion(Arg.Is(allocationResultId), Arg.Is(version)) .Returns(publishedAllocationLineResultVersion); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository, publishedProviderResultsVersionRepository: versionRepository); //Act PublishedProviderResult result = await service.GetPublishedProviderResultByAllocationResultId(allocationResultId, version); //Assert result .Should() .NotBeNull(); result .FundingStreamResult .AllocationLineResult .Current .Version .Should() .Be(5); }
public void GetPublishedProviderResultByVersionId_GivenResultFound_ReturnsResult() { //Arrange string id = "id-1"; string entityId = "entity-id-1"; PublishedAllocationLineResultVersion version = new PublishedAllocationLineResultVersion { PublishedProviderResultId = entityId, FeedIndexId = id }; PublishedProviderResult publishedProviderResult = new PublishedProviderResult { FundingStreamResult = new PublishedFundingStreamResult { AllocationLineResult = new PublishedAllocationLineResult() } }; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultVersionForFeedIndexId(Arg.Is(id)) .Returns(version); publishedProviderResultsRepository .GetPublishedProviderResultForId(Arg.Is(entityId)) .Returns(publishedProviderResult); PublishedResultsService publishedResultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act PublishedProviderResult result = publishedResultsService.GetPublishedProviderResultByVersionId(id); //Assert result .Should() .NotBeNull(); result .FundingStreamResult .AllocationLineResult .Current .Should() .Be(version); }
public async Task GetPublishedProviderResultsByFundingPeriodIdAndSpecificationIdAndFundingStreamId_GivenProviderResultsFound_ReturnsAllocationResultsOrderedByAllocationName() { // Arrange IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, { "fundingPeriodId", new StringValues(fundingPeriodId) }, { "fundingStreamId", new StringValues(fundingStreamId) }, }); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); IEnumerable <PublishedProviderResultByAllocationLineViewModel> publishedProviderResults = CreatePublishedProviderResultByAllocationLineViewModelWithMultipleAllocationLines(); IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultsSummaryByFundingPeriodIdAndSpecificationIdAndFundingStreamId(Arg.Is(fundingPeriodId), Arg.Is(specificationId), Arg.Is(fundingStreamId)) .Returns(publishedProviderResults); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); // Act IActionResult actionResult = await resultsService.GetPublishedProviderResultsByFundingPeriodIdAndSpecificationIdAndFundingStreamId(request); // Assert actionResult .Should() .BeOfType <OkObjectResult>(); OkObjectResult okObjectResult = actionResult as OkObjectResult; IEnumerable <PublishedProviderResultModel> publishedProviderResultModels = okObjectResult.Value as IEnumerable <PublishedProviderResultModel>; publishedProviderResultModels .Count() .Should() .Be(1); IEnumerable <string> allocationResultNames = publishedProviderResultModels.First().FundingStreamResults.First().AllocationLineResults.Select(r => r.AllocationLineName); allocationResultNames.Should().BeInAscendingOrder(); }
public async Task GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId_RepoReturnsEmpty_ReturnsNotFoundResult() { string providerId = "123"; string specificationId = "456"; string fundingStreamId = "789"; IPublishedProviderResultsRepository publishedProviderResultsRepository = Substitute.For <IPublishedProviderResultsRepository>(); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); IActionResult result = await service.GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId); await publishedProviderResultsRepository .Received(1) .GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId); result.Should().BeOfType <NotFoundResult>(); }
static PublishedResultsService CreateResultsService(ILogger logger = null, IMapper mapper = null, ITelemetry telemetry = null, ICalculationResultsRepository resultsRepository = null, ISpecificationsRepository specificationsRepository = null, IResultsResiliencePolicies resiliencePolicies = null, IPublishedProviderResultsAssemblerService publishedProviderResultsAssemblerService = null, IPublishedProviderResultsRepository publishedProviderResultsRepository = null, ICacheProvider cacheProvider = null, ISearchRepository <AllocationNotificationFeedIndex> allocationNotificationFeedSearchRepository = null, IProfilingApiClient profilingApiClient = null, IMessengerService messengerService = null, IVersionRepository <PublishedAllocationLineResultVersion> publishedProviderResultsVersionRepository = null, IPublishedAllocationLineLogicalResultVersionService publishedAllocationLineLogicalResultVersionService = null, IFeatureToggle featureToggle = null, IJobsApiClient jobsApiClient = null, IPublishedProviderResultsSettings publishedProviderResultsSettings = null, IProviderChangesRepository providerChangesRepository = null, IProviderVariationsService providerVariationsService = null, IProviderVariationsStorageRepository providerVariationsStorageRepository = null) { ISpecificationsRepository specsRepo = specificationsRepository ?? CreateSpecificationsRepository(); return(new PublishedResultsService( logger ?? CreateLogger(), mapper ?? CreateMapper(), telemetry ?? CreateTelemetry(), resultsRepository ?? CreateResultsRepository(), specsRepo, resiliencePolicies ?? ResultsResilienceTestHelper.GenerateTestPolicies(), publishedProviderResultsAssemblerService ?? CreateResultsAssembler(), publishedProviderResultsRepository ?? CreatePublishedProviderResultsRepository(), cacheProvider ?? CreateCacheProvider(), allocationNotificationFeedSearchRepository ?? CreateAllocationNotificationFeedSearchRepository(), profilingApiClient ?? CreateProfilingRepository(), messengerService ?? CreateMessengerService(), publishedProviderResultsVersionRepository ?? CreatePublishedProviderResultsVersionRepository(), publishedAllocationLineLogicalResultVersionService ?? CreatePublishedAllocationLineLogicalResultVersionService(), featureToggle ?? CreateFeatureToggle(), jobsApiClient ?? CreateJobsApiClient(), publishedProviderResultsSettings ?? CreatePublishedProviderResultsSettings(), providerChangesRepository ?? CreateProviderChangesRepository(), providerVariationsService ?? CreateProviderVariationsService(CreateProviderVariationAssemblerService(), specsRepo), providerVariationsStorageRepository ?? CreateProviderVariationsStorageRepository() )); }
public async Task ReIndexAllocationNotificationFeeds_GivenPublishedProviderFoundButAllHeld_DoesNotIndexReturnsContentResult() { //Arrange Message message = new Message(); IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(Enumerable.Empty <PublishedProviderResult>()); ILogger logger = CreateLogger(); ISearchRepository <AllocationNotificationFeedIndex> searchRepository = CreateAllocationNotificationFeedSearchRepository(); SpecificationCurrentVersion specification = CreateSpecification(specificationId); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); specificationsRepository .GetCurrentSpecificationById(Arg.Is("spec-1")) .Returns(specification); PublishedResultsService resultsService = CreateResultsService(logger, publishedProviderResultsRepository: repository, allocationNotificationFeedSearchRepository: searchRepository, specificationsRepository: specificationsRepository); //Act await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert await searchRepository .DidNotReceive() .Index(Arg.Any <IEnumerable <AllocationNotificationFeedIndex> >()); logger .Received(1) .Warning(Arg.Is("No published provider results were found to index.")); await repository .Received(0) .GetAllNonHeldPublishedProviderResultVersions(Arg.Any <string>(), Arg.Any <string>()); }
public async Task GetPublishedProviderResultByAllocationResultId_GivenVersionSuppliedButAlreadyCurrent_ReturnsResultDoesNotFetchHistory() { //Arrange string allocationResultId = "12345"; int version = 1; PublishedProviderResult publishedProviderResult = new PublishedProviderResult { FundingStreamResult = new PublishedFundingStreamResult { AllocationLineResult = new PublishedAllocationLineResult { Current = new PublishedAllocationLineResultVersion { Version = version } } } }; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); IVersionRepository <PublishedAllocationLineResultVersion> versionRepository = CreatePublishedProviderResultsVersionRepository(); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository, publishedProviderResultsVersionRepository: versionRepository); //Act PublishedProviderResult result = await service.GetPublishedProviderResultByAllocationResultId(allocationResultId, version); //Assert result .Should() .NotBeNull(); await versionRepository .DidNotReceive() .GetVersion(Arg.Any <string>(), Arg.Any <int>()); }
public async Task GetPublishedProviderResultWithHistoryByAllocationResultId_GivenResultNotFound_ResturnsNull() { //Arrange string allocationResultId = "12345"; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId)) .Returns((PublishedProviderResult)null); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act PublishedProviderResultWithHistory result = await service.GetPublishedProviderResultWithHistoryByAllocationResultId(allocationResultId); //Assert result .Should() .BeNull(); }
public void GetPublishedProviderResultByVersionId_GivenVersionCannotBeFound_ReturnsNull() { //Arrange string id = "id-1"; IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultVersionForFeedIndexId(Arg.Is(id)) .Returns((PublishedAllocationLineResultVersion)null); PublishedResultsService publishedResultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act PublishedProviderResult result = publishedResultsService.GetPublishedProviderResultByVersionId(id); //Assert result .Should() .BeNull(); }
public async Task GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId_ValidData_ReturnsData() { string providerId = "123"; string specificationId = "456"; string fundingStreamId = "789"; IPublishedProviderResultsRepository publishedProviderResultsRepository = Substitute.For <IPublishedProviderResultsRepository>(); IEnumerable <PublishedProviderProfileViewModel> returnData = new[] { new PublishedProviderProfileViewModel() }; publishedProviderResultsRepository .GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId) .Returns(returnData); PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); IActionResult result = await service.GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId); await publishedProviderResultsRepository .Received(1) .GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId); result.Should().BeOfType <OkObjectResult>(); (result as OkObjectResult).Value.Should().Be(returnData); }
public async Task GetPublishedProviderResultsBySpecificationId_GivenProviderResultsFound_ReturnsProviderResults() { //arrange IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); IEnumerable <Models.Results.PublishedProviderResultByAllocationLineViewModel> publishedProviderResults = CreatePublishedProviderResultByAllocationLineViewModel(); IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultSummaryForSpecificationId(Arg.Is(specificationId)) .Returns(publishedProviderResults); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act IActionResult actionResult = await resultsService.GetPublishedProviderResultsBySpecificationId(request); //Assert actionResult .Should() .BeOfType <OkObjectResult>(); OkObjectResult okObjectResult = actionResult as OkObjectResult; IEnumerable <PublishedProviderResultModel> publishedProviderResultModels = okObjectResult.Value as IEnumerable <PublishedProviderResultModel>; publishedProviderResultModels .Count() .Should() .Be(1); publishedProviderResultModels .First() .ProviderName .Should() .Be("test provider name 1"); publishedProviderResultModels .First() .ProviderId .Should() .Be("1111"); publishedProviderResultModels .First() .FundingStreamResults .Count() .Should() .Be(2); publishedProviderResultModels .First() .FundingStreamResults .First() .AllocationLineResults .Count() .Should() .Be(2); publishedProviderResultModels .First() .FundingStreamResults .Last() .AllocationLineResults .Count() .Should() .Be(1); }
public async Task ReIndexAllocationNotificationFeeds_GivenPublishedProviderFoundAndMajorMinorFeatureToggleIsEnabledAndIsAllAllocationResultsVersionsInFeedIndexEnabled_IndexesAndReturnsNoContentResult() { //Arrange int major = 2; int minor = 7; Message message = new Message(); const string specificationId = "spec-1"; IEnumerable <PublishedProviderResult> results = CreatePublishedProviderResultsWithDifferentProviders(); foreach (PublishedProviderResult result in results) { result.FundingStreamResult.AllocationLineResult.Current.Status = AllocationLineStatus.Approved; result.FundingStreamResult.AllocationLineResult.Current.ProfilingPeriods = new[] { new ProfilingPeriod() }; result.FundingStreamResult.AllocationLineResult.Current.Major = major; result.FundingStreamResult.AllocationLineResult.Current.Minor = minor; result.FundingStreamResult.AllocationLineResult.Current.FeedIndexId = "feed-index-id"; } IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(results); ILogger logger = CreateLogger(); IEnumerable <PublishedAllocationLineResultVersion> history = results.Select(m => m.FundingStreamResult.AllocationLineResult.Current); history.ElementAt(0).Status = AllocationLineStatus.Approved; foreach (var providerVersion in history.GroupBy(c => c.PublishedProviderResultId)) { if (providerVersion.Any()) { IEnumerable <PublishedAllocationLineResultVersion> providerHistory = providerVersion.AsEnumerable(); string providerId = providerHistory.First().ProviderId; providerId .Should() .NotBeNullOrWhiteSpace(); repository .GetAllNonHeldPublishedProviderResultVersions(Arg.Is(providerVersion.Key), Arg.Is(providerId)) .Returns(providerHistory); } } ISearchRepository <AllocationNotificationFeedIndex> searchRepository = CreateAllocationNotificationFeedSearchRepository(); SpecificationCurrentVersion specification = CreateSpecification(specificationId); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); specificationsRepository .GetCurrentSpecificationById(Arg.Is("spec-1")) .Returns(specification); IEnumerable <AllocationNotificationFeedIndex> resultsBeingSaved = null; await searchRepository.Index(Arg.Do <IEnumerable <AllocationNotificationFeedIndex> >(r => resultsBeingSaved = r)); PublishedResultsService resultsService = CreateResultsService( logger, publishedProviderResultsRepository: repository, allocationNotificationFeedSearchRepository: searchRepository, specificationsRepository: specificationsRepository); //Act await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert await searchRepository .Received(1) .Index(Arg.Is <IEnumerable <AllocationNotificationFeedIndex> >(m => m.Count() == 3)); AllocationNotificationFeedIndex feedResult = resultsBeingSaved.FirstOrDefault(m => m.ProviderId == "1111"); feedResult.ProviderId.Should().Be("1111"); feedResult.Title.Should().Be("Allocation test allocation line 1 was Approved"); feedResult.Summary.Should().Be($"UKPRN: 1111, version {major}.{minor}"); feedResult.DatePublished.HasValue.Should().Be(false); feedResult.FundingStreamId.Should().Be("fs-1"); feedResult.FundingStreamName.Should().Be("funding stream 1"); feedResult.FundingPeriodId.Should().Be("1819"); feedResult.ProviderUkPrn.Should().Be("1111"); feedResult.ProviderUpin.Should().Be("2222"); feedResult.AllocationLineId.Should().Be("AAAAA"); feedResult.AllocationLineName.Should().Be("test allocation line 1"); feedResult.AllocationVersionNumber.Should().Be(1); feedResult.AllocationAmount.Should().Be(50.0); feedResult.ProviderProfiling.Should().Be("[{\"period\":null,\"occurrence\":0,\"periodYear\":0,\"periodType\":null,\"profileValue\":0.0,\"distributionPeriod\":null}]"); feedResult.ProviderName.Should().Be("test provider name 1"); feedResult.LaCode.Should().Be("77777"); feedResult.Authority.Should().Be("London"); feedResult.ProviderType.Should().Be("test type"); feedResult.SubProviderType.Should().Be("test sub type"); feedResult.EstablishmentNumber.Should().Be("es123"); feedResult.FundingPeriodStartYear.Should().Be(DateTime.Now.Year); feedResult.FundingPeriodEndYear.Should().Be(DateTime.Now.Year + 1); feedResult.FundingStreamStartDay.Should().Be(1); feedResult.FundingStreamStartMonth.Should().Be(8); feedResult.FundingStreamEndDay.Should().Be(31); feedResult.FundingStreamEndMonth.Should().Be(7); feedResult.FundingStreamPeriodName.Should().Be("period-type 1"); feedResult.FundingStreamPeriodId.Should().Be("pt1"); feedResult.AllocationLineContractRequired.Should().Be(true); feedResult.AllocationLineFundingRoute.Should().Be("LA"); feedResult.MajorVersion.Should().Be(major); feedResult.MinorVersion.Should().Be(minor); }
public async Task GetConfirmationDetailsForApprovePublishProviderResults_GivenNoPublishedResultsReturns_ReturnsZeroResults() { //arrange IEnumerable <UpdatePublishedAllocationLineResultStatusProviderModel> Providers = new[] { new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "1234" } }; IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); UpdatePublishedAllocationLineResultStatusModel model = new UpdatePublishedAllocationLineResultStatusModel { Providers = Providers }; string json = JsonConvert.SerializeObject(model); byte[] byteArray = Encoding.UTF8.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); request .Body .Returns(stream); IPublishedProviderResultsRepository resultsProviderRepository = CreatePublishedProviderResultsRepository(); resultsProviderRepository .GetPublishedProviderResultsForSpecificationId(Arg.Is(specificationId)) .Returns(Enumerable.Empty <PublishedProviderResult>()); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: resultsProviderRepository); //Act IActionResult actionResult = await resultsService.GetConfirmationDetailsForApprovePublishProviderResults(request); //Arrange OkObjectResult okResult = actionResult .Should() .BeOfType <OkObjectResult>() .Subject; ConfirmPublishApproveModel x = okResult.Value.Should().BeAssignableTo <ConfirmPublishApproveModel>().Subject; x.NumberOfProviders.Should().Be(0, nameof(x.NumberOfProviders)); x.LocalAuthorities.Should().HaveCount(0, nameof(x.LocalAuthorities)); x.ProviderTypes.Should().HaveCount(0, nameof(x.ProviderTypes)); x.FundingPeriod.Should().BeNullOrEmpty("FundingPeriod should be blank"); x.FundingStreams.Should().BeEmpty(nameof(x.FundingStreams)); x.TotalFundingApproved.Should().Be(0, "TotalFundingApproved should be zero as there are no results"); }
public async Task GetConfirmationDetailsForApprovePublishProviderResults_GivenPublishedResultsReturnsSingluar_ReturnsOkAndResult() { // Arrange IEnumerable <UpdatePublishedAllocationLineResultStatusProviderModel> Providers = new[] { new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "1" } }; IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); UpdatePublishedAllocationLineResultStatusModel model = new UpdatePublishedAllocationLineResultStatusModel { Status = AllocationLineStatus.Held, Providers = Providers }; IEnumerable <PublishedProviderResult> publishedProviderResults = new List <PublishedProviderResult> { new PublishedProviderResult { FundingPeriod = new Models.Specs.Period { Name = "Period1" }, FundingStreamResult = new PublishedFundingStreamResult { FundingStream = new PublishedFundingStreamDefinition { Name = "Stream1" }, AllocationLineResult = new PublishedAllocationLineResult { AllocationLine = new PublishedAllocationLineDefinition { Name = "AllocLine1" }, Current = new PublishedAllocationLineResultVersion { Value = 12, Provider = new ProviderSummary { Id = "1", Authority = "Auth1", ProviderType = "PType1" } } } } } }; string json = JsonConvert.SerializeObject(model); byte[] byteArray = Encoding.UTF8.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); request .Body .Returns(stream); IPublishedProviderResultsRepository resultsProviderRepository = CreatePublishedProviderResultsRepository(); resultsProviderRepository .GetPublishedProviderResultsForSpecificationAndStatus(Arg.Is(specificationId), Arg.Any <UpdatePublishedAllocationLineResultStatusModel>()) .Returns(publishedProviderResults); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: resultsProviderRepository); // Act IActionResult actionResult = await resultsService.GetConfirmationDetailsForApprovePublishProviderResults(request); // Assert AssertConfirmPublishApproveModel(actionResult, publishedProviderResults.Count(), 1, 1, "Period1", 1, 12); }
public async Task GetPublishedProviderResultsByFundingPeriodIdAndSpecificationIdAndFundingStreamId_GivenProviderResultsFound_ReturnsProviderResults() { //arrange IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, { "fundingPeriodId", new StringValues(fundingPeriodId) }, { "fundingStreamId", new StringValues(fundingStreamId) }, }); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); IEnumerable <PublishedProviderResultByAllocationLineViewModel> publishedProviderResults = CreatePublishedProviderResultByAllocationLineViewModel(); IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository(); publishedProviderResultsRepository .GetPublishedProviderResultsSummaryByFundingPeriodIdAndSpecificationIdAndFundingStreamId(Arg.Is(fundingPeriodId), Arg.Is(specificationId), Arg.Is(fundingStreamId)) .Returns(publishedProviderResults); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository); //Act IActionResult actionResult = await resultsService.GetPublishedProviderResultsByFundingPeriodIdAndSpecificationIdAndFundingStreamId(request); //Assert OkObjectResult okObjectResult = actionResult .Should() .BeOfType <OkObjectResult>() .Subject; IEnumerable <PublishedProviderResultModel> publishedProviderResultModels = okObjectResult.Value .Should() .BeAssignableTo <IEnumerable <PublishedProviderResultModel> >() .Subject; publishedProviderResultModels .Should() .HaveCount(1, "there should be 1 results"); publishedProviderResultModels .First() .ProviderName .Should() .Be("test provider name 1"); publishedProviderResultModels .First() .ProviderId .Should() .Be("1111"); publishedProviderResultModels .First() .FundingStreamResults .Should() .HaveCount(2, "there should be 2 funding stream results"); publishedProviderResultModels .First() .FundingStreamResults .First(f => f.FundingStreamId == "fs-1") .AllocationLineResults .Should() .HaveCountLessOrEqualTo(2, "there should be 2 allocation line results for fs-1"); publishedProviderResultModels .First() .FundingStreamResults .First(f => f.FundingStreamId == "fs-2") .AllocationLineResults .Should() .HaveCountLessOrEqualTo(2, "there should be 1 allocation line results for fs-2"); }
public async Task GetConfirmationDetailsForApprovePublishProviderResults_GivenPublishedResultsReturnsMultiple_ReturnsOkAndAllocationLinesCoalesced() { // Arrange IEnumerable <UpdatePublishedAllocationLineResultStatusProviderModel> Providers = new[] { new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "1" }, new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "2" } }; IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); UpdatePublishedAllocationLineResultStatusModel model = new UpdatePublishedAllocationLineResultStatusModel { Status = AllocationLineStatus.Held, Providers = Providers }; IEnumerable <PublishedProviderResult> publishedProviderResults = new List <PublishedProviderResult> { new PublishedProviderResult { FundingPeriod = new Models.Specs.Period { Name = "Period1" }, FundingStreamResult = new PublishedFundingStreamResult { FundingStream = new PublishedFundingStreamDefinition { Name = "Stream1" }, AllocationLineResult = new PublishedAllocationLineResult { AllocationLine = new PublishedAllocationLineDefinition { Name = "AllocLine1" }, Current = new PublishedAllocationLineResultVersion { Value = 12, Provider = new ProviderSummary { Id = "1", Authority = "B Auth", ProviderType = "B PType" } } } } }, new PublishedProviderResult { FundingPeriod = new Models.Specs.Period { Name = "Period1" }, FundingStreamResult = new PublishedFundingStreamResult { FundingStream = new PublishedFundingStreamDefinition { Name = "Stream1" }, AllocationLineResult = new PublishedAllocationLineResult { AllocationLine = new PublishedAllocationLineDefinition { Name = "AllocLine1" }, Current = new PublishedAllocationLineResultVersion { Value = 15, Provider = new ProviderSummary { Id = "2", Authority = "A Auth", ProviderType = "A PType" } } } } } }; string json = JsonConvert.SerializeObject(model); byte[] byteArray = Encoding.UTF8.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); request .Body .Returns(stream); IPublishedProviderResultsRepository resultsProviderRepository = CreatePublishedProviderResultsRepository(); resultsProviderRepository .GetPublishedProviderResultsForSpecificationAndStatus(Arg.Is(specificationId), Arg.Any <UpdatePublishedAllocationLineResultStatusModel>()) .Returns(publishedProviderResults); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: resultsProviderRepository); // Act IActionResult actionResult = await resultsService.GetConfirmationDetailsForApprovePublishProviderResults(request); // Assert OkObjectResult okResult = actionResult.Should().BeOfType <OkObjectResult>().Subject; ConfirmPublishApproveModel confDetalis = okResult.Value.Should().BeAssignableTo <ConfirmPublishApproveModel>().Subject; confDetalis.FundingStreams.Should().HaveCount(1, "Funding Stream"); confDetalis.FundingStreams.First().AllocationLines.Should().HaveCount(1, "Allocation Lines"); }
public async Task ReIndexAllocationNotificationFeeds_GivenResultHasProviderDataChange_AndHasNotBeenVariedInAnyOtherWay_IndexesAndReturnsNoContentResult() { //Arrange Message message = new Message(); const string specificationId = "spec-1"; IEnumerable <PublishedProviderResult> results = CreatePublishedProviderResultsWithDifferentProviders(); foreach (PublishedProviderResult result in results) { result.FundingStreamResult.AllocationLineResult.Current.Status = AllocationLineStatus.Approved; result.FundingStreamResult.AllocationLineResult.Current.ProfilingPeriods = new[] { new ProfilingPeriod() }; result.FundingStreamResult.AllocationLineResult.Current.FinancialEnvelopes = new[] { new FinancialEnvelope() }; result.FundingStreamResult.AllocationLineResult.Current.Calculations = new[] { new PublishedProviderCalculationResult { CalculationSpecification = new Common.Models.Reference("calc-id-1", "calc1"), Policy = new PolicySummary("policy-id-1", "policy1", "desc") }, new PublishedProviderCalculationResult { CalculationSpecification = new Common.Models.Reference("calc-id-2", "calc2"), Policy = new PolicySummary("policy-id-1", "policy1", "desc") }, new PublishedProviderCalculationResult { CalculationSpecification = new Common.Models.Reference("calc-id-3", "calc3"), Policy = new PolicySummary("policy-id-2", "policy2", "desc") }, }; } PublishedAllocationLineResult publishedAllocationLineResult = results.First().FundingStreamResult.AllocationLineResult; publishedAllocationLineResult.HasResultBeenVaried = false; publishedAllocationLineResult.Current.VariationReasons = new[] { VariationReason.AuthorityFieldUpdated, VariationReason.NameFieldUpdated }; IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(results); IEnumerable <PublishedAllocationLineResultVersion> history = results.Select(m => m.FundingStreamResult.AllocationLineResult.Current); history.ElementAt(0).Status = AllocationLineStatus.Approved; history.ElementAt(1).Status = AllocationLineStatus.Approved; history.ElementAt(2).Status = AllocationLineStatus.Published; foreach (var providerVersion in history.GroupBy(c => c.PublishedProviderResultId)) { if (providerVersion.Any()) { IEnumerable <PublishedAllocationLineResultVersion> providerHistory = providerVersion.AsEnumerable(); string providerId = providerHistory.First().ProviderId; providerId .Should() .NotBeNullOrWhiteSpace(); repository .GetAllNonHeldPublishedProviderResultVersions(Arg.Is(providerVersion.Key), Arg.Is(providerId)) .Returns(providerHistory); } } ILogger logger = CreateLogger(); ISearchRepository <AllocationNotificationFeedIndex> searchRepository = CreateAllocationNotificationFeedSearchRepository(); SpecificationCurrentVersion specification = CreateSpecification(specificationId); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); specificationsRepository .GetCurrentSpecificationById(Arg.Is(specificationId)) .Returns(specification); IEnumerable <AllocationNotificationFeedIndex> resultsBeingSaved = null; await searchRepository .Index(Arg.Do <IEnumerable <AllocationNotificationFeedIndex> >(r => resultsBeingSaved = r)); PublishedResultsService resultsService = CreateResultsService( logger, publishedProviderResultsRepository: repository, allocationNotificationFeedSearchRepository: searchRepository, specificationsRepository: specificationsRepository); //Act await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert await searchRepository .Received(1) .Index(Arg.Is <IEnumerable <AllocationNotificationFeedIndex> >(m => m.Count() == 3)); AllocationNotificationFeedIndex feedResult = resultsBeingSaved.FirstOrDefault(m => m.ProviderId == "1111"); feedResult.ProviderId.Should().Be("1111"); feedResult.Title.Should().Be("Allocation test allocation line 1 was Approved"); feedResult.Summary.Should().Be("UKPRN: 1111, version 0.1"); feedResult.DatePublished.HasValue.Should().Be(false); feedResult.FundingStreamId.Should().Be("fs-1"); feedResult.FundingStreamName.Should().Be("funding stream 1"); feedResult.FundingPeriodId.Should().Be("1819"); feedResult.ProviderUkPrn.Should().Be("1111"); feedResult.ProviderUpin.Should().Be("2222"); feedResult.AllocationLineId.Should().Be("AAAAA"); feedResult.AllocationLineName.Should().Be("test allocation line 1"); feedResult.AllocationVersionNumber.Should().Be(1); feedResult.AllocationAmount.Should().Be(50.0); feedResult.ProviderProfiling.Should().Be("[{\"period\":null,\"occurrence\":0,\"periodYear\":0,\"periodType\":null,\"profileValue\":0.0,\"distributionPeriod\":null}]"); feedResult.ProviderName.Should().Be("test provider name 1"); feedResult.LaCode.Should().Be("77777"); feedResult.Authority.Should().Be("London"); feedResult.ProviderType.Should().Be("test type"); feedResult.SubProviderType.Should().Be("test sub type"); feedResult.EstablishmentNumber.Should().Be("es123"); feedResult.FundingPeriodStartYear.Should().Be(DateTime.Now.Year); feedResult.FundingPeriodEndYear.Should().Be(DateTime.Now.Year + 1); feedResult.FundingStreamStartDay.Should().Be(1); feedResult.FundingStreamStartMonth.Should().Be(8); feedResult.FundingStreamEndDay.Should().Be(31); feedResult.FundingStreamEndMonth.Should().Be(7); feedResult.FundingStreamPeriodName.Should().Be("period-type 1"); feedResult.FundingStreamPeriodId.Should().Be("pt1"); feedResult.AllocationLineContractRequired.Should().Be(true); feedResult.AllocationLineFundingRoute.Should().Be("LA"); feedResult.AllocationLineShortName.Should().Be("tal1"); feedResult.PolicySummaries.Should().Be("[{\"policy\":{\"description\":\"test decscription\",\"parentPolicyId\":null,\"id\":\"policy-1\",\"name\":\"policy one\"},\"policies\":[{\"policy\":{\"description\":\"test decscription\",\"parentPolicyId\":null,\"id\":\"subpolicy-1\",\"name\":\"sub policy one\"},\"policies\":[],\"calculations\":[]}],\"calculations\":[]}]"); feedResult.Calculations.Should().Be("[{\"calculationName\":\"calc1\",\"calculationDisplayName\":\"calc1\",\"calculationVersion\":0,\"calculationType\":\"Number\",\"calculationAmount\":null,\"allocationLineId\":\"AAAAA\",\"policyId\":\"policy-id-1\",\"policyName\":\"policy1\"},{\"calculationName\":\"calc2\",\"calculationDisplayName\":\"calc2\",\"calculationVersion\":0,\"calculationType\":\"Number\",\"calculationAmount\":null,\"allocationLineId\":\"AAAAA\",\"policyId\":\"policy-id-1\",\"policyName\":\"policy1\"},{\"calculationName\":\"calc3\",\"calculationDisplayName\":\"calc3\",\"calculationVersion\":0,\"calculationType\":\"Number\",\"calculationAmount\":null,\"allocationLineId\":\"AAAAA\",\"policyId\":\"policy-id-2\",\"policyName\":\"policy2\"}]"); feedResult.OpenReason.Should().BeNull(); feedResult.CloseReason.Should().BeNull(); feedResult.Predecessors.Should().BeNull(); feedResult.Successors.Should().BeNull(); }
public async Task ReIndexAllocationNotificationFeeds_GivenPublishedProviderFoundButUpdatingIndexThrowsException_ReturnsInternalServerError() { //Arrange Message message = new Message(); IEnumerable <PublishedProviderResult> results = CreatePublishedProviderResultsWithDifferentProviders(); foreach (PublishedProviderResult result in results) { result.FundingStreamResult.AllocationLineResult.Current.Status = AllocationLineStatus.Approved; result.FundingStreamResult.AllocationLineResult.Current.ProfilingPeriods = new[] { new ProfilingPeriod() }; } IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(results); IEnumerable <PublishedAllocationLineResultVersion> history = CreatePublishedProviderResultsWithDifferentProviders() .Select(m => m.FundingStreamResult.AllocationLineResult.Current); history.ElementAt(1).Status = AllocationLineStatus.Approved; history.ElementAt(1).Status = AllocationLineStatus.Published; foreach (var providerVersion in history.GroupBy(c => c.PublishedProviderResultId)) { if (providerVersion.Any()) { IEnumerable <PublishedAllocationLineResultVersion> providerHistory = providerVersion.AsEnumerable(); string providerId = providerHistory.First().ProviderId; providerId .Should() .NotBeNullOrWhiteSpace(); repository .GetAllNonHeldPublishedProviderResultVersions(Arg.Is(providerVersion.Key), Arg.Is(providerId)) .Returns(providerHistory); } } ILogger logger = CreateLogger(); ISearchRepository <AllocationNotificationFeedIndex> searchRepository = CreateAllocationNotificationFeedSearchRepository(); searchRepository.When(x => x.Index(Arg.Any <IEnumerable <AllocationNotificationFeedIndex> >())) .Do(x => { throw new Exception("Error indexing"); }); SpecificationCurrentVersion specification = CreateSpecification("spec-1"); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); specificationsRepository .GetCurrentSpecificationById(Arg.Is("spec-1")) .Returns(specification); PublishedResultsService resultsService = CreateResultsService( logger, publishedProviderResultsRepository: repository, allocationNotificationFeedSearchRepository: searchRepository, specificationsRepository: specificationsRepository); //Act Func <Task> test = async() => await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert test .Should() .ThrowExactly <RetriableException>(); logger .Received() .Error(Arg.Any <Exception>(), Arg.Is("Failed to index allocation feeds")); await repository .Received(3) .GetAllNonHeldPublishedProviderResultVersions(Arg.Any <string>(), Arg.Any <string>()); }