public async Task ShouldNotRemovePreviousSuccessfulProviderJobSubmission()
        {
            var keys = new List <string> {
                "1", "2"
            };
            var successfulUkprn       = 23456;
            var requiredPaymentEvent1 = new CalculatedRequiredLevyAmount
            {
                EventId   = Guid.NewGuid(),
                AmountDue = 100,
                SfaContributionPercentage = 11,
                OnProgrammeEarningType    = OnProgrammeEarningType.Completion,
                Learner          = new Learner(),
                CollectionPeriod = new CollectionPeriod {
                    AcademicYear = 1920, Period = 1
                },
                Ukprn                 = 123456,
                AccountId             = 1,
                JobId                 = 1,
                IlrSubmissionDateTime = DateTime.Now.AddMinutes(-1)
            };
            var requiredPaymentEvent2 = new CalculatedRequiredLevyAmount
            {
                EventId   = Guid.NewGuid(),
                AmountDue = 100,
                SfaContributionPercentage = 11,
                OnProgrammeEarningType    = OnProgrammeEarningType.Completion,
                Learner          = new Learner(),
                CollectionPeriod = new CollectionPeriod {
                    AcademicYear = 1920, Period = 1
                },
                Ukprn                 = successfulUkprn,
                AccountId             = 1,
                JobId                 = 2,
                IlrSubmissionDateTime = DateTime.Now
            };

            generateSortedPaymentKeysMock
            .Setup(x => x.GeyKeys())
            .ReturnsAsync(keys)
            .Verifiable();

            eventCacheMock.Setup(c => c.TryGet("1", CancellationToken.None))
            .ReturnsAsync(() => new ConditionalValue <CalculatedRequiredLevyAmount>(true, requiredPaymentEvent1))
            .Verifiable();
            eventCacheMock.Setup(c => c.TryGet("2", CancellationToken.None))
            .ReturnsAsync(() => new ConditionalValue <CalculatedRequiredLevyAmount>(true, requiredPaymentEvent2))
            .Verifiable();

            // act
            await service.RemovePreviousSubmissions(requiredPaymentEvent2.JobId,
                                                    requiredPaymentEvent2.CollectionPeriod.Period,
                                                    requiredPaymentEvent2.CollectionPeriod.AcademicYear,
                                                    requiredPaymentEvent2.IlrSubmissionDateTime,
                                                    requiredPaymentEvent2.Ukprn);

            // assert
            eventCacheMock.Verify(c => c.Clear("1", CancellationToken.None), Times.Never);
        }
Beispiel #2
0
        public async Task RemovePreviousSubmissions(SubmissionSucceededEvent message)
        {
            paymentLogger.LogVerbose($"Handling ProcessSubmissionDeletion for {Id}, Job: {message.JobId}");
            try
            {
                using (var operation = telemetry.StartOperation())
                {
                    await fundingSourceService.RemovePreviousSubmissions(message.JobId, message.CollectionPeriod, message.AcademicYear, message.IlrSubmissionDateTime, message.Ukprn);

                    telemetry.StopOperation(operation);
                }
            }
            catch (Exception ex)
            {
                paymentLogger.LogError($"Failed to remove previous submission required payments. Error: {ex.Message}", ex);
                throw;
            }
        }