public async Task <IActionResult> PreviewProfilingChange(ProfilePreviewRequest request) { Guard.ArgumentNotNull(request, nameof(request)); ReProfileRequest reProfileRequest = await _reProfilingRequestBuilder.BuildReProfileRequest(request.SpecificationId, request.FundingStreamId, request.FundingPeriodId, request.ProviderId, request.FundingLineCode, request.ProfilePatternKey, request.ConfigurationType); ApiResponse <ReProfileResponse> reProfilingApiResponse = await _profilingResilience.ExecuteAsync(() => _profiling.ReProfile(reProfileRequest)); ReProfileResponse reProfileResponse = reProfilingApiResponse?.Content; if (reProfileResponse == null) { throw new InvalidOperationException( $"Did not received a valid re-profiling response for profile pattern preview request {request}"); } ExistingProfilePeriod[] existingProfilePeriods = reProfileRequest.ExistingPeriods.ToArray(); int isPaidTo = GetIsPaidTo(existingProfilePeriods); ProfileTotal[] profileTotals = BuildProfileTotals(reProfileResponse, existingProfilePeriods, isPaidTo); await AddFundingDatesToProfileTotals(request, profileTotals); return(new OkObjectResult(profileTotals)); }
private void AndAReProfileRequestWasBuiltForTheRequest(ProfilePreviewRequest request) => _reProfilingRequestBuilder.Verify(_ => _.BuildReProfileRequest(request.SpecificationId, request.FundingStreamId, request.FundingPeriodId, request.ProviderId, request.FundingLineCode, request.ProfilePatternKey, request.ConfigurationType, null), Times.Once);
private void GivenTheReProfileRequest(ProfilePreviewRequest previewRequest, ReProfileRequest reProfileRequest) => _reProfilingRequestBuilder.Setup(_ => _.BuildReProfileRequest(previewRequest.SpecificationId, previewRequest.FundingStreamId, previewRequest.FundingPeriodId, previewRequest.ProviderId, previewRequest.FundingLineCode, previewRequest.ProfilePatternKey, previewRequest.ConfigurationType, null)) .ReturnsAsync(reProfileRequest);
public async Task PreviewProfileChange() { ProfilePreviewRequest publishProvidersRequest = new ProfilePreviewRequest(); await AssertPostRequest("publishedproviderfundinglinepreview", publishProvidersRequest, new[] { NewRandomProfileTotal(), NewRandomProfileTotal(), NewRandomProfileTotal(), NewRandomProfileTotal(), NewRandomProfileTotal() }.AsEnumerable(), () => _client.PreviewProfileChange(publishProvidersRequest)); }
public void GuardsAgainstNotGettingAReProfilingResponse() { ProfilePreviewRequest previewRequest = NewProfilePreviewRequest(); Func <Task <IActionResult> > invocation = () => WhenTheProfilePatternChangeIsPreviewed(previewRequest); invocation .Should() .Throw <InvalidOperationException>() .Which .Message .Should() .Be($"Did not received a valid re-profiling response for profile pattern preview request {previewRequest}"); AndAReProfileRequestWasBuiltForTheRequest(previewRequest); }
private async Task AddFundingDatesToProfileTotals(ProfilePreviewRequest request, IEnumerable <ProfileTotal> profileTotals) { ApiResponse <FundingDate> fundingDateApiResponse = await _policiesResilience.ExecuteAsync(() => _policies.GetFundingDate(request.FundingStreamId, request.FundingPeriodId, request.FundingLineCode)); IEnumerable <FundingDatePattern> fundingDatePatterns = fundingDateApiResponse?.Content?.Patterns; foreach (ProfileTotal profileTotal in profileTotals ?? ArraySegment <ProfileTotal> .Empty) { profileTotal.ActualDate = fundingDatePatterns?.SingleOrDefault(_ => _.Occurrence == profileTotal.Occurrence && _.Period == profileTotal.TypeValue && _.PeriodYear == profileTotal.Year)?.PaymentDate; } }
public async Task ReProfilesFundingLineAndMapsResultsIntoProfileTotals() { ProfilePreviewRequest previewRequest = NewProfilePreviewRequest(); string distributionPeriod = NewRandomString(); ReProfileRequest expectedReProfileRequest = NewReProfileRequest(_ => _.WithFundingLineTotal(999) .WithExistingFundingLineTotal(1000) .WithExistingProfilePeriods(NewExistingProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("January") .WithValue(23) .WithYear(2021) .WithOccurrence(0)), NewExistingProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("January") .WithValue(24) .WithYear(2021) .WithOccurrence(1)), NewExistingProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("February") .WithValue(null) .WithYear(2021) .WithOccurrence(0)), NewExistingProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("March") .WithValue(null) .WithYear(2021) .WithOccurrence(0)), NewExistingProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("April") .WithValue(null) .WithYear(2021) .WithOccurrence(0)), NewExistingProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("May") .WithValue(null) .WithYear(2021) .WithOccurrence(0)) )); ReProfileResponse expectedReProfileResponse = NewReProfileResponse(_ => _.WithCarryOverAmount(992) .WithDeliveryProfilePeriods(NewDeliveryProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("January") .WithValue(33) .WithYear(2021) .WithOccurrence(0)), NewDeliveryProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("January") .WithValue(34) .WithYear(2021) .WithOccurrence(1)), NewDeliveryProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("February") .WithValue(35) .WithYear(2021) .WithOccurrence(0)), NewDeliveryProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("March") .WithValue(36) .WithYear(2021) .WithOccurrence(0)), NewDeliveryProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("April") .WithValue(37) .WithYear(2021) .WithOccurrence(0)), NewDeliveryProfilePeriod(exp => exp.WithDistributionPeriod(distributionPeriod) .WithPeriodType(PeriodType.CalendarMonth) .WithTypeValue("May") .WithValue(38) .WithYear(2021) .WithOccurrence(0)))); DateTimeOffset expectedActualDateOne = NewRandomDate(); DateTimeOffset expectedActualDateTwo = NewRandomDate(); DateTimeOffset expectedActualDateThree = NewRandomDate(); DateTimeOffset expectedActualDateFour = NewRandomDate(); FundingDate expectedFundingDate = NewFundingDate(_ => _.WithPatterns(NewFundingDatePattern(fdp => fdp.WithOccurrence(0) .WithPeriod("January") .WithPeriodYear(2021) .WithPaymentDate(expectedActualDateOne)), NewFundingDatePattern(fdp => fdp.WithOccurrence(0) .WithPeriod("February") .WithPeriodYear(2021) .WithPaymentDate(expectedActualDateTwo)), NewFundingDatePattern(fdp => fdp.WithOccurrence(0) .WithPeriod("April") .WithPeriodYear(2021) .WithPaymentDate(expectedActualDateThree)), NewFundingDatePattern(fdp => fdp.WithOccurrence(0) .WithPeriod("May") .WithPeriodYear(2021) .WithPaymentDate(expectedActualDateFour)), NewFundingDatePattern())); GivenTheReProfileRequest(previewRequest, expectedReProfileRequest); AndTheReProfileResponse(expectedReProfileRequest, expectedReProfileResponse); AndTheFundingDate(previewRequest, expectedFundingDate); OkObjectResult response = await WhenTheProfilePatternChangeIsPreviewed(previewRequest) as OkObjectResult; response? .Value .Should() .BeEquivalentTo(new [] { NewProfileTotal(_ => _.WithOccurrence(0) .WithDistributionPeriod(distributionPeriod) .WithValue(23) .WithYear(2021) .WithPeriodType("CalenderMonth") .WithTypeValue("January") .WithIsPaid(true) .WithInstallmentNumber(1) .WithActualDate(expectedActualDateOne)), NewProfileTotal(_ => _.WithOccurrence(1) .WithDistributionPeriod(distributionPeriod) .WithValue(24) .WithYear(2021) .WithPeriodType("CalenderMonth") .WithTypeValue("January") .WithIsPaid(true) .WithInstallmentNumber(2) .WithActualDate(null)), NewProfileTotal(_ => _.WithOccurrence(0) .WithDistributionPeriod(distributionPeriod) .WithValue(35) .WithYear(2021) .WithPeriodType("CalenderMonth") .WithTypeValue("February") .WithIsPaid(false) .WithInstallmentNumber(3) .WithActualDate(expectedActualDateTwo)), NewProfileTotal(_ => _.WithOccurrence(0) .WithDistributionPeriod(distributionPeriod) .WithValue(36) .WithYear(2021) .WithPeriodType("CalenderMonth") .WithTypeValue("March") .WithIsPaid(false) .WithInstallmentNumber(4) .WithActualDate(null)), NewProfileTotal(_ => _.WithOccurrence(0) .WithDistributionPeriod(distributionPeriod) .WithValue(37) .WithYear(2021) .WithPeriodType("CalenderMonth") .WithTypeValue("April") .WithIsPaid(false) .WithInstallmentNumber(5) .WithActualDate(expectedActualDateThree)), NewProfileTotal(_ => _.WithOccurrence(0) .WithDistributionPeriod(distributionPeriod) .WithValue(38) .WithYear(2021) .WithPeriodType("CalenderMonth") .WithTypeValue("May") .WithIsPaid(false) .WithInstallmentNumber(6) .WithActualDate(expectedActualDateFour)) }); }
private void AndTheFundingDate(ProfilePreviewRequest previewRequest, FundingDate fundingDate) => _policies.Setup(_ => _.GetFundingDate(previewRequest.FundingStreamId, previewRequest.FundingPeriodId, previewRequest.FundingLineCode)) .ReturnsAsync(new ApiResponse <FundingDate>(HttpStatusCode.OK, fundingDate));
private async Task <IActionResult> WhenTheProfilePatternChangeIsPreviewed(ProfilePreviewRequest request) => await _preview.PreviewProfilingChange(request);
public async Task <IActionResult> PreviewProfileChange([FromBody] ProfilePreviewRequest request) => await _profilePatternPreview.PreviewProfilingChange(request);