public async Task Handle(ReceivedProviderEarningsEvent message, CancellationToken cancellationToken)
        {
            logger.LogVerbose($"Handling ILR Submissions. Data: {message.ToJson()}");
            var currentIlr = await GetCurrentIlrSubmissionEvent(message.Ukprn, cancellationToken);

            var isNewIlrSubmission = validateIlrSubmission.IsNewIlrSubmission(new IlrSubmissionValidationRequest
            {
                IncomingPaymentUkprn          = message.Ukprn,
                IncomingPaymentSubmissionDate = message.IlrSubmissionDateTime,
                CurrentIlr = currentIlr
            });

            if (!isNewIlrSubmission)
            {
                logger.LogInfo($"Ignored same Ilr Submission Data for Ukprn {message.Ukprn} and Job Id {message.JobId} Submission already processed");
                return;
            }

            logger.LogInfo($"Updating current Ilr Submission Data for Ukprn {message.Ukprn} and Job Id {message.JobId}");

            await ilrSubmittedEventCache.Clear(message.Ukprn.ToString(), cancellationToken);

            await ilrSubmittedEventCache.Add(message.Ukprn.ToString(), message, cancellationToken);

            logger.LogDebug($"Successfully Updated current Ilr Submission Data for Ukprn {message.Ukprn} and Job Id {message.JobId}");

            await providerPaymentsRepository.DeleteOldMonthEndPayment(message.CollectionPeriod,
                                                                      message.Ukprn,
                                                                      message.IlrSubmissionDateTime,
                                                                      cancellationToken);

            logger.LogInfo($"Successfully Deleted Old Month End Payment for Ukprn {message.Ukprn} and Job Id {message.JobId}");
        }
Ejemplo n.º 2
0
 public void Setup()
 {
     currentIlr = new ReceivedProviderEarningsEvent
     {
         Ukprn = 1000,
         JobId = 1000,
         IlrSubmissionDateTime = DateTime.MaxValue
     };
 }
Ejemplo n.º 3
0
        private async Task SendReceivedEarningsEvent(long jobId, DateTime ilrSubmissionDateTime, string academicYear, int collectionPeriod, long ukprn)
        {
            var message = new ReceivedProviderEarningsEvent
            {
                JobId = jobId,
                IlrSubmissionDateTime = ilrSubmissionDateTime,
                CollectionPeriod      = new CollectionPeriod {
                    AcademicYear = short.Parse(academicYear), Period = (byte)collectionPeriod
                },
                Ukprn     = ukprn,
                EventTime = DateTimeOffset.UtcNow
            };

            var endpointInstance = await factory.GetEndpointInstance().ConfigureAwait(false);

            await endpointInstance.Publish(message).ConfigureAwait(false);
        }
Ejemplo n.º 4
0
        public void SetUp()
        {
            mocker = AutoMock.GetLoose();

            payments = new List <PaymentModel>
            {
                new PaymentModel
                {
                    Ukprn                     = ukprn,
                    FundingSource             = FundingSourceType.CoInvestedEmployer,
                    SfaContributionPercentage = 0.9m,
                    JobId                     = 1,
                    DeliveryPeriod            = 7,
                    CollectionPeriod          = new CollectionPeriod
                    {
                        AcademicYear = 1819,
                        Period       = 8
                    },
                    IlrSubmissionDateTime  = DateTime.UtcNow,
                    ContractType           = ContractType.Act1,
                    PriceEpisodeIdentifier = "P-1",
                    LearnerReferenceNumber = "100500",
                    EventId = Guid.NewGuid(),
                    LearningAimFundingLineType = "16-18",
                    LearningAimPathwayCode     = 1,
                    LearningAimReference       = "1",
                    LearningAimFrameworkCode   = 1,
                    TransactionType            = TransactionType.Learning,
                    LearnerUln = 1000,
                    LearningAimProgrammeType = 1,
                    LearningAimStandardCode  = 1,
                    Amount = 2000.00m
                }
            };

            providerPaymentsRepository = mocker.Mock <IProviderPaymentsRepository>();
            providerPaymentsRepository
            .Setup(t => t.SavePayment(It.IsAny <PaymentModel>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            providerPaymentsRepository
            .Setup(o => o.GetMonthEndPayments(It.IsAny <CollectionPeriod>(), It.IsAny <long>(),
                                              It.IsAny <CancellationToken>()))
            .ReturnsAsync(payments)
            .Verifiable();

            providerPaymentsRepository
            .Setup(o => o.DeleteOldMonthEndPayment(It.IsAny <CollectionPeriod>(),
                                                   It.IsAny <long>(),
                                                   It.IsAny <DateTime>(),
                                                   It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            receivedProviderEarningsEvent = new ReceivedProviderEarningsEvent
            {
                Ukprn = ukprn,
                JobId = jobId,
                IlrSubmissionDateTime = DateTime.MaxValue,
                CollectionPeriod      = new CollectionPeriodBuilder().WithDate(new DateTime(2018, 2, 1)).Build(),
            };

            ilrSubmittedEventCache = mocker.Mock <IDataCache <ReceivedProviderEarningsEvent> >();
            ilrSubmittedEventCache
            .Setup(o => o.TryGet(ukprn.ToString(), default(CancellationToken)))
            .Returns(Task.FromResult(new ConditionalValue <ReceivedProviderEarningsEvent>(true, receivedProviderEarningsEvent)));

            ilrSubmittedEventCache
            .Setup(o => o.Clear(ukprn.ToString(), default(CancellationToken)))
            .Returns(Task.CompletedTask);

            ilrSubmittedEventCache
            .Setup(o => o.Add(ukprn.ToString(), It.IsAny <ReceivedProviderEarningsEvent>(), default(CancellationToken)))
            .Returns(Task.CompletedTask);

            validateIlrSubmission = mocker.Mock <IValidateIlrSubmission>();
            validateIlrSubmission
            .Setup(o => o.IsLatestIlrPayment(It.IsAny <IlrSubmissionValidationRequest>()))
            .Returns(true);


            ilrSubmissionService = mocker.Create <HandleIlrSubmissionService>();
        }