public async Task <PublishedProvider> CreateVersion(PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest) { Guard.ArgumentNotNull(publishedProviderCreateVersionRequest.PublishedProvider, nameof(publishedProviderCreateVersionRequest.PublishedProvider)); Guard.ArgumentNotNull(publishedProviderCreateVersionRequest.NewVersion, nameof(publishedProviderCreateVersionRequest.NewVersion)); PublishedProviderVersion currentVersion = publishedProviderCreateVersionRequest.PublishedProvider.Current; PublishedProviderVersion newVersion = publishedProviderCreateVersionRequest.NewVersion; string partitionKey = currentVersion != null ? publishedProviderCreateVersionRequest.PublishedProvider.PartitionKey : string.Empty; try { publishedProviderCreateVersionRequest.PublishedProvider.Current = await _versionRepositoryPolicy.ExecuteAsync(() => _versionRepository.CreateVersion(newVersion, currentVersion, partitionKey)); } catch (Exception ex) { _logger.Error(ex, $"Failed to create new version for published provider version id: {newVersion.Id}"); throw; } return(publishedProviderCreateVersionRequest.PublishedProvider); }
private void AndTheNewCreatedPublishedProvider(PublishedProvider publishedProvider, PublishedProviderCreateVersionRequest expectedPublishedProviderCreateVersionRequest) { _publishedProviderVersioningService.Setup(_ => _.CreateVersion(expectedPublishedProviderCreateVersionRequest)) .ReturnsAsync(publishedProvider); }
public async Task CreateVersion_GivenValidInputWithCurrentVersion_EnsuresCallsCreateVersionWithCorrectParameters() { //Arrange const string providerId = "123"; const string fundingPeriodId = "456"; const string fundingStreamId = "789"; string partitionKey = $"publishedprovider-{providerId}-{fundingPeriodId}-{fundingStreamId}"; PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest = new PublishedProviderCreateVersionRequest { PublishedProvider = new PublishedProvider { Current = new PublishedProviderVersion { ProviderId = providerId, FundingPeriodId = fundingPeriodId, FundingStreamId = fundingStreamId } }, NewVersion = new PublishedProviderVersion { ProviderId = providerId, FundingPeriodId = fundingPeriodId, FundingStreamId = fundingStreamId } }; IEnumerable <PublishedProviderCreateVersionRequest> versions = new[] { publishedProviderCreateVersionRequest }; ILogger logger = CreateLogger(); IVersionRepository <PublishedProviderVersion> versionRepository = CreateVersionRepository(); PublishedProviderVersioningService service = CreateVersioningService(logger, versionRepository); //Act IEnumerable <PublishedProvider> result = await service.CreateVersions(versions); //Assert await versionRepository .Received(1) .CreateVersion( Arg.Is(publishedProviderCreateVersionRequest.NewVersion), Arg.Is <PublishedProviderVersion>(m => m.ProviderId == providerId && m.FundingPeriodId == fundingPeriodId && m.FundingStreamId == fundingStreamId), Arg.Is(partitionKey)); }
private async Task <PublishedProvider> CreateVersion(PublishedProvider publishedProvider, Reference author) { IEnumerable <PublishedProviderCreateVersionRequest> publishedProviderCreateVersionRequests = _publishedProviderVersioningService.AssemblePublishedProviderCreateVersionRequests(new[] { publishedProvider }, author, PublishedProviderStatus.Updated); PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest = publishedProviderCreateVersionRequests.FirstOrDefault(); if (publishedProviderCreateVersionRequest == null) { _logger.Warning($"Assign profile pattern key to published provider with ID: {publishedProvider.Id} failed on create new version step."); return(null); } return(await _publishedProviderVersioningService.CreateVersion(publishedProviderCreateVersionRequest)); }
private void AndThePublishedProviderCreateVersionRequest(PublishedProvider expectedPublishedProvider, PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest) { _publishedProviderVersioningService.Setup(_ => _.AssemblePublishedProviderCreateVersionRequests( It.Is <IEnumerable <PublishedProvider> >(pp => PublishedProviderMatches(pp, expectedPublishedProvider)), It.Is <Reference>(rf => rf != null && _author != null && rf.ToString() == _author.ToString()), PublishedProviderStatus.Updated, null, null, false)) .Returns(new[] { publishedProviderCreateVersionRequest }); }
public async Task AssignProfilePatternKeyReturnsOkAndUpdatesPatternKeyWithNewVersion() { string fundingLineCode = NewRandomString(); string existingProfilePatternKey = NewRandomString(); string newProfilePatterFundingKey = NewRandomString(); string specificationId = NewRandomString(); GivenTheFundingConfiguration(true); ProfilePatternKey profilePatternKey = NewProfilePatternKey(_ => _.WithFundingLineCode(fundingLineCode).WithKey(newProfilePatterFundingKey)); FundingLine fundingLine = NewFundingLine(_ => _.WithFundingLineCode(fundingLineCode)); PublishedProviderVersion existingPublishedProviderVersion = NewPublishedProviderVersion(ppv => ppv .WithFundingStreamId(_fundingStreamId) .WithSpecificationId(specificationId) .WithFundingPeriodId(_fundingPeriodId) .WithProfilePatternKeys( NewProfilePatternKey(_ => _.WithFundingLineCode(fundingLineCode).WithKey(existingProfilePatternKey))) .WithFundingLines(fundingLine) ); PublishedProvider publishedProvider = NewPublishedProvider(_ => _.WithCurrent(existingPublishedProviderVersion)); PublishedProviderVersion newPublishedProviderVersion = existingPublishedProviderVersion; PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest = NewPublishedProviderCreateVersionRequest(_ => _ .WithPublishedProvider(publishedProvider) .WithNewVersion(newPublishedProviderVersion)); GivenThePublishedProvider(publishedProvider); AndThePublishedProviderCreateVersionRequest(publishedProvider, publishedProviderCreateVersionRequest); AndTheNewCreatedPublishedProvider(publishedProvider, publishedProviderCreateVersionRequest); AndTheProfileVariationPointers(null, specificationId); AndTheProfileFundingLines(profilePatternKey); AndTheSavePublishedProviderVersionResponse(HttpStatusCode.OK, existingPublishedProviderVersion); AndTheUpsertPublishedProviderResponse(HttpStatusCode.OK, publishedProvider); IActionResult result = await WhenProfilePatternKeyIsAssigned(_fundingStreamId, _fundingPeriodId, _providerId, profilePatternKey); ThenResultShouldBe(result, HttpStatusCode.OK); AndProfilePatternKeyWasUpdated(newPublishedProviderVersion, profilePatternKey); AndThePublishedProviderWasProcessed(publishedProvider); AndTheProfilingAuditWasUpdatedForTheFundingLine(publishedProvider, profilePatternKey.FundingLineCode, _author); }
public async Task CreateVersion_GivenValidInputWithCurrentVersion_ReturnsPublishedProviderWithNewVersion() { //Arrange const string providerId = "123"; const string fundingPeriodId = "456"; const string fundingStreamId = "789"; string partitionKey = $"publishedprovider_{providerId}_{fundingPeriodId}_{fundingStreamId}"; PublishedProviderVersion newCreatedVersion = new PublishedProviderVersion { ProviderId = providerId, FundingPeriodId = fundingPeriodId, FundingStreamId = fundingStreamId, Version = 1, Date = DateTimeOffset.Now, PublishStatus = PublishStatus.Approved }; PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest = new PublishedProviderCreateVersionRequest { PublishedProvider = new PublishedProvider { Current = new PublishedProviderVersion { ProviderId = providerId, FundingPeriodId = fundingPeriodId, FundingStreamId = fundingStreamId } }, NewVersion = new PublishedProviderVersion { ProviderId = providerId, FundingPeriodId = fundingPeriodId, FundingStreamId = fundingStreamId } }; IEnumerable <PublishedProviderCreateVersionRequest> versions = new[] { publishedProviderCreateVersionRequest }; ILogger logger = CreateLogger(); IVersionRepository <PublishedProviderVersion> versionRepository = CreateVersionRepository(); versionRepository .CreateVersion(Arg.Any <PublishedProviderVersion>(), Arg.Any <PublishedProviderVersion>(), Arg.Any <string>()) .Returns(newCreatedVersion); PublishedProviderVersioningService service = CreateVersioningService(logger, versionRepository); //Act IEnumerable <PublishedProvider> result = await service.CreateVersions(versions); //Assert result .Should() .HaveCount(1); result .First() .Current .Should() .BeEquivalentTo(newCreatedVersion); }
public async Task AssignProfilePatternKeyForFundingLineWithAlreadyPaidProfilePeriodsUsesReProfileResponseResultsFromApi() { string fundingLineCode = NewRandomString(); string existingProfilePatternKey = NewRandomString(); string newProfilePatterFundingKey = NewRandomString(); string specificationId = NewRandomString(); int occurence = NewRandomNumberBetween(1, 100); ProfilePeriodType profilePeriodType = NewRandomEnum <ProfilePeriodType>(); string typeValue = NewRandomString(); int year = NewRandomNumberBetween(2019, 2021); string distributionPeriodId = NewRandomString(); decimal carryOverAmount = NewRandomNumberBetween(1, int.MaxValue); GivenTheFundingConfiguration(true); ProfilePatternKey profilePatternKey = NewProfilePatternKey(_ => _.WithFundingLineCode(fundingLineCode).WithKey(newProfilePatterFundingKey)); ProfilePeriod paidProfilePeriod = NewProfilePeriod(pp => pp .WithDistributionPeriodId(distributionPeriodId) .WithType(profilePeriodType) .WithTypeValue(typeValue) .WithYear(year) .WithOccurence(occurence)); FundingLine fundingLine = NewFundingLine(_ => _ .WithFundingLineCode(fundingLineCode) .WithDistributionPeriods( NewDistributionPeriod(dp => dp .WithDistributionPeriodId(distributionPeriodId) .WithProfilePeriods(paidProfilePeriod)) )); PublishedProviderVersion existingPublishedProviderVersion = NewPublishedProviderVersion(ppv => ppv .WithFundingStreamId(_fundingStreamId) .WithFundingPeriodId(_fundingPeriodId) .WithSpecificationId(specificationId) .WithProfilePatternKeys( NewProfilePatternKey(_ => _.WithFundingLineCode(fundingLineCode) .WithKey(existingProfilePatternKey))) .WithFundingLines(fundingLine) ); PublishedProvider publishedProvider = NewPublishedProvider(_ => _.WithCurrent(existingPublishedProviderVersion)); PublishedProviderCreateVersionRequest publishedProviderCreateVersionRequest = NewPublishedProviderCreateVersionRequest(_ => _.WithPublishedProvider(publishedProvider) .WithNewVersion(existingPublishedProviderVersion)); IEnumerable <ProfileVariationPointer> profileVariationPointers = NewProfileVariationPointers(_ => _ .WithFundingLineId(fundingLineCode) .WithFundingStreamId(_fundingStreamId) .WithOccurence(occurence) .WithPeriodType(profilePeriodType.ToString()) .WithTypeValue(typeValue) .WithYear(year)); ReProfileRequest reProfileRequest = NewReProfileRequest(); ReProfileResponse reProfileResponse = NewReProfileResponse(_ => _.WithCarryOverAmount(carryOverAmount) .WithDeliveryProfilePeriods(NewDeliveryProfilePeriod(dpp => dpp.WithOccurrence(1) .WithValue(10) .WithYear(2021) .WithTypeValue("JANUARY") .WithPeriodType(PeriodType.CalendarMonth) .WithDistributionPeriod("dp1")), NewDeliveryProfilePeriod(dpp => dpp.WithOccurrence(1) .WithValue(20) .WithYear(2022) .WithTypeValue("JANUARY") .WithPeriodType(PeriodType.CalendarMonth) .WithDistributionPeriod("dp2")))); GivenThePublishedProvider(publishedProvider); AndThePublishedProviderCreateVersionRequest(publishedProvider, publishedProviderCreateVersionRequest); AndTheNewCreatedPublishedProvider(publishedProvider, publishedProviderCreateVersionRequest); AndTheProfileVariationPointers(profileVariationPointers, specificationId); AndTheReProfileRequest(existingPublishedProviderVersion.SpecificationId, existingPublishedProviderVersion.FundingStreamId, existingPublishedProviderVersion.FundingPeriodId, existingPublishedProviderVersion.ProviderId, profilePatternKey.FundingLineCode, profilePatternKey.Key, ProfileConfigurationType.Custom, fundingLine.Value, reProfileRequest); AndTheReProfileResponse(reProfileRequest, reProfileResponse); AndTheProfileFundingLines(profilePatternKey); AndTheSavePublishedProviderVersionResponse(HttpStatusCode.OK, existingPublishedProviderVersion); AndTheUpsertPublishedProviderResponse(HttpStatusCode.OK, publishedProvider); IActionResult result = await WhenProfilePatternKeyIsAssigned(_fundingStreamId, _fundingPeriodId, _providerId, profilePatternKey); ThenResultShouldBe(result, HttpStatusCode.OK); AndProfilePatternKeyWasUpdated(existingPublishedProviderVersion, profilePatternKey); fundingLine.DistributionPeriods .Count() .Should() .Be(2); DistributionPeriod firstDistributionPeriod = fundingLine.DistributionPeriods.SingleOrDefault(_ => _.DistributionPeriodId == "dp1"); firstDistributionPeriod.ProfilePeriods .Should() .BeEquivalentTo(NewProfilePeriod(_ => _.WithAmount(10) .WithTypeValue("JANUARY") .WithDistributionPeriodId("dp1") .WithType(ProfilePeriodType.CalendarMonth) .WithOccurence(1) .WithYear(2021))); DistributionPeriod secondDistributionPeriod = fundingLine.DistributionPeriods.SingleOrDefault(_ => _.DistributionPeriodId == "dp2"); secondDistributionPeriod.ProfilePeriods .Should() .BeEquivalentTo(NewProfilePeriod(_ => _.WithAmount(20) .WithTypeValue("JANUARY") .WithDistributionPeriodId("dp2") .WithType(ProfilePeriodType.CalendarMonth) .WithOccurence(1) .WithYear(2022))); existingPublishedProviderVersion.CarryOvers .Should() .BeEquivalentTo(NewCarryOver(_ => _.WithAmount(carryOverAmount) .WithFundingLineCode(fundingLineCode) .WithType(ProfilingCarryOverType.CustomProfile))); AndThePublishedProviderWasProcessed(publishedProvider); AndTheProfilingAuditWasUpdatedForTheFundingLine(publishedProvider, profilePatternKey.FundingLineCode, _author); }