public async Task SaveProviderResults_WhenNoResults_ThenNoResultsSaved() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); ISearchRepository <CalculationProviderResultsIndex> searchRepository = CreateCalculationProviderResultsSearchRepository(); ProviderResultsRepository repo = CreateProviderResultsRepository(cosmosRepository, searchRepository); IEnumerable <ProviderResult> results = Enumerable.Empty <ProviderResult>(); // Act await repo.SaveProviderResults(results); // Assert await cosmosRepository.DidNotReceive().BulkCreateAsync(Arg.Any <IEnumerable <KeyValuePair <string, ProviderResult> > >()); await searchRepository.DidNotReceive().Index(Arg.Any <IList <CalculationProviderResultsIndex> >()); }
public async Task SaveProviderResults_WhenResults_ThenResultsSavedToCosmos() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); ProviderResultsRepository repo = CreateProviderResultsRepository(cosmosRepository); SpecificationSummary specificationSummary = new SpecificationSummary { Name = "Specification 1", FundingPeriod = new Reference() }; IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { CalculationResults = new List <CalculationResult> { new CalculationResult { Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = Models.Calcs.CalculationType.Template, Value = 1112.3M } }, FundingLineResults = new List <FundingLineResult> { new FundingLineResult { FundingLine = new Reference { Id = "fl1", Name = "funding line one" }, FundingLineFundingStreamId = "FS1", Value = 112.3M } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results, specificationSummary, 1, 1, _user, _correlationId, _jobId); // Assert await cosmosRepository.Received(1).UpsertAsync <ProviderResult>( Arg.Any <ProviderResult>(), Arg.Any <string>(), Arg.Is <bool>(false), Arg.Is <bool>(false)); }
public async Task SaveProviderResults_WhenExcludedResultsAndIsNewProviderCalculationResultsIndexEnabled_ThenResultsSavedToCosmosSavesNull() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); IJobManagement jobManagement = CreateJobManagement(); ProviderResultsRepository repo = CreateProviderResultsRepository( cosmosRepository, jobManagement: jobManagement); SpecificationSummary specificationSummary = new SpecificationSummary { Name = "Specification 1", FundingPeriod = new Reference() }; IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { CalculationResults = new List <CalculationResult> { new CalculationResult { Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = Models.Calcs.CalculationType.Template, Value = null } }, FundingLineResults = new List <FundingLineResult> { new FundingLineResult { FundingLine = new Reference { Id = "fl1", Name = "funding line one" }, FundingLineFundingStreamId = "FS1", Value = null } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results, specificationSummary, 1, 1, _user, _correlationId, _jobId); // Assert await cosmosRepository.Received(1).UpsertAsync <ProviderResult>( Arg.Any <ProviderResult>(), Arg.Any <string>(), Arg.Is <bool>(false), Arg.Is <bool>(false)); await jobManagement.Received(1).QueueJob(Arg.Is <JobCreateModel>(_ => _.JobDefinitionId == JobConstants.DefinitionNames.SearchIndexWriterJob && _.ParentJobId == _jobId && _.Properties["specification-id"] == specificationSummary.GetSpecificationId() && _.Properties["specification-name"] == specificationSummary.Name && _.Properties["index-writer-type"] == SearchIndexWriterTypes.ProviderCalculationResultsIndexWriter && _.MessageBody == JsonConvert.SerializeObject(results.Select(x => x.Provider.Id)))); }
public async Task SaveProviderResults_WhenResultsAndIsNewProviderCalculationResultsIndexEnabled_ThenQueueSearchIndexWriterJob() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); IJobManagement jobManagement = CreateJobManagement(); ProviderResultsRepository repo = CreateProviderResultsRepository( cosmosRepository, jobManagement: jobManagement); SpecificationSummary specificationSummary = new SpecificationSummary { Id = NewRandomString(), Name = NewRandomString(), FundingPeriod = new Reference { Id = NewRandomString() }, LastEditedDate = new RandomDateTime(), FundingStreams = new[] { new Reference { Id = NewRandomString() }, new Reference { Id = NewRandomString() }, new Reference { Id = NewRandomString() } } }; IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { CalculationResults = new List <CalculationResult> { new CalculationResult { Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = CalculationType.Template, Value = 1112.3M } }, FundingLineResults = new List <FundingLineResult> { new FundingLineResult { FundingLine = new Reference { Id = "fl1", Name = "funding line one" }, FundingLineFundingStreamId = "FS1", Value = 112.3M } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results, specificationSummary, 1, 1, _user, _correlationId, _jobId); // Assert await jobManagement.Received(1).QueueJob(Arg.Is <JobCreateModel>(_ => _.JobDefinitionId == JobConstants.DefinitionNames.SearchIndexWriterJob && _.Properties["specification-id"] == specificationSummary.GetSpecificationId() && _.Properties["specification-name"] == specificationSummary.Name && _.Properties["index-writer-type"] == SearchIndexWriterTypes.ProviderCalculationResultsIndexWriter && _.ParentJobId == _jobId && _.MessageBody == JsonConvert.SerializeObject(results.Select(x => x.Provider.Id)))); await _resultsApiClient.Received(1) .QueueMergeSpecificationInformationJob(Arg.Is <MergeSpecificationInformationRequest>(_ => _.SpecificationInformation.Id == specificationSummary.Id && _.SpecificationInformation.Name == specificationSummary.Name && _.SpecificationInformation.LastEditDate == specificationSummary.LastEditedDate && _.SpecificationInformation.FundingStreamIds.SequenceEqual(specificationSummary.FundingStreams.Select(fs => fs.Id).ToArray()) && _.SpecificationInformation.FundingPeriodId == specificationSummary.FundingPeriod.Id && _.ProviderIds.SequenceEqual(new[] { "prov1" }))); }
public async Task SaveProviderResults_WhenExcludedResultsButResultsNotChanged_ThenResultsNotSavedToCosmos() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); IProviderResultCalculationsHashProvider hashProvider = Substitute.For <IProviderResultCalculationsHashProvider>(); ProviderResultsRepository repo = CreateProviderResultsRepository(cosmosRepository, calculationsHashProvider: hashProvider); SpecificationSummary specificationSummary = new SpecificationSummary { Id = NewRandomString(), Name = NewRandomString(), FundingPeriod = new Reference { Id = NewRandomString() }, LastEditedDate = new RandomDateTime() }; IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { CalculationResults = new List <CalculationResult> { new CalculationResult { Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = CalculationType.Template, Value = null } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results, specificationSummary, 1, 1, _user, _correlationId, _jobId); // Assert await cosmosRepository.Received(0).BulkUpsertAsync(Arg.Is <IEnumerable <KeyValuePair <string, ProviderResult> > >(r => r.Count() == 1), Arg.Any <int>(), Arg.Any <bool>(), Arg.Is <bool>(false)); }
public async Task SaveProviderResults_WhenExcludedResultsAndIsNewProviderCalculationResultsIndexEnabled_ThenResultsSavedToCosmosSavesNull() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); ISearchRepository <ProviderCalculationResultsIndex> searchRepository = CreateProviderCalculationResultsSearchRepository(); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); IFeatureToggle featureToggle = CreateFeatureToggle(); featureToggle .IsNewProviderCalculationResultsIndexEnabled() .Returns(true); ProviderResultsRepository repo = CreateProviderResultsRepository(cosmosRepository, specificationsRepository: specificationsRepository, providerCalculationResultsSearchRepository: searchRepository, featureToggle: featureToggle); specificationsRepository.GetSpecificationSummaryById(Arg.Any <string>()).Returns(new SpecificationSummary { Name = "Specification 1" }); IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { AllocationLineResults = new List <AllocationLineResult> { new AllocationLineResult { AllocationLine = new Reference { Id = "alloc 1", Name = "Allocation one" }, Value = 1112.3M } }, CalculationResults = new List <CalculationResult> { new CalculationResult { AllocationLine = new Reference { Id = "alloc1", Name = "Allocation one" }, Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationSpecification = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = Models.Calcs.CalculationType.Funding, Value = null } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results); // Assert await cosmosRepository.Received().BulkUpsertAsync(Arg.Is <IEnumerable <KeyValuePair <string, ProviderResult> > >(r => r.Count() == 1), Arg.Any <int>(), Arg.Any <bool>(), Arg.Is <bool>(false)); await searchRepository.Received(1).Index(Arg.Is <IEnumerable <ProviderCalculationResultsIndex> >(r => r.First().SpecificationId == results.First().SpecificationId&& r.First().SpecificationName == "Specification 1" && r.First().CalculationId.Any() && r.First().CalculationId.First() == results.First().CalculationResults.First().Calculation.Id&& r.First().CalculationName.Any() && r.First().CalculationName.First() == results.First().CalculationResults.First().Calculation.Name&& r.First().ProviderId == results.First().Provider.Id&& r.First().ProviderName == results.First().Provider.Name&& r.First().ProviderType == results.First().Provider.ProviderType&& r.First().ProviderSubType == results.First().Provider.ProviderSubType&& r.First().LocalAuthority == results.First().Provider.Authority&& r.First().UKPRN == results.First().Provider.UKPRN&& r.First().URN == results.First().Provider.URN&& r.First().UPIN == results.First().Provider.UPIN&& r.First().EstablishmentNumber == results.First().Provider.EstablishmentNumber&& r.First().OpenDate == results.First().Provider.DateOpened&& r.First().CalculationResult.Any() && r.First().CalculationResult.First() == "null")); }
public async Task SaveProviderResults_WhenResults_ThenResultsSavedToCosmos() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); ISearchRepository <CalculationProviderResultsIndex> searchRepository = CreateCalculationProviderResultsSearchRepository(); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); ProviderResultsRepository repo = CreateProviderResultsRepository(cosmosRepository, searchRepository, specificationsRepository); specificationsRepository.GetSpecificationSummaryById(Arg.Any <string>()).Returns(new SpecificationSummary { Name = "Specification 1" }); IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { AllocationLineResults = new List <AllocationLineResult> { new AllocationLineResult { AllocationLine = new Reference { Id = "alloc 1", Name = "Allocation one" }, Value = 1112.3M } }, CalculationResults = new List <CalculationResult> { new CalculationResult { AllocationLine = new Reference { Id = "alloc1", Name = "Allocation one" }, Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationSpecification = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = Models.Calcs.CalculationType.Funding, Value = 1112.3M } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results); // Assert await cosmosRepository.Received().BulkUpsertAsync(Arg.Is <IEnumerable <KeyValuePair <string, ProviderResult> > >(r => r.Count() == 1), Arg.Any <int>(), Arg.Any <bool>(), Arg.Is <bool>(false)); }
public async Task SaveProviderResults_WhenResults_ThenResultsSavedToSearch() { // Arrange ICosmosRepository cosmosRepository = CreateCosmosRepository(); ISearchRepository <CalculationProviderResultsIndex> searchRepository = CreateCalculationProviderResultsSearchRepository(); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); ProviderResultsRepository repo = CreateProviderResultsRepository(cosmosRepository, searchRepository, specificationsRepository); specificationsRepository.GetSpecificationSummaryById(Arg.Any <string>()).Returns(new SpecificationSummary { Name = "Specification 1" }); IEnumerable <ProviderResult> results = new List <ProviderResult> { new ProviderResult { AllocationLineResults = new List <AllocationLineResult> { new AllocationLineResult { AllocationLine = new Reference { Id = "alloc 1", Name = "Allocation one" }, Value = 1112.3M } }, CalculationResults = new List <CalculationResult> { new CalculationResult { AllocationLine = new Reference { Id = "alloc1", Name = "Allocation one" }, Calculation = new Reference { Id = "calc1", Name = "calculation one" }, CalculationSpecification = new Reference { Id = "calc1", Name = "calculation one" }, CalculationType = Models.Calcs.CalculationType.Funding, Value = 1112.3M } }, Id = Guid.NewGuid().ToString(), Provider = new ProviderSummary { Id = "prov1", Name = "Provider 1", ProviderType = "TYpe 1", ProviderSubType = "Sub type 1", Authority = "Authority", UKPRN = "ukprn123", URN = "urn123", EstablishmentNumber = "en123", UPIN = "upin123", DateOpened = DateTime.Now }, SpecificationId = "spec1" } }; // Act await repo.SaveProviderResults(results); // Assert await searchRepository.Received(1).Index(Arg.Is <IEnumerable <CalculationProviderResultsIndex> >(r => r.Count() == 1)); await searchRepository.Received(1).Index(Arg.Is <IEnumerable <CalculationProviderResultsIndex> >(r => r.First().SpecificationId == results.First().SpecificationId&& r.First().SpecificationName == "Specification 1" && r.First().CalculationSpecificationId == results.First().CalculationResults.First().CalculationSpecification.Id&& r.First().CalculationSpecificationName == results.First().CalculationResults.First().CalculationSpecification.Name&& r.First().CalculationName == results.First().CalculationResults.First().Calculation.Name&& r.First().CalculationId == results.First().CalculationResults.First().Calculation.Id&& r.First().CalculationType == results.First().CalculationResults.First().CalculationType.ToString() && r.First().ProviderId == results.First().Provider.Id&& r.First().ProviderName == results.First().Provider.Name&& r.First().ProviderType == results.First().Provider.ProviderType&& r.First().ProviderSubType == results.First().Provider.ProviderSubType&& r.First().LocalAuthority == results.First().Provider.Authority&& r.First().UKPRN == results.First().Provider.UKPRN&& r.First().URN == results.First().Provider.URN&& r.First().UPIN == results.First().Provider.UPIN&& r.First().EstablishmentNumber == results.First().Provider.EstablishmentNumber&& r.First().OpenDate == results.First().Provider.DateOpened&& r.First().CalculationResult == Convert.ToDouble(results.First().CalculationResults.First().Value) && r.First().IsExcluded == false)); }