public async Task TestSfaContributionIsCalculatedForZeroEarningRefunds()
        {
            // arrange
            var  period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 3);
            byte deliveryPeriod = 2;

            var earningEvent = new ApprenticeshipContractType2EarningEvent
            {
                Ukprn = 1,
                SfaContributionPercentage = 0,
                CollectionPeriod          = period,
                CollectionYear            = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Balancing,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>
                        {
                            new EarningPeriod
                            {
                                Period = deliveryPeriod,
                                Amount = 0,
                                PriceEpisodeIdentifier    = "priceEpisodeIdentifier",
                                SfaContributionPercentage = 0
                            }
                        })
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 1,
                    EarningType = EarningType.CoInvested,
                    SfaContributionPercentage = 0.77m,
                },
            };

            var paymentHistoryEntities = new List <PaymentHistoryEntity>();
            var paymentHistory         = new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities.ToArray());

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>())).ReturnsAsync(paymentHistory).Verifiable();
            requiredPaymentService
            .Setup(p => p.GetRequiredPayments(It.Is <Earning>(x => x.Amount == 0), It.Is <List <Payment> >(x => x.Count == 0)))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await act2EarningEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            Assert.IsNotEmpty(actualRequiredPayment);
            Assert.AreEqual(.77m, ((CalculatedRequiredCoInvestedAmount)actualRequiredPayment[0]).SfaContributionPercentage);
        }
        public async Task TestPriceEpisodeIdentifierPickedFromHistoryForRefunds(decimal amount, string priceEpisodeIdentifier)
        {
            // arrange
            var period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 3);
            var deliveryPeriod = (byte)2;

            var earningEvent = new ApprenticeshipContractType2EarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = period,
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Balancing,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = amount,
                                Period = deliveryPeriod,
                                PriceEpisodeIdentifier    = priceEpisodeIdentifier,
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                }
            };

            var paymentHistoryEntities = new PaymentHistoryEntity[0];
            var requiredPayments       = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 1,
                    EarningType = EarningType.CoInvested,
                    SfaContributionPercentage = 0.8m,
                    PriceEpisodeIdentifier    = "2",
                },
            };
            var paymentHistory = new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities);

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>())).ReturnsAsync(paymentHistory).Verifiable();

            requiredPaymentService
            .Setup(p => p.GetRequiredPayments(It.Is <Earning>(x => x.Amount == amount), It.Is <List <Payment> >(x => x.Count == 0)))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await act2EarningEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            Assert.IsNotNull(actualRequiredPayment);
            Assert.AreEqual("2", actualRequiredPayment.First().PriceEpisodeIdentifier);
        }
コード例 #3
0
        public async Task TestHandleZeroEvent()
        {
            // arrange
            var  period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);
            byte deliveryPeriod = 2;

            var earningEvent = new ApprenticeshipContractType2EarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = period,
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Completion,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = 0,
                                Period = deliveryPeriod,
                                PriceEpisodeIdentifier    = null,
                                SfaContributionPercentage = 0m,
                            }
                        })
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>();

            var paymentHistoryEntities = new PaymentHistoryEntity[0];

            var paymentHistory = new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities);

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>())).ReturnsAsync(paymentHistory).Verifiable();
            requiredPaymentService
            .Setup(p => p.GetRequiredPayments(It.Is <Earning>(x => x.Amount == 0), It.Is <List <Payment> >(x => x.Count == 0)))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await act2EarningEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            Assert.IsNotNull(actualRequiredPayment);
            actualRequiredPayment.Should().BeEmpty();
        }
        public async Task TestNoEventProducedWhenZeroToPay()
        {
            // arrange
            var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);

            var earningEvent = new Act2FunctionalSkillEarningsEvent
            {
                Ukprn            = 1,
                CollectionPeriod = period,
                CollectionYear   = period.AcademicYear,
                Learner          = EarningEventDataHelper.CreateLearner(),
                LearningAim      = EarningEventDataHelper.CreateLearningAim(),
                Earnings         = new ReadOnlyCollection <FunctionalSkillEarning>(new List <FunctionalSkillEarning>
                {
                    new FunctionalSkillEarning
                    {
                        Type    = FunctionalSkillType.OnProgrammeMathsAndEnglish,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>
                        {
                            new EarningPeriod
                            {
                                Period = 2,
                                Amount = 100,
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.8m,
                            }
                        })
                    }
                })
            };

            var paymentHistoryEntities = new PaymentHistoryEntity[0];

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities))
            .Verifiable();
            requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.Is <Earning>(x => x.Amount == 100), It.IsAny <List <Payment> >()))
            .Returns(new List <RequiredPayment>())
            .Verifiable();

            // act
            var actualRequiredPayment = await eventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            Assert.AreEqual(0, actualRequiredPayment.Count);
        }
        private PayableEarningEvent GeneratePayableDataLockEvent(short academicYear, byte deliveryPeriod, decimal periodAmount)
        {
            var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(academicYear, deliveryPeriod);

            return(new PayableEarningEvent
            {
                Ukprn = 1,
                CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(academicYear, deliveryPeriod),
                CollectionYear = period.AcademicYear,
                Learner = EarningEventDataHelper.CreateLearner(),
                LearningAim = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type = OnProgrammeEarningType.Completion,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = periodAmount,
                                Period = period.Period,
                                SfaContributionPercentage = 0.9m,
                            },
                        })
                    }
                },
                PriceEpisodes = new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        Identifier = "1",
                        EffectiveTotalNegotiatedPriceStartDate = DateTime.UtcNow,
                        PlannedEndDate = DateTime.UtcNow,
                        ActualEndDate = DateTime.UtcNow,
                        CompletionAmount = 350M,
                        InstalmentAmount = 200M,
                        NumberOfInstalments = 16,
                        FundingLineType = "19+ Apprenticeship Non-Levy Contract (procured)"
                    }
                }
            });
        }
        public async Task TestNormalEvent()
        {
            // arrange
            var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);

            var earningEvent = new PayableEarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Learning,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = 100,
                                Period = period.Period,
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            },
                            new EarningPeriod
                            {
                                Amount = 200,
                                Period = (byte)(period.Period + 1),
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                },
                PriceEpisodes = new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        LearningAimSequenceNumber = 2,
                        Identifier = "2"
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 100,
                    EarningType = EarningType.Levy,
                },
            };

            var paymentHistoryEntities = new[] { new PaymentHistoryEntity
                                                 {
                                                     CollectionPeriod  = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                                                     DeliveryPeriod    = 2,
                                                     LearnAimReference = earningEvent.LearningAim.Reference,
                                                     TransactionType   = (int)OnProgrammeEarningType.Learning
                                                 } };

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities))
            .Verifiable();
            requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >()))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await processor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            actualRequiredPayment.Should().HaveCount(1);
            actualRequiredPayment.First().LearningAimSequenceNumber.Should().Be(2);
        }
        public async Task TestGeneratesValidRequiredEventFundingLineType()
        {
            // arrange
            var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);

            var earningEvent = new PayableEarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Learning,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = 100,
                                Period = period.Period,
                                PriceEpisodeIdentifier    = "1",
                                SfaContributionPercentage = 0.9m,
                            },
                            new EarningPeriod
                            {
                                Amount = 200,
                                Period = (byte)(period.Period + 1),
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                },
                PriceEpisodes = new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        Identifier = "1",
                        EffectiveTotalNegotiatedPriceStartDate = DateTime.UtcNow,
                        PlannedEndDate      = DateTime.UtcNow,
                        ActualEndDate       = DateTime.UtcNow,
                        CompletionAmount    = 100M,
                        InstalmentAmount    = 200M,
                        NumberOfInstalments = 16,
                        FundingLineType     = "19+ Apprenticeship Non-Levy Contract (procured)"
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 100,
                    EarningType = EarningType.Levy,
                },
            };

            var paymentHistoryEntities = new[] { new PaymentHistoryEntity
                                                 {
                                                     CollectionPeriod  = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                                                     DeliveryPeriod    = 2,
                                                     LearnAimReference = earningEvent.LearningAim.Reference,
                                                     TransactionType   = (int)OnProgrammeEarningType.Learning
                                                 } };

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities))
            .Verifiable();
            requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >()))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await processor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            actualRequiredPayment.Should().HaveCount(1);
            actualRequiredPayment[0].LearningAim.Should().NotBeNull();
            actualRequiredPayment[0].LearningAim.FundingLineType.Should().Be(earningEvent.PriceEpisodes[0].FundingLineType);
        }
        public async Task When_HoldingBackCompletionPayment_Then_Log_a_Custom_Event()
        {
            // arrange
            var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);

            var priceEpisodes = new List <PriceEpisode>(new []
            {
                new PriceEpisode
                {
                    Identifier                      = "1",
                    EmployerContribution            = 100,
                    CompletionHoldBackExemptionCode = 0
                },
                new PriceEpisode
                {
                    Identifier                      = "2",
                    EmployerContribution            = 1,
                    CompletionHoldBackExemptionCode = 2
                }
            });


            var earningEvent = new PayableEarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                PriceEpisodes       = priceEpisodes,
                OnProgrammeEarnings = new List <OnProgrammeEarning>
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Completion,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>
                        {
                            new EarningPeriod
                            {
                                Amount = 200,
                                Period = period.Period,
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 100,
                    EarningType = EarningType.Levy,
                },
            };

            var paymentHistoryEntities = new[] { new PaymentHistoryEntity {
                                                     CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2), DeliveryPeriod = 2, LearnAimReference = "ZPROG001"
                                                 } };
            var key = new ApprenticeshipKey();

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(k => k == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities))
            .Verifiable();
            requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >())).Returns(requiredPayments).Verifiable();
            apprenticeshipKeyProviderMock.Setup(a => a.GetCurrentKey()).Returns(key).Verifiable();
            paymentHistoryRepositoryMock.Setup(repo => repo.GetEmployerCoInvestedPaymentHistoryTotal(key, It.IsAny <CancellationToken>())).ReturnsAsync(11).Verifiable();
            holdingBackCompletionPaymentServiceMock.Setup(h => h.ShouldHoldBackCompletionPayment(11, priceEpisodes[1])).Returns(true).Verifiable();

            // act
            var actualRequiredPayment = await processor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            actualRequiredPayment.Should().HaveCount(1);

            mocker.Mock <ITelemetry>().Verify(t => t.TrackEvent("Holding Back Completion Payment",
                                                                It.Is <Dictionary <string, string> >(d =>
                                                                                                     d.Contains(new KeyValuePair <string, string>("Expected Employer Contribution", "2")) &&
                                                                                                     d.Contains(new KeyValuePair <string, string>("Reported Employer Contribution", "1"))),
                                                                It.IsAny <Dictionary <string, double> >()));
        }
        public async Task Matching_Historic_Aim_To_Current_Aim_Should_Be_Case_InSensitive_On_Aim_Reference()
        {
            // arrange
            var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);

            var earningEvent = new PayableEarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Learning,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = 100,
                                Period = period.Period,
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>
            {
            };

            earningEvent.LearningAim.Reference = "ZPROG001";
            var paymentHistoryEntities = new[] { new PaymentHistoryEntity
                                                 {
                                                     CollectionPeriod          = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                                                     DeliveryPeriod            = period.Period,
                                                     LearnAimReference         = earningEvent.LearningAim.Reference.ToLower(),
                                                     TransactionType           = (int)OnProgrammeEarningType.Learning,
                                                     Amount                    = 100,
                                                     SfaContributionPercentage = 0.9m,
                                                     PriceEpisodeIdentifier    = "2"
                                                 } };

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities))
            .Verifiable();
            requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >()))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await processor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            actualRequiredPayment.Should().HaveCount(0);
            //Ideally this logic should be moved into a specific testable class
            requiredPaymentsService.Verify(x => x.GetRequiredPayments(It.IsAny <Earning>(), It.Is <List <Payment> >(lst => lst.Count == 1 && lst.Any(p => p.LearnAimReference == "zprog001"))));
        }
コード例 #10
0
        public async Task TestHandleNormalEvent()
        {
            // arrange
            var  period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);
            byte deliveryPeriod = 2;

            var earningEvent = new ApprenticeshipContractType2EarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = period,
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    new OnProgrammeEarning
                    {
                        Type    = OnProgrammeEarningType.Learning,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>()
                        {
                            new EarningPeriod
                            {
                                Amount = 100,
                                Period = deliveryPeriod,
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                },
                PriceEpisodes = new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        LearningAimSequenceNumber = 2,
                        Identifier = "2"
                    }
                }
            };

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 1,
                    EarningType = EarningType.CoInvested,
                },
            };

            var paymentHistoryEntities = new[] { new PaymentHistoryEntity
                                                 {
                                                     CollectionPeriod  = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                                                     DeliveryPeriod    = 2,
                                                     LearnAimReference = earningEvent.LearningAim.Reference,
                                                     TransactionType   = (int)OnProgrammeEarningType.Learning
                                                 } };

            var paymentHistory = new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities);

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>())).ReturnsAsync(paymentHistory).Verifiable();
            requiredPaymentService
            .Setup(p => p.GetRequiredPayments(It.Is <Earning>(x => x.Amount == 100), It.Is <List <Payment> >(x => x.Count == 1)))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await act2EarningEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            Assert.IsNotNull(actualRequiredPayment);
            Assert.AreEqual(1, actualRequiredPayment.Count);
            Assert.AreEqual(1, actualRequiredPayment.First().AmountDue);
            Assert.AreEqual(earningEvent.LearningAim.Reference, actualRequiredPayment.First().LearningAim.Reference);
            Assert.AreEqual(2, actualRequiredPayment.First().LearningAimSequenceNumber);
        }
コード例 #11
0
        public async Task TestPriceEpisodeIdentifierPickedFromHistoryForRefunds2(ApprenticeshipEmployerType employerType, OnProgrammeEarning earning, PaymentHistoryEntity previousPayment)
        {
            // arrange
            var period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 3);
            var deliveryPeriod = (byte)2;

            var earningEvent = new ApprenticeshipContractType2EarningEvent
            {
                Ukprn               = 1,
                CollectionPeriod    = period,
                CollectionYear      = period.AcademicYear,
                Learner             = EarningEventDataHelper.CreateLearner(),
                LearningAim         = EarningEventDataHelper.CreateLearningAim(),
                OnProgrammeEarnings = new List <OnProgrammeEarning>()
                {
                    earning,
                },
                PriceEpisodes = new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        LearningAimSequenceNumber = 1234
                    }
                }
            };

            earning.Periods[0].ApprenticeshipEmployerType
                  = previousPayment.ApprenticeshipEmployerType
                  = employerType;

            earning.Type              = OnProgrammeEarningType.Balancing;
            earning.Periods           = earning.Periods.Take(1).ToList().AsReadOnly();
            earning.Periods[0].Period = deliveryPeriod;
            earning.Periods[0].Amount = previousPayment.Amount - 1;

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = -1,
                    EarningType = EarningType.CoInvested,
                    ApprenticeshipEmployerType   = employerType,
                    ApprenticeshipId             = previousPayment.ApprenticeshipId,
                    ApprenticeshipPriceEpisodeId = previousPayment.ApprenticeshipPriceEpisodeId,
                },
            };

            previousPayment.LearnAimReference = earningEvent.LearningAim.Reference;
            previousPayment.DeliveryPeriod    = deliveryPeriod;
            previousPayment.TransactionType   = (int)earning.Type;

            var paymentHistory = ConditionalValue.WithArray(previousPayment);

            paymentHistoryCacheMock
            .Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(paymentHistory);

            requiredPaymentService
            .Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >()))
            .Returns(requiredPayments);

            // act
            var actualRequiredPayment =
                await act2EarningEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            actualRequiredPayment.Should().BeEquivalentTo(
                new
            {
                previousPayment.ApprenticeshipEmployerType,
                previousPayment.ApprenticeshipId,
                previousPayment.ApprenticeshipPriceEpisodeId,
            });
        }
        public async Task TestHandleNormalEvent()
        {
            // arrange
            var  period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2);
            byte deliveryPeriod = 2;

            var earningEvent = new Act2FunctionalSkillEarningsEvent
            {
                Ukprn            = 1,
                CollectionPeriod = period,
                CollectionYear   = period.AcademicYear,
                Learner          = EarningEventDataHelper.CreateLearner(),
                LearningAim      = EarningEventDataHelper.CreateLearningAim(),
                Earnings         = new ReadOnlyCollection <FunctionalSkillEarning>(new List <FunctionalSkillEarning>
                {
                    new FunctionalSkillEarning
                    {
                        Type    = FunctionalSkillType.BalancingMathsAndEnglish,
                        Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod>
                        {
                            new EarningPeriod
                            {
                                Period = deliveryPeriod,
                                Amount = 100,
                                PriceEpisodeIdentifier    = "2",
                                SfaContributionPercentage = 0.9m,
                            }
                        })
                    }
                })
            };

            var requiredPayments = new List <RequiredPayment>
            {
                new RequiredPayment
                {
                    Amount      = 100,
                    EarningType = EarningType.Incentive,
                    SfaContributionPercentage = 0.9m,
                    PriceEpisodeIdentifier    = "2",
                },
            };

            var paymentHistoryEntities = new[] { new PaymentHistoryEntity
                                                 {
                                                     CollectionPeriod  = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2),
                                                     DeliveryPeriod    = 2,
                                                     LearnAimReference = earningEvent.LearningAim.Reference,
                                                     TransactionType   = (int)FunctionalSkillType.BalancingMathsAndEnglish
                                                 } };

            paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(key => key == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities))
            .Verifiable();

            requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.Is <Earning>(x => x.Amount == 100), It.IsAny <List <Payment> >()))
            .Returns(requiredPayments)
            .Verifiable();

            // act
            var actualRequiredPayment = await eventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None);

            // assert
            Assert.IsNotNull(actualRequiredPayment);
            Assert.AreEqual(1, actualRequiredPayment.Count);
            Assert.AreEqual(100, actualRequiredPayment.First().AmountDue);
            Assert.AreEqual(earningEvent.LearningAim.Reference, actualRequiredPayment.First().LearningAim.Reference);
            Assert.AreEqual("2", actualRequiredPayment.First().PriceEpisodeIdentifier);
        }