public async Task <ReadOnlyCollection <FundingSourcePaymentEvent> > UnableToFundTransfer(ProcessUnableToFundTransferFundingSourcePayment message) { try { using (var operation = telemetry.StartOperation("LevyFundedService.UnableToFundTransfer", message.EventId.ToString())) { var stopwatch = Stopwatch.StartNew(); paymentLogger.LogDebug($"Handling UnableToFundTransfer for {Id}, Job: {message.JobId}, UKPRN: {message.Ukprn}, Receiver Account: {message.AccountId}, Sender Account: {message.TransferSenderAccountId}"); var fundingSourcePayments = await fundingSourceService.ProcessReceiverTransferPayment(message).ConfigureAwait(false); paymentLogger.LogInfo($"Finished handling required payment for {Id}, Job: {message.JobId}, UKPRN: {message.Ukprn}, Account: {message.AccountId}"); telemetry.TrackDuration("LevyFundedService.UnableToFundTransfer", stopwatch, message); telemetry.StopOperation(operation); return(fundingSourcePayments); } } catch (Exception e) { paymentLogger.LogError($"Error handling unable to fund transfer. Error: {e.Message}", e); throw; } }
public async Task ShouldAddPaymentToCacheIfMonthEndNotStarted() { // arrange const long expectedUln = 200; const long expectedUkprn = 100; var expectedEventId = Guid.NewGuid(); var keys = new List <RequiredPaymentSortKeyModel> { new RequiredPaymentSortKeyModel { Ukprn = expectedUkprn, Uln = 1, Id = Guid.NewGuid().ToString(), AgreedOnDate = DateTime.Today }, new RequiredPaymentSortKeyModel { Ukprn = expectedUkprn, Uln = 2, Id = Guid.NewGuid().ToString(), AgreedOnDate = DateTime.Today } }; var unableToFundEvent = new ProcessUnableToFundTransferFundingSourcePayment { Ukprn = expectedUkprn, EventId = expectedEventId, AccountId = 1, AmountDue = 100, StartDate = DateTime.Today, Learner = new Learner { Uln = expectedUln }, }; eventCacheMock .Setup(c => c.AddOrReplace(expectedEventId.ToString(), It.Is <CalculatedRequiredLevyAmount>(levyEvent => levyEvent.AmountDue == unableToFundEvent.AmountDue && levyEvent.EventId == expectedEventId), CancellationToken.None)) .Returns(Task.CompletedTask) .Verifiable(); requiredPaymentSortKeysCacheMock .Setup(c => c.TryGet(CacheKeys.RequiredPaymentKeyListKey, CancellationToken.None)) .ReturnsAsync(() => new ConditionalValue <List <RequiredPaymentSortKeyModel> >(true, keys)) .Verifiable(); requiredPaymentSortKeysCacheMock .Setup(c => c.AddOrReplace(CacheKeys.RequiredPaymentKeyListKey, It.Is <List <RequiredPaymentSortKeyModel> >(list => list.Count == 3 && list[2].Uln == expectedUln && list[2].Ukprn == expectedUkprn), CancellationToken.None)) .Returns(Task.CompletedTask) .Verifiable(); monthEndCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key.Equals(CacheKeys.MonthEndCacheKey)), It.IsAny <CancellationToken>())) .ReturnsAsync(() => new ConditionalValue <bool>(false, false)) .Verifiable(); // act await service.ProcessReceiverTransferPayment(unableToFundEvent); // assert }