private void GivenThePaymentDates(FundingStreamPaymentDates fundingStreamPaymentDates, string fundingStreamId, string fundingPeriodId) { _paymentDates.Setup(_ => _.GetUpdateDates(fundingStreamId, fundingPeriodId)) .ReturnsAsync(fundingStreamPaymentDates); }
public async Task <IActionResult> GetFundingStreamPaymentDates(string fundingStreamId, string fundingPeriodId) { Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId)); Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId)); FundingStreamPaymentDates fundingStreamPaymentDates = await _resilience.ExecuteAsync(() => _fundingStreamPaymentDates.GetUpdateDates(fundingStreamId, fundingPeriodId)); return(fundingStreamPaymentDates == null ? (IActionResult) new NotFoundResult() : new OkObjectResult(fundingStreamPaymentDates)); }
public async Task SaveFundingStreamUpdatedDatesDelegatesToCosmosRepository() { FundingStreamPaymentDates paymentDates = NewPaymentDates(); await _repository.SaveFundingStreamUpdatedDates(paymentDates); _cosmosRepository .Verify(_ => _.UpsertAsync(paymentDates, paymentDates.FundingStreamId, false, true), Times.Once); }
public async Task DelegatesToRepositoryAndReturnsOkObjectResult() { string fundingStreamId = NewRandomString(); string fundingPeriodId = NewRandomString(); FundingStreamPaymentDates expectedPaymentDates = NewPaymentDates(); GivenThePaymentDates(expectedPaymentDates, fundingStreamId, fundingPeriodId); OkObjectResult result = await WhenThePaymentDatesAreQueried(fundingStreamId, fundingPeriodId) as OkObjectResult; result? .Value .Should() .BeSameAs(expectedPaymentDates); }
public async Task GetUpdateDatesExecutesSqlQueryAgainstCosmosRepositoryForSuppliedFundingStreamAndPeriodIds() { string fundingPeriodId = NewRandomString(); string fundingStreamId = NewRandomString(); FundingStreamPaymentDates expectedPaymentDates = NewPaymentDates(); GivenThePaymentDatesForTheFundingStreamAndPeriodIds(fundingPeriodId, fundingStreamId, expectedPaymentDates); FundingStreamPaymentDates actualPaymentDates = await WhenThePaymentDatesAreQueried(fundingStreamId, fundingPeriodId); actualPaymentDates .Should() .BeSameAs(expectedPaymentDates); _cosmosRepository .Verify(); }
private void GivenThePaymentDatesForTheFundingStreamAndPeriodIds(string fundingPeriodId, string fundingStreamId, FundingStreamPaymentDates paymentDates) { _cosmosRepository.Setup(_ => _.QuerySql <FundingStreamPaymentDates>(It.Is <CosmosDbQuery>(query => query.QueryText == @"SELECT * FROM c WHERE c.documentType = 'FundingStreamPaymentDates' AND c.deleted = false AND c.content.fundingStreamId = @fundingStreamId AND c.content.fundingPeriodId = @fundingPeriodId" && HasParameter(query.Parameters, "@fundingStreamId", fundingStreamId) && HasParameter(query.Parameters, "@fundingPeriodId", fundingPeriodId)), -1, 1)) .ReturnsAsync(new[] { paymentDates }) .Verifiable(); }
public async Task <IActionResult> GetProfileHistory(string fundingStreamId, string fundingPeriodId, string providerId) { Guard.IsNullOrWhiteSpace(providerId, nameof(providerId)); Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId)); Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId)); FundingStreamPaymentDates paymentDates = await _paymentDatesPolicy.ExecuteAsync(() => _paymentDates.GetUpdateDates(fundingStreamId, fundingPeriodId)); PublishedProviderVersion publishedProviderVersion = await _publishedFundingPolicy.ExecuteAsync(() => _publishedFunding.GetLatestPublishedProviderVersion(fundingStreamId, fundingPeriodId, providerId)); if (publishedProviderVersion == null) { return(new NotFoundResult()); } ProfileTotal[] publishedProviderProfiling = new PaymentFundingLineProfileTotals(publishedProviderVersion) .ToArray(); foreach (FundingStreamPaymentDate paymentDate in PastPaymentDates(paymentDates)) { ProfileTotal matchingProfileTotal = publishedProviderProfiling.SingleOrDefault(_ => _.Year == paymentDate.Year && _.TypeValue == paymentDate.TypeValue && _.Occurrence == paymentDate.Occurrence); if (matchingProfileTotal == null) { continue; } matchingProfileTotal.IsPaid = true; } return(new OkObjectResult(publishedProviderProfiling)); }
private void AndThePaymentDates(string fundingStreamId, string fundingPeriodId, FundingStreamPaymentDates paymentDates) { _paymentDates.Setup(_ => _.GetUpdateDates(fundingStreamId, fundingPeriodId)) .ReturnsAsync(paymentDates); }
public async Task CorrelatesPaymentDatesForFundingStreamWithProfileTotalsToMarkAnyInThePastAsPaid() { DateTimeOffset utcNow = DateTimeOffset.Parse("2020-03-20"); PublishedProviderVersion publishedProviderVersion = NewPublishedProviderVersion(_ => _.WithFundingLines(NewFundingLine( fl => fl.WithFundingLineType(FundingLineType.Payment) .WithDistributionPeriods(NewDistributionPeriod(dp => dp.WithProfilePeriods(NewProfilePeriod(pp => pp.WithTypeValue("January") .WithYear(2020) .WithOccurence(1)), NewProfilePeriod(pp => pp.WithTypeValue("January") .WithYear(2020) .WithOccurence(2)), NewProfilePeriod(pp => pp.WithTypeValue("February") .WithYear(2020) .WithOccurence(1)), NewProfilePeriod(pp => pp.WithTypeValue("February") .WithYear(2020) .WithOccurence(2)), NewProfilePeriod(pp => pp.WithTypeValue("March") .WithYear(2020) .WithOccurence(1)), NewProfilePeriod(pp => pp.WithTypeValue("March") .WithYear(2020) .WithOccurence(2)), NewProfilePeriod(pp => pp.WithTypeValue("April") .WithYear(2020) .WithOccurence(1)), NewProfilePeriod(pp => pp.WithTypeValue("April") .WithYear(2020) .WithOccurence(2)) )))))); FundingStreamPaymentDates paymentDates = NewPaymentDates(_ => _.WithPaymentDates( NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("January") .WithOccurence(1) .WithDate("2020-01-07")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("January") .WithOccurence(2) .WithDate("2020-01-21")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("February") .WithOccurence(1) .WithDate("2020-02-07")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("February") .WithOccurence(2) .WithDate("2020-02-21")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("March") .WithOccurence(1) .WithDate("2020-03-07")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("March") .WithOccurence(2) .WithDate("2020-03-21")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("April") .WithOccurence(1) .WithDate("2020-04-07")), NewPaymentDate(pd => pd.WithOccurence(1) .WithYear(2020) .WithTypeValue("April") .WithOccurence(2) .WithDate("2020-04-21")) )); string fundingStreamId = NewRandomString(); string fundingPeriodId = NewRandomString(); string providerId = NewRandomString(); GivenTheCurrentDateTime(utcNow); AndTheLatestPublishedProviderVersion(fundingStreamId, fundingPeriodId, providerId, publishedProviderVersion); AndThePaymentDates(fundingStreamId, fundingPeriodId, paymentDates); OkObjectResult result = (await WhenTheProfileHistoryIsQueried(fundingStreamId, fundingPeriodId, providerId)) as OkObjectResult; result .Should() .NotBeNull(); ProfileTotal[] expectedProfileTotals = new[] { NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("January") .WithOccurrence(1) .WithIsPaid(true)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("January") .WithOccurrence(2) .WithIsPaid(true)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("February") .WithOccurrence(1) .WithIsPaid(true)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("February") .WithOccurrence(2) .WithIsPaid(true)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("March") .WithOccurrence(1) .WithIsPaid(true)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("March") .WithOccurrence(2) .WithIsPaid(false)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("April") .WithOccurrence(1) .WithIsPaid(false)), NewProfileTotal(_ => _.WithYear(2020) .WithTypeValue("April") .WithOccurrence(2) .WithIsPaid(false)), }; result .Value .Should() .BeEquivalentTo(expectedProfileTotals, opt => opt.WithoutStrictOrdering()); }
public async Task SaveFundingStreamUpdatedDates(FundingStreamPaymentDates paymentDates) { await _cosmosRepository.UpsertAsync(paymentDates, paymentDates.FundingStreamId); }
private IEnumerable <FundingStreamPaymentDate> PastPaymentDates(FundingStreamPaymentDates paymentDates) { DateTimeOffset today = _dateTimeProvider.UtcNow.Date; return((paymentDates?.PaymentDates ?? Enumerable.Empty <FundingStreamPaymentDate>()).Where(_ => _.Date <= today)); }