public async Task ApproveAllProvidersResults_IfUpdateProviderStatusExceptionsTransactionCompensates() { PublishedProvider[] expectedPublishedProviders = { NewPublishedProvider(), NewPublishedProvider(), NewPublishedProvider(), NewPublishedProvider(), NewPublishedProvider(), NewPublishedProvider() }; string specificationId = NewRandomString(); GivenTheMessageHasACorrelationId(); GivenTheMessageHasTheSpecificationId(specificationId); AndTheMessageIsOtherwiseValid(); AndTheSpecificationHasTheHeldUnApprovedPublishedProviders(specificationId, null, expectedPublishedProviders); AndRetrieveJobAndCheckCanBeProcessedSuccessfully(_ => _.WithJobId(_jobId)); AndNumberOfApprovedPublishedProvidersThrowsException(expectedPublishedProviders); Func <Task> invocation = WhenAllProvidersResultsAreApproved; invocation .Should() .Throw <Exception>(); await _publishedProviderVersionService .Received(1) .CreateReIndexJob(Arg.Any <Reference>(), Arg.Any <string>(), Arg.Is(specificationId), Arg.Is(_jobId)); }
public async Task PublishAllProviderFundingResults_WhenAnUpdatePublishStatusThrowsException_TransactionCompensates() { string error = "Unable to update status."; GivenJobCanBeProcessed(); AndSpecification(); AndCalculationResultsBySpecificationId(); AndTemplateMetadataContents(); AndPublishedProviders(); AndUpdateStatusThrowsAnError(error); AndTemplateMapping(); Func <Task> invocation = WhenPublishAllProvidersMessageReceivedWithJobId; invocation .Should() .Throw <Exception>() .And .Message .Should() .Be(error); await _publishedProviderVersionService .Received(1) .CreateReIndexJob(Arg.Any <Reference>(), Arg.Any <string>(), Arg.Is(SpecificationId), Arg.Is(JobId)); await _publishedFundingSearchRepository .Received(0) .RunIndexer(); }
public async Task SavesAndIndexesPublishedProviderVersionWhenCorrectInputGiven() { // Arrange TemplateMetadataContents templateMetadataContents = Substitute.For <TemplateMetadataContents>(); TemplateMapping templateMapping = Substitute.For <TemplateMapping>(); IPublishedProviderContentsGenerator publishedProviderContentsGenerator = Substitute.For <IPublishedProviderContentsGenerator>(); List <PublishedProvider> publishedProvidersToUpdate = new List <PublishedProvider>(); PublishedProviderVersion publishedProviderVersion = NewPublishedProviderVersion(providerVersion => providerVersion .WithProviderId(ProviderVersionProviderId) .WithFundingPeriodId(ProviderVersionFundingPeriodId) .WithFundingStreamId(ProviderVersionFundingStreamId) .WithVersion(ProviderVersionVersion) .WithSpecificationId(ProviderVersionSpecificationId)); PublishedProvider publishedProvider = NewPublishedProvider(provider => provider.WithCurrent(publishedProviderVersion)); publishedProvidersToUpdate.Add(publishedProvider); publishedProviderContentsGenerator .GenerateContents(publishedProviderVersion, templateMetadataContents, templateMapping) .Returns("contents"); // Act await _publishedProviderContentPersistanceService.SavePublishedProviderContents( templateMetadataContents, templateMapping, publishedProvidersToUpdate, publishedProviderContentsGenerator); // Assert await _publishedProviderVersionService .Received() .SavePublishedProviderVersionBody(publishedProviderVersion.FundingId, Arg.Any <string>(), publishedProviderVersion.SpecificationId); await _publishedProviderIndexerService .Received() .IndexPublishedProvider(publishedProviderVersion); }