private void PopulateCommonProperties(FundingSourcePaymentEvent expectedEvent) { expectedEvent.FundingSourceType = FundingSourceType.Levy; expectedEvent.ApprenticeshipId = 12; expectedEvent.Learner = new Learner { ReferenceNumber = "001", Uln = 1234567890 }; expectedEvent.JobId = 1; expectedEvent.ContractType = ContractType.Act1; expectedEvent.Ukprn = 10000; expectedEvent.AmountDue = 55; expectedEvent.TransactionType = TransactionType.Learning; expectedEvent.LearningAim = new LearningAim { FrameworkCode = 403 }; expectedEvent.DeliveryPeriod = 1; expectedEvent.IlrSubmissionDateTime = DateTime.Today; expectedEvent.RequiredPaymentEventId = requiredPaymentEvent.EventId; expectedEvent.PriceEpisodeIdentifier = "1819-P01"; expectedEvent.SfaContributionPercentage = .9m; expectedEvent.CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 1); expectedEvent.AccountId = 1000000; expectedEvent.EarningEventId = requiredPaymentEvent.EarningEventId; expectedEvent.ApprenticeshipEmployerType = requiredPaymentEvent.ApprenticeshipEmployerType; }
private PaymentModel ToPayment(HistoricalPayment payment, FundingSourceType fundingSource) { var testSessionLearner = TestSession.Learners.FirstOrDefault(l => l.LearnerIdentifier == payment.LearnerId) ?? TestSession.Learner; Assert.IsNotNull(testSessionLearner, $"Test session learner with learner id: '{payment.LearnerId}' not found."); return(new PaymentModel { EventId = Guid.NewGuid(), FundingSourceEventId = Guid.NewGuid(), Ukprn = TestSession.Ukprn, LearnerReferenceNumber = testSessionLearner.LearnRefNumber, LearnerUln = testSessionLearner.Uln, PriceEpisodeIdentifier = payment.PriceEpisodeIdentifier, Amount = GetFundingAmount(payment.Amount, fundingSource), CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(AcademicYear, CollectionPeriod), DeliveryPeriod = payment.DeliveryPeriod, LearningAimReference = testSessionLearner.Course.LearnAimRef, LearningAimProgrammeType = testSessionLearner.Course.ProgrammeType, LearningAimStandardCode = testSessionLearner.Course.StandardCode, LearningAimFrameworkCode = testSessionLearner.Course.FrameworkCode, LearningAimPathwayCode = testSessionLearner.Course.PathwayCode, LearningAimFundingLineType = testSessionLearner.Course.FundingLineType, FundingSource = fundingSource, ContractType = Payments.Model.Core.Entities.ContractType.Act2, SfaContributionPercentage = SfaContributionPercentage, JobId = TestSession.JobId, TransactionType = (TransactionType)payment.Type, IlrSubmissionDateTime = TestSession.IlrSubmissionTime }); }
public void TestMultiplePaymentsFoundWithLessPaidThanDue() { // arrange paymentDueProcessor = new PaymentDueProcessor(); var history = new List <Payment> { new Payment { Amount = 1, DeliveryPeriod = 2, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2), }, new Payment { Amount = 3, DeliveryPeriod = 2, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2), } }; // act var amount = paymentDueProcessor.CalculateRequiredPaymentAmount(5, history); // assert Assert.AreEqual(1, amount); }
public void Setup() { requiredCoInvestedAmount = new CalculatedRequiredCoInvestedAmount { AmountDue = 1000.00m, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 1), DeliveryPeriod = 1, EventTime = DateTime.UtcNow, JobId = 1, Learner = new Learner { ReferenceNumber = "001", Uln = 1234567890 }, OnProgrammeEarningType = OnProgrammeEarningType.Learning, LearningAim = new LearningAim { FrameworkCode = 403 }, PriceEpisodeIdentifier = "1819-P01", SfaContributionPercentage = 0.9m, Ukprn = 10000, AccountId = 1000000, ContractType = ContractType.Act2, ApprenticeshipEmployerType = ApprenticeshipEmployerType.Levy, }; mapperConfiguration = AutoMapperConfigurationFactory.CreateMappingConfig(); autoMapper = mapperConfiguration.CreateMapper(); coInvestedFundingMapper = new CoInvestedFundingSourcePaymentEventMapper(autoMapper); }
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); }
public void ValidateMap() { var payment = new PaymentHistoryEntity { CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 11), DeliveryPeriod = 10 }; mapper.Map <PaymentHistoryEntity, Payment>(payment); }
private void MapCommon(RequiredPayment requiredPayment, PeriodisedRequiredPaymentEvent paymentEvent) { paymentEvent.Learner = TestSession.Learner.ToLearner(); paymentEvent.Ukprn = TestSession.Ukprn; paymentEvent.AmountDue = requiredPayment.Amount; paymentEvent.JobId = TestSession.JobId; paymentEvent.EventTime = DateTimeOffset.UtcNow; paymentEvent.CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(AcademicYear, CollectionPeriod); paymentEvent.DeliveryPeriod = requiredPayment.DeliveryPeriod; paymentEvent.IlrSubmissionDateTime = TestSession.IlrSubmissionTime; paymentEvent.LearningAim = TestSession.Learner.Course.ToLearningAim(); paymentEvent.PriceEpisodeIdentifier = requiredPayment.PriceEpisodeIdentifier; }
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); }
public void TestOnePaymentFound() { // arrange var history = new List <Payment> { new Payment { Amount = 2, DeliveryPeriod = 2, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2), } }; // act var amount = paymentDueProcessor.CalculateRequiredPaymentAmount(2, history); // assert Assert.AreEqual(0, amount); }
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)" } } }); }
private ApprenticeshipContractTypeEarningsEvent CreateEarningEvent(IGrouping <string, OnProgrammeEarning> group) { var earningEvent = ContractType == ContractType.Act1 ? (ApprenticeshipContractTypeEarningsEvent) new ApprenticeshipContractType1EarningEvent() : new ApprenticeshipContractType2EarningEvent(); var testSessionLearner = TestSession.Learners.FirstOrDefault(l => l.LearnerIdentifier == group.Key) ?? TestSession.Learner; earningEvent.Learner = testSessionLearner.ToLearner(); earningEvent.Ukprn = TestSession.Ukprn; earningEvent.SfaContributionPercentage = SfaContributionPercentage; earningEvent.CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(AcademicYear, CollectionPeriod); earningEvent.CollectionYear = AcademicYear; earningEvent.JobId = TestSession.JobId; earningEvent.LearningAim = testSessionLearner.Course.ToLearningAim(); var onProgrammeEarnings = new List <Payments.Model.Core.OnProgramme.OnProgrammeEarning>(); foreach (var learnerEarning in group) { var onProgrammeEarning = new Payments.Model.Core.OnProgramme.OnProgrammeEarning { Type = learnerEarning.Type, Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod> { new EarningPeriod { Amount = learnerEarning.Amount, Period = learnerEarning.DeliveryPeriod, PriceEpisodeIdentifier = learnerEarning.PriceEpisodeIdentifier } }) }; onProgrammeEarnings.Add(onProgrammeEarning); } earningEvent.OnProgrammeEarnings = onProgrammeEarnings; return(earningEvent); }
public async Task TestRefundedCompletionPaymentShouldNotBeHeldBack() { // arrange var earningEvent = GeneratePayableDataLockEvent(1920, 2, 0m); var paymentHistoryEntities = new[] { new PaymentHistoryEntity { CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1920, 2), DeliveryPeriod = 2, LearnAimReference = earningEvent.LearningAim.Reference, TransactionType = (int)OnProgrammeEarningType.Completion, Amount = 350 } }; var requiredPayments = new List <RequiredPayment> { new RequiredPayment { Amount = -350, EarningType = EarningType.Levy, }, }; 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().AmountDue.Should().Be(-350); }
public void Setup() { requiredPaymentEvent = new CalculatedRequiredLevyAmount { AmountDue = 1000.00m, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 1), DeliveryPeriod = 1, EventTime = DateTime.UtcNow, JobId = 1, Learner = new Learner { ReferenceNumber = "001", Uln = 1234567890 }, OnProgrammeEarningType = OnProgrammeEarningType.Learning, LearningAim = new LearningAim { FrameworkCode = 403 }, PriceEpisodeIdentifier = "1819-P01", SfaContributionPercentage = 0.9m, Ukprn = 10000, AgreementId = "11", Priority = 13, EventId = Guid.NewGuid(), AccountId = 1000000, IlrSubmissionDateTime = DateTime.Today, EarningEventId = Guid.NewGuid(), ContractType = ContractType.Act1, ApprenticeshipEmployerType = ApprenticeshipEmployerType.Levy, ApprenticeshipId = 12, }; mapperConfiguration = AutoMapperConfigurationFactory.CreateMappingConfig(); autoMapper = mapperConfiguration.CreateMapper(); }
private async Task SendMonthEndEvent() { MonthEndJobId = TestSession.GenerateId(); Console.WriteLine($"Month end job id: {MonthEndJobId}"); var monthEndCommand = new ProcessProviderMonthEndCommand { Ukprn = TestSession.Ukprn, JobId = MonthEndJobId, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(AcademicYear, CollectionPeriod), }; await CreateJob(DateTimeOffset.UtcNow, new List <GeneratedMessage> { new GeneratedMessage { StartTime = monthEndCommand.RequestTime, MessageName = monthEndCommand.GetType().FullName, MessageId = monthEndCommand.CommandId } }, JobType.ComponentAcceptanceTestMonthEndJob); await MessageSession.Send(monthEndCommand).ConfigureAwait(false); }
private static PayableEarningEvent CreatePayableEarning() { return(new PayableEarningEvent { EventId = Guid.NewGuid(), EarningEventId = Guid.NewGuid(), AgreementId = "103", CollectionYear = 1819, Learner = new Learner { ReferenceNumber = "R", Uln = 10 }, Ukprn = 20, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 7), LearningAim = new LearningAim { FundingLineType = "flt", PathwayCode = 3, StandardCode = 4, ProgrammeType = 5, FrameworkCode = 6, Reference = "7" }, JobId = 8, IlrSubmissionDateTime = DateTime.Today, OnProgrammeEarnings = new List <OnProgrammeEarning> { new OnProgrammeEarning { Type = OnProgrammeEarningType.Learning, Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod> { new EarningPeriod { Period = 1, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 2, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 3, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 4, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 5, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 6, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 7, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 8, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 9, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 10, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 11, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, new EarningPeriod { Period = 12, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = .9m, ApprenticeshipId = 102, AccountId = 101, ApprenticeshipPriceEpisodeId = 105, Priority = 104, AgreedOnDate = DateTime.Today }, }) } } }); }
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")))); }
public async Task WhenCallingGetYearToDatePayments_WithMultipleProviders_TheYtdPaymentsAreCorrect() { var mocker = AutoMock.GetLoose(); var payments = new List <PaymentModel> { new PaymentModel { Ukprn = 1, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(2021, 1), ContractType = ContractType.Act1, Amount = 1000, }, new PaymentModel { Ukprn = 1, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(2021, 1), ContractType = ContractType.Act2, Amount = 2000, }, new PaymentModel { Ukprn = 2, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(2021, 1), ContractType = ContractType.Act1, Amount = 10000, }, new PaymentModel { Ukprn = 2, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(2021, 1), ContractType = ContractType.Act2, Amount = 20000, }, }; using (var context = new InMemoryMetricsQueryDataContext()) { var factory = mocker.Mock <IMetricsQueryDataContextFactory>(); factory.Setup(x => x.Create()) .Returns(context); var sut = mocker.Create <PeriodEndMetricsRepository>(); foreach (var payment in payments) { await context.AddAsync(payment); } await context.SaveChangesAsync(); var actual = await sut.GetYearToDatePayments(2021, 2, CancellationToken.None); actual.Where(x => x.Ukprn == 1).Should().HaveCount(1); actual.Where(x => x.Ukprn == 2).Should().HaveCount(1); actual.Where(x => x.Ukprn == 3).Should().BeEmpty(); actual.Single(x => x.Ukprn == 1).Total.Should().Be(3000); actual.Single(x => x.Ukprn == 2).Total.Should().Be(30000); } }
public void PeriodIsCorrect(short academicYear, byte period, byte expected) { var actual = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(academicYear, period); actual.Period.Should().Be(expected); }
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); }
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 EarningsEventProfile() { CreateMap <IntermediateLearningAim, EarningEvent>() .Include <IntermediateLearningAim, ApprenticeshipContractTypeEarningsEvent>() .Include <IntermediateLearningAim, FunctionalSkillEarningsEvent>() .Include <IntermediateLearningAim, Act1FunctionalSkillEarningsEvent>() .Include <IntermediateLearningAim, Act2FunctionalSkillEarningsEvent>() .ForMember(destinationMember => destinationMember.PriceEpisodes, opt => opt.MapFrom(source => source.PriceEpisodes)) .ForMember(destinationMember => destinationMember.LearningAim, opt => opt.MapFrom(source => source.Aims)) .ForMember(destinationMember => destinationMember.CollectionYear, opt => opt.MapFrom(source => source.AcademicYear)) .ForMember(destinationMember => destinationMember.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(destinationMember => destinationMember.JobId, opt => opt.MapFrom(source => source.JobId)) .ForMember(destinationMember => destinationMember.EventTime, opt => opt.Ignore()) .ForMember(destinationMember => destinationMember.EventId, opt => opt.Ignore()) .ForMember(dest => dest.CollectionPeriod, opt => opt.ResolveUsing(src => CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(src.AcademicYear, (byte)src.CollectionPeriod))) .ForMember(dest => dest.LearningAim, opt => opt.MapFrom(source => source)) ; CreateMap <IntermediateLearningAim, ApprenticeshipContractTypeEarningsEvent>() .Include <IntermediateLearningAim, ApprenticeshipContractType1EarningEvent>() .Include <IntermediateLearningAim, ApprenticeshipContractType2EarningEvent>() .ForMember(destinationMember => destinationMember.OnProgrammeEarnings, opt => opt.ResolveUsing <OnProgrammeEarningValueResolver>()) .ForMember(destinationMember => destinationMember.IncentiveEarnings, opt => opt.ResolveUsing <IncentiveEarningValueResolver>()) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(src => src.Aims.Min(aim => aim.LearningDeliveryValues.LearnStartDate))) .Ignore(dest => dest.SfaContributionPercentage) ; CreateMap <IntermediateLearningAim, ApprenticeshipContractType1EarningEvent>() .ForMember(dest => dest.AgreementId, opt => opt.MapFrom(aim => aim.PriceEpisodes[0].PriceEpisodeValues.PriceEpisodeAgreeId)) ; CreateMap <IntermediateLearningAim, ApprenticeshipContractType2EarningEvent>(); CreateMap <IntermediateLearningAim, Act1FunctionalSkillEarningsEvent>(); CreateMap <IntermediateLearningAim, Act2FunctionalSkillEarningsEvent>(); CreateMap <IntermediateLearningAim, FunctionalSkillEarningsEvent>() .Include <IntermediateLearningAim, Act1FunctionalSkillEarningsEvent>() .Include <IntermediateLearningAim, Act2FunctionalSkillEarningsEvent>() .ForMember(destinationMember => destinationMember.Earnings, opt => opt.ResolveUsing <FunctionalSkillsEarningValueResolver>()) .ForMember(destinationMember => destinationMember.StartDate, opt => opt.MapFrom(source => source.Aims.Min(aim => aim.LearningDeliveryValues.LearnStartDate))) .Ignore(x => x.ContractType) ; CreateMap <ApprenticeshipContractType1EarningEvent, ApprenticeshipContractType1RedundancyEarningEvent>() .Ignore(x => x.EventId); CreateMap <ApprenticeshipContractType2EarningEvent, ApprenticeshipContractType2RedundancyEarningEvent>() .Ignore(x => x.EventId); CreateMap <Act1FunctionalSkillEarningsEvent, Act1RedundancyFunctionalSkillEarningsEvent>() .Ignore(x => x.EventId); CreateMap <Act2FunctionalSkillEarningsEvent, Act2RedundancyFunctionalSkillEarningsEvent>() .Ignore(x => x.EventId); CreateMap <FunctionalSkillEarning, FunctionalSkillEarning>(); CreateMap <OnProgrammeEarning, OnProgrammeEarning>(); CreateMap <IncentiveEarning, IncentiveEarning>(); CreateMap <EarningPeriod, EarningPeriod>(); CreateMap <FM36Learner, Learner>() .ForMember(dest => dest.ReferenceNumber, opt => opt.MapFrom(source => source.LearnRefNumber)) .ForMember(dest => dest.Uln, opt => opt.MapFrom(source => source.ULN)); CreateMap <IntermediateLearningAim, LearningAim>() .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.Aims.First().LearningDeliveryValues.PwayCode)) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.Aims.First().LearningDeliveryValues.FworkCode)) .Ignore(x => x.FundingLineType) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.Aims.First().LearningDeliveryValues.ProgType)) .ForMember(dest => dest.Reference, opt => opt.MapFrom(source => source.Aims.First().LearningDeliveryValues.LearnAimRef)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.Aims.First().LearningDeliveryValues.StdCode)) .ForMember(dest => dest.SequenceNumber, opt => opt.MapFrom(source => source.Aims.First().AimSeqNumber)) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(source => source.Aims.Min(aim => aim.LearningDeliveryValues.LearnStartDate))) ; CreateMap <IntermediateLearningAim, SubmittedLearnerAimModel>() .ForMember(model => model.LearnerReferenceNumber, opt => opt.MapFrom(aim => aim.Learner.LearnRefNumber)) .ForMember(model => model.LearningAimFrameworkCode, opt => opt.MapFrom(aim => aim.Aims.First().LearningDeliveryValues.FworkCode)) .ForMember(model => model.LearningAimPathwayCode, opt => opt.MapFrom(aim => aim.Aims.First().LearningDeliveryValues.PwayCode)) .ForMember(model => model.LearningAimProgrammeType, opt => opt.MapFrom(aim => aim.Aims.First().LearningDeliveryValues.ProgType)) .ForMember(model => model.LearningAimStandardCode, opt => opt.MapFrom(aim => aim.Aims.First().LearningDeliveryValues.StdCode)) .ForMember(model => model.LearningAimReference, opt => opt.MapFrom(aim => aim.Aims.First().LearningDeliveryValues.LearnAimRef)) .ForMember(model => model.ContractType, opt => opt.MapFrom(aim => aim.ContractType)) .Ignore(model => model.Id) ; CreateMap <ESFA.DC.ILR.FundingService.FM36.FundingOutput.Model.Output.PriceEpisode, Model.Core.PriceEpisode>() .ForMember(dest => dest.Identifier, opt => opt.MapFrom(source => source.PriceEpisodeIdentifier)) .ForMember(dest => dest.TotalNegotiatedPrice1, opt => opt.MapFrom(source => source.PriceEpisodeValues.TNP1)) .ForMember(dest => dest.TotalNegotiatedPrice2, opt => opt.MapFrom(source => source.PriceEpisodeValues.TNP2)) .ForMember(dest => dest.TotalNegotiatedPrice3, opt => opt.MapFrom(source => source.PriceEpisodeValues.TNP3)) .ForMember(dest => dest.TotalNegotiatedPrice4, opt => opt.MapFrom(source => source.PriceEpisodeValues.TNP4)) .ForMember(dest => dest.AgreedPrice, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeTotalTNPPrice)) .ForMember(dest => dest.CourseStartDate, opt => opt.MapFrom(source => source.PriceEpisodeValues.EpisodeStartDate)) .ForMember(dest => dest.EffectiveTotalNegotiatedPriceStartDate, opt => opt.MapFrom(source => source.PriceEpisodeValues.EpisodeEffectiveTNPStartDate)) .ForMember(dest => dest.PlannedEndDate, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodePlannedEndDate)) .ForMember(dest => dest.ActualEndDate, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeActualEndDate)) .ForMember(dest => dest.NumberOfInstalments, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodePlannedInstalments)) //TODO: should this be actual if there is an actual end date? .ForMember(dest => dest.InstalmentAmount, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeInstalmentValue)) .ForMember(dest => dest.CompletionAmount, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeCompletionElement)) .ForMember(dest => dest.Completed, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeCompleted)) .ForMember(dest => dest.EmployerContribution, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeCumulativePMRs)) .ForMember(dest => dest.CompletionHoldBackExemptionCode, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeCompExemCode)) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(source => source.PriceEpisodeValues.EpisodeStartDate)) .ForMember(dest => dest.FundingLineType, opt => opt.MapFrom(source => source.PriceEpisodeValues.PriceEpisodeFundLineType)) ; }
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); }
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); }
private static PayableFunctionalSkillEarningEvent CreatePayableFunctionalSkillEarningsEvent() { return(new PayableFunctionalSkillEarningEvent { CollectionYear = 1819, Learner = new Learner { ReferenceNumber = "R", Uln = uln }, Ukprn = ukprn, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 7), LearningAim = new LearningAim { FundingLineType = "flt", PathwayCode = 3, StandardCode = 4, ProgrammeType = 5, FrameworkCode = 6, Reference = "7" }, JobId = 8, IlrSubmissionDateTime = DateTime.Today, StartDate = DateTime.Today.AddDays(-10), Earnings = new ReadOnlyCollection <FunctionalSkillEarning>(new List <FunctionalSkillEarning> { new FunctionalSkillEarning { Type = FunctionalSkillType.OnProgrammeMathsAndEnglish, Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod> { new EarningPeriod { Period = 1, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 2, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 3, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 4, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 5, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 6, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 7, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 8, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 9, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 10, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 11, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, new EarningPeriod { Period = 12, Amount = 100, PriceEpisodeIdentifier = "1", SfaContributionPercentage = 1 }, }) } }) }); }
public ProviderPaymentsProfile() { CreateMap <FundingSourcePaymentEvent, ProviderPaymentEventModel>() .Include <EmployerCoInvestedFundingSourcePaymentEvent, ProviderPaymentEventModel>() .Include <SfaCoInvestedFundingSourcePaymentEvent, ProviderPaymentEventModel>() .Include <SfaFullyFundedFundingSourcePaymentEvent, ProviderPaymentEventModel>() .Include <LevyFundingSourcePaymentEvent, ProviderPaymentEventModel>() .Include <TransferFundingSourcePaymentEvent, ProviderPaymentEventModel>() .ForMember(dest => dest.EventId, opt => opt.ResolveUsing(src => Guid.NewGuid())) .ForMember(dest => dest.FundingSourceId, opt => opt.MapFrom(source => source.EventId)) .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.CollectionPeriod, opt => opt.MapFrom(source => source.CollectionPeriod.Period)) .ForMember(dest => dest.AcademicYear, opt => opt.MapFrom(source => source.CollectionPeriod.AcademicYear)) .ForMember(dest => dest.DeliveryPeriod, opt => opt.MapFrom(source => source.DeliveryPeriod)) .ForMember(dest => dest.Amount, opt => opt.MapFrom(source => source.AmountDue)) .ForMember(dest => dest.ContractType, opt => opt.MapFrom(source => source.ContractType)) .ForMember(dest => dest.FundingSource, opt => opt.MapFrom(source => source.FundingSourceType)) .ForMember(dest => dest.IlrSubmissionDateTime, opt => opt.MapFrom(source => source.IlrSubmissionDateTime)) .ForMember(dest => dest.JobId, opt => opt.MapFrom(source => source.JobId)) .ForMember(dest => dest.LearnerUln, opt => opt.MapFrom(source => source.Learner.Uln)) .ForMember(dest => dest.LearnerReferenceNumber, opt => opt.MapFrom(source => source.Learner.ReferenceNumber)) .ForMember(dest => dest.LearningAimFrameworkCode, opt => opt.MapFrom(source => source.LearningAim.FrameworkCode)) .ForMember(dest => dest.LearningAimFundingLineType, opt => opt.MapFrom(source => source.LearningAim.FundingLineType)) .ForMember(dest => dest.LearningAimPathwayCode, opt => opt.MapFrom(source => source.LearningAim.PathwayCode)) .ForMember(dest => dest.LearningAimProgrammeType, opt => opt.MapFrom(source => source.LearningAim.ProgrammeType)) .ForMember(dest => dest.LearningAimReference, opt => opt.MapFrom(source => source.LearningAim.Reference)) .ForMember(dest => dest.LearningAimStandardCode, opt => opt.MapFrom(source => source.LearningAim.StandardCode)) .ForMember(dest => dest.PriceEpisodeIdentifier, opt => opt.MapFrom(source => source.PriceEpisodeIdentifier)) .ForMember(dest => dest.SfaContributionPercentage, opt => opt.MapFrom(source => source.SfaContributionPercentage)) .ForMember(dest => dest.TransactionType, opt => opt.MapFrom(source => source.TransactionType)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.AgreementId, opt => opt.Ignore()) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(source => source.StartDate)) .ForMember(dest => dest.PlannedEndDate, opt => opt.MapFrom(source => source.PlannedEndDate)) .ForMember(dest => dest.ActualEndDate, opt => opt.MapFrom(source => source.ActualEndDate)) .ForMember(dest => dest.CompletionStatus, opt => opt.MapFrom(source => source.CompletionStatus)) .ForMember(dest => dest.CompletionAmount, opt => opt.MapFrom(source => source.CompletionAmount)) .ForMember(dest => dest.InstalmentAmount, opt => opt.MapFrom(source => source.InstalmentAmount)) .ForMember(dest => dest.NumberOfInstalments, opt => opt.MapFrom(source => source.NumberOfInstalments)) .ForMember(dest => dest.LearningStartDate, opt => opt.MapFrom(source => source.LearningStartDate)) .ForMember(dest => dest.ApprenticeshipId, opt => opt.MapFrom(source => source.ApprenticeshipId)) .ForMember(dest => dest.ApprenticeshipPriceEpisodeId, opt => opt.MapFrom(source => source.ApprenticeshipPriceEpisodeId)) .ForMember(dest => dest.NumberOfInstalments, opt => opt.MapFrom(source => source.NumberOfInstalments)) .ForMember(dest => dest.ReportingAimFundingLineType, opt => opt.ResolveUsing <ReportingAimFundingLineTypeValueResolver>()) .ForMember(dest => dest.NonPaymentReason, opt => opt.Ignore()) ; CreateMap <EmployerCoInvestedFundingSourcePaymentEvent, ProviderPaymentEventModel>(); CreateMap <SfaCoInvestedFundingSourcePaymentEvent, ProviderPaymentEventModel>(); CreateMap <SfaFullyFundedFundingSourcePaymentEvent, ProviderPaymentEventModel>(); CreateMap <LevyFundingSourcePaymentEvent, ProviderPaymentEventModel>(); CreateMap <TransferFundingSourcePaymentEvent, ProviderPaymentEventModel>(); CreateMap <PaymentModel, ProviderPaymentEvent>() .Include <PaymentModel, EmployerCoInvestedProviderPaymentEvent>() .Include <PaymentModel, SfaCoInvestedProviderPaymentEvent>() .Include <PaymentModel, SfaFullyFundedProviderPaymentEvent>() .Include <PaymentModel, LevyProviderPaymentEvent>() .Include <PaymentModel, TransferProviderPaymentEvent>() .ForMember(dest => dest.EventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(dest => dest.EventTime, opt => opt.ResolveUsing(src => DateTimeOffset.UtcNow)) .ForMember(dest => dest.CollectionPeriod, opt => opt.MapFrom(source => source.CollectionPeriod)) .ForMember(dest => dest.DeliveryPeriod, opt => opt.MapFrom(source => source.DeliveryPeriod)) .ForMember(dest => dest.AmountDue, opt => opt.MapFrom(source => source.Amount)) .ForMember(dest => dest.ContractType, opt => opt.MapFrom(source => source.ContractType)) .ForMember(dest => dest.FundingSourceType, opt => opt.MapFrom(source => source.FundingSource)) .ForMember(dest => dest.IlrSubmissionDateTime, opt => opt.MapFrom(source => source.IlrSubmissionDateTime)) .ForMember(dest => dest.IlrFileName, opt => opt.Ignore()) .ForMember(dest => dest.JobId, opt => opt.MapFrom(source => source.JobId)) .ForPath(dest => dest.Learner.Uln, opt => opt.MapFrom(source => source.LearnerUln)) .ForPath(dest => dest.Learner.ReferenceNumber, opt => opt.MapFrom(source => source.LearnerReferenceNumber)) .ForPath(dest => dest.LearningAim.FrameworkCode, opt => opt.MapFrom(source => source.LearningAimFrameworkCode)) .ForPath(dest => dest.LearningAim.FundingLineType, opt => opt.MapFrom(source => source.LearningAimFundingLineType)) .ForPath(dest => dest.LearningAim.PathwayCode, opt => opt.MapFrom(source => source.LearningAimPathwayCode)) .ForPath(dest => dest.LearningAim.ProgrammeType, opt => opt.MapFrom(source => source.LearningAimProgrammeType)) .ForPath(dest => dest.LearningAim.Reference, opt => opt.MapFrom(source => source.LearningAimReference)) .ForPath(dest => dest.LearningAim.StandardCode, opt => opt.MapFrom(source => source.LearningAimStandardCode)) .ForMember(dest => dest.PriceEpisodeIdentifier, opt => opt.MapFrom(source => source.PriceEpisodeIdentifier)) .ForMember(dest => dest.SfaContributionPercentage, opt => opt.MapFrom(source => source.SfaContributionPercentage)) .ForMember(dest => dest.TransactionType, opt => opt.MapFrom(source => source.TransactionType)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.AccountId, opt => opt.MapFrom(source => source.AccountId)) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(source => source.StartDate)) .ForMember(dest => dest.PlannedEndDate, opt => opt.MapFrom(source => source.PlannedEndDate)) .ForMember(dest => dest.ActualEndDate, opt => opt.MapFrom(source => source.ActualEndDate)) .ForMember(dest => dest.CompletionStatus, opt => opt.MapFrom(source => source.CompletionStatus)) .ForMember(dest => dest.CompletionAmount, opt => opt.MapFrom(source => source.CompletionAmount)) .ForMember(dest => dest.InstalmentAmount, opt => opt.MapFrom(source => source.InstalmentAmount)) .ForMember(dest => dest.NumberOfInstalments, opt => opt.MapFrom(source => source.NumberOfInstalments)) .ForMember(dest => dest.LearningStartDate, opt => opt.MapFrom(source => source.LearningStartDate)) .ForMember(dest => dest.ApprenticeshipId, opt => opt.MapFrom(source => source.ApprenticeshipId)) .ForMember(dest => dest.ApprenticeshipPriceEpisodeId, opt => opt.MapFrom(source => source.ApprenticeshipPriceEpisodeId)) .ForMember(dest => dest.NumberOfInstalments, opt => opt.MapFrom(source => source.NumberOfInstalments)) .ForMember(dest => dest.ApprenticeshipEmployerType, opt => opt.MapFrom(source => source.ApprenticeshipEmployerType)) .ForMember(dest => dest.ReportingAimFundingLineType, opt => opt.MapFrom(source => source.ReportingAimFundingLineType)) ; CreateMap <PaymentModel, EmployerCoInvestedProviderPaymentEvent>(); CreateMap <PaymentModel, SfaCoInvestedProviderPaymentEvent>(); CreateMap <PaymentModel, SfaFullyFundedProviderPaymentEvent>(); CreateMap <PaymentModel, LevyProviderPaymentEvent>(); CreateMap <PaymentModel, TransferProviderPaymentEvent>(); CreateMap <FundingSourcePaymentEvent, ProviderPaymentEvent>() .Include <EmployerCoInvestedFundingSourcePaymentEvent, EmployerCoInvestedProviderPaymentEvent>() .Include <SfaCoInvestedFundingSourcePaymentEvent, SfaCoInvestedProviderPaymentEvent>() .Include <SfaFullyFundedFundingSourcePaymentEvent, SfaFullyFundedProviderPaymentEvent>() .Include <LevyFundingSourcePaymentEvent, LevyProviderPaymentEvent>() .Include <TransferFundingSourcePaymentEvent, TransferProviderPaymentEvent>() .ForMember(dest => dest.EventId, opt => opt.Ignore()); CreateMap <EmployerCoInvestedFundingSourcePaymentEvent, EmployerCoInvestedProviderPaymentEvent>(); CreateMap <SfaCoInvestedFundingSourcePaymentEvent, SfaCoInvestedProviderPaymentEvent>(); CreateMap <SfaFullyFundedFundingSourcePaymentEvent, SfaFullyFundedProviderPaymentEvent>(); CreateMap <LevyFundingSourcePaymentEvent, LevyProviderPaymentEvent>(); CreateMap <TransferFundingSourcePaymentEvent, TransferProviderPaymentEvent>(); CreateMap <PaymentModel, RecordedAct1CompletionPayment>() .ForMember(dest => dest.EventId, opt => opt.MapFrom(source => Guid.NewGuid())) .ForMember(dest => dest.EventTime, opt => opt.MapFrom(source => DateTimeOffset.UtcNow)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.DeliveryPeriod, opt => opt.MapFrom(source => source.DeliveryPeriod)) .ForMember(dest => dest.CollectionPeriod, opt => opt.ResolveUsing(src => CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(src.CollectionPeriod.AcademicYear, src.CollectionPeriod.Period))) .ForMember(dest => dest.Learner, opt => opt.ResolveUsing(LearnerFactory.Create)) .ForMember(dest => dest.LearningAim, opt => opt.ResolveUsing(LearningAimFactory.Create)) .ForMember(dest => dest.IlrSubmissionDateTime, opt => opt.MapFrom(source => source.IlrSubmissionDateTime)) .ForMember(dest => dest.TransactionType, opt => opt.MapFrom(source => source.TransactionType)) .ForMember(dest => dest.SfaContributionPercentage, opt => opt.MapFrom(source => source.SfaContributionPercentage)) .ForMember(dest => dest.FundingSource, opt => opt.MapFrom(source => source.FundingSource)) .ForMember(dest => dest.AmountDue, opt => opt.MapFrom(source => source.Amount)) .ForMember(dest => dest.AccountId, opt => opt.MapFrom(source => source.AccountId)) .ForMember(dest => dest.TransferSenderAccountId, opt => opt.MapFrom(source => source.TransferSenderAccountId)) .ForMember(dest => dest.EarningDetails, opt => opt.ResolveUsing(EarningDetailsFactory.Create)) .ForMember(dest => dest.ApprenticeshipId, opt => opt.MapFrom(source => source.ApprenticeshipId)) .ForMember(dest => dest.ApprenticeshipEmployerType, opt => opt.MapFrom(source => source.ApprenticeshipEmployerType)) .ForMember(dest => dest.ReportingAimFundingLineType, opt => opt.MapFrom(source => source.ReportingAimFundingLineType)) .ForMember(dest => dest.ContractType, opt => opt.MapFrom(source => source.ContractType)) .ForAllOtherMembers(dest => dest.Ignore()) ; }
public DataLocksProfile() { CreateMap <ApprenticeshipContractType1EarningEvent, PayableEarningEvent>() .ForMember(destinationMember => destinationMember.EarningEventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(destinationMember => destinationMember.EventId, opt => opt.Ignore()); CreateMap <ApprenticeshipContractType1EarningEvent, EarningFailedDataLockMatching>() .ForMember(destinationMember => destinationMember.EarningEventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(destinationMember => destinationMember.EventId, opt => opt.Ignore()); CreateMap <Act1FunctionalSkillEarningsEvent, PayableFunctionalSkillEarningEvent>() .ForMember(destinationMember => destinationMember.EarningEventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(destinationMember => destinationMember.EventId, opt => opt.Ignore()); CreateMap <Act1FunctionalSkillEarningsEvent, FunctionalSkillEarningFailedDataLockMatching>() .ForMember(destinationMember => destinationMember.EarningEventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(destinationMember => destinationMember.EventId, opt => opt.Ignore()); CreateMap <FunctionalSkillEarningsEvent, FunctionalSkillDataLockEvent>() .Include <Act1FunctionalSkillEarningsEvent, PayableFunctionalSkillEarningEvent>() .Include <Act1FunctionalSkillEarningsEvent, FunctionalSkillEarningFailedDataLockMatching>() .ForMember(dest => dest.ContractType, opt => opt.MapFrom(src => src.ContractType)) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(src => src.StartDate)) .ForMember(destinationMember => destinationMember.EarningEventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(destinationMember => destinationMember.EventId, opt => opt.Ignore()) .ForMember(dest => dest.AgreementId, opt => opt.Ignore()) .ForMember(dest => dest.OnProgrammeEarnings, opt => opt.Ignore()) .ForMember(dest => dest.IncentiveEarnings, opt => opt.Ignore()); CreateMap <ApprenticeshipCreatedEvent, ApprenticeshipModel>() .ForMember(dest => dest.AccountId, opt => opt.MapFrom(source => source.AccountId)) .ForMember(dest => dest.AgreedOnDate, opt => opt.MapFrom(source => source.AgreedOn)) .ForMember(dest => dest.AgreementId, opt => opt.MapFrom(source => source.AccountLegalEntityPublicHashedId)) .ForMember(dest => dest.EstimatedEndDate, opt => opt.MapFrom(source => source.EndDate)) .ForMember(dest => dest.EstimatedStartDate, opt => opt.MapFrom(source => source.StartDate)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.TrainingCode.ToStandardCode(source.TrainingType))) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.TrainingCode.ToFrameworkCode(source.TrainingType))) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.TrainingCode.ToProgrammeType(source.TrainingType))) .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.TrainingCode.ToPathwayCode(source.TrainingType))) .ForMember(dest => dest.Id, opt => opt.MapFrom(source => source.ApprenticeshipId)) .ForMember(dest => dest.LegalEntityName, opt => opt.MapFrom(source => source.LegalEntityName)) .ForMember(dest => dest.Status, opt => opt.UseValue(ApprenticeshipStatus.Active)) .ForMember(dest => dest.TransferSendingEmployerAccountId, opt => opt.MapFrom(source => source.TransferSenderId)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.ProviderId)) .ForMember(dest => dest.Uln, opt => opt.MapFrom(source => source.Uln)) .ForMember(dest => dest.ApprenticeshipPriceEpisodes, opt => opt.MapFrom(source => source.PriceEpisodes)) .ForMember(dest => dest.Priority, opt => opt.Ignore()) .ForMember(dest => dest.IsLevyPayer, opt => opt.UseValue(true)) .ForMember(dest => dest.StopDate, dest => dest.Ignore()) .ForMember(dest => dest.ApprenticeshipEmployerType, opt => opt.ResolveUsing <ApprenticeshipEmployerTypeResolver>()) .ForMember(dest => dest.CreationDate, opt => opt.Ignore()) .ForMember(dest => dest.ApprenticeshipPauses, opt => opt.Ignore()) ; CreateMap <PriceEpisode, ApprenticeshipPriceEpisodeModel>() .ForMember(dest => dest.StartDate, opt => opt.MapFrom(source => source.FromDate)) .ForMember(dest => dest.Cost, opt => opt.MapFrom(source => source.Cost)) .ForMember(dest => dest.EndDate, opt => opt.MapFrom(source => source.ToDate)) .ForMember(dest => dest.ApprenticeshipId, opt => opt.Ignore()) .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.Removed, opt => opt.Ignore()) ; CreateMap <ApprenticeshipModel, ApprenticeshipUpdated>() .ForMember(dest => dest.EmployerAccountId, opt => opt.MapFrom(source => source.AccountId)) .ForMember(dest => dest.AgreedOnDate, opt => opt.MapFrom(source => source.AgreedOnDate)) .ForMember(dest => dest.AgreementId, opt => opt.MapFrom(source => source.AgreementId)) .ForMember(dest => dest.EstimatedEndDate, opt => opt.MapFrom(source => source.EstimatedEndDate)) .ForMember(dest => dest.EstimatedStartDate, opt => opt.MapFrom(source => source.EstimatedStartDate)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.StandardCode)) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.FrameworkCode)) .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.PathwayCode)) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.ProgrammeType)) .ForMember(dest => dest.Id, opt => opt.MapFrom(source => source.Id)) .ForMember(dest => dest.LegalEntityName, opt => opt.MapFrom(source => source.LegalEntityName)) .ForMember(dest => dest.Status, opt => opt.MapFrom(source => source.Status)) .ForMember(dest => dest.TransferSendingEmployerAccountId, opt => opt.MapFrom(source => source.TransferSendingEmployerAccountId)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.Uln, opt => opt.MapFrom(source => source.Uln)) .ForMember(dest => dest.ApprenticeshipPriceEpisodes, opt => opt.MapFrom(source => source.ApprenticeshipPriceEpisodes)) .ForMember(dest => dest.IsLevyPayer, opt => opt.MapFrom(source => source.IsLevyPayer)) .ForMember(dest => dest.Duplicates, opt => opt.Ignore()) .ForMember(dest => dest.EventId, opt => opt.Ignore()) .ForMember(dest => dest.EventTime, opt => opt.Ignore()) .ForMember(dest => dest.ApprenticeshipEmployerType, opt => opt.MapFrom(source => source.ApprenticeshipEmployerType)) ; CreateMap <ApprenticeshipUpdated, ApprenticeshipModel>() .ForMember(dest => dest.AccountId, opt => opt.MapFrom(source => source.EmployerAccountId)) .ForMember(dest => dest.AgreedOnDate, opt => opt.MapFrom(source => source.AgreedOnDate)) .ForMember(dest => dest.AgreementId, opt => opt.MapFrom(source => source.AgreementId)) .ForMember(dest => dest.EstimatedEndDate, opt => opt.MapFrom(source => source.EstimatedEndDate)) .ForMember(dest => dest.EstimatedStartDate, opt => opt.MapFrom(source => source.EstimatedStartDate)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.StandardCode)) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.FrameworkCode)) .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.PathwayCode)) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.ProgrammeType)) .ForMember(dest => dest.Id, opt => opt.MapFrom(source => source.Id)) .ForMember(dest => dest.LegalEntityName, opt => opt.MapFrom(source => source.LegalEntityName)) .ForMember(dest => dest.Status, opt => opt.MapFrom(source => source.Status)) .ForMember(dest => dest.TransferSendingEmployerAccountId, opt => opt.MapFrom(source => source.TransferSendingEmployerAccountId)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.Uln, opt => opt.MapFrom(source => source.Uln)) .ForMember(dest => dest.ApprenticeshipPriceEpisodes, opt => opt.MapFrom(source => source.ApprenticeshipPriceEpisodes)) .ForMember(dest => dest.IsLevyPayer, opt => opt.MapFrom(source => source.IsLevyPayer)) .ForMember(dest => dest.Priority, opt => opt.Ignore()) .ForMember(dest => dest.ApprenticeshipEmployerType, opt => opt.MapFrom(source => source.ApprenticeshipEmployerType)) .ForMember(dest => dest.CreationDate, opt => opt.Ignore()) .ForMember(dest => dest.ApprenticeshipPauses, opt => opt.Ignore()) ; CreateMap <ApprenticeshipUpdatedApprovedEvent, UpdatedApprenticeshipApprovedModel>() .ForMember(dest => dest.ApprenticeshipId, opt => opt.MapFrom(source => source.ApprenticeshipId)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.TrainingCode.ToStandardCode(source.TrainingType))) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.TrainingCode.ToFrameworkCode(source.TrainingType))) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.TrainingCode.ToProgrammeType(source.TrainingType))) .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.TrainingCode.ToPathwayCode(source.TrainingType))) .ForMember(dest => dest.Uln, opt => opt.MapFrom(source => source.Uln)) .ForMember(dest => dest.ApprenticeshipPriceEpisodes, opt => opt.MapFrom(source => source.PriceEpisodes)) .ForMember(dest => dest.AgreedOnDate, opt => opt.MapFrom(source => source.ApprovedOn)) .ForMember(dest => dest.EstimatedEndDate, opt => opt.MapFrom(source => source.EndDate)) .ForMember(dest => dest.EstimatedStartDate, opt => opt.MapFrom(source => source.StartDate)) ; CreateMap <DataLockTriageApprovedEvent, UpdatedApprenticeshipDataLockTriageModel>() .ForMember(dest => dest.ApprenticeshipId, opt => opt.MapFrom(source => source.ApprenticeshipId)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.TrainingCode.ToStandardCode(source.TrainingType))) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.TrainingCode.ToFrameworkCode(source.TrainingType))) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.TrainingCode.ToProgrammeType(source.TrainingType))) .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.TrainingCode.ToPathwayCode(source.TrainingType))) .ForMember(dest => dest.AgreedOnDate, opt => opt.MapFrom(source => source.ApprovedOn)) .ForMember(dest => dest.ApprenticeshipPriceEpisodes, opt => opt.MapFrom(source => source.PriceEpisodes)); CreateMap <EarningEventModel, ApprenticeshipContractType1EarningEvent>() .ForMember(dest => dest.AgreementId, opt => opt.MapFrom(source => source.AgreementId)) .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.CollectionPeriod, opt => opt.MapFrom(source => CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(source.AcademicYear, source.CollectionPeriod))) .ForMember(dest => dest.CollectionYear, opt => opt.MapFrom(source => source.AcademicYear)) .ForMember(dest => dest.EventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(dest => dest.EventTime, opt => opt.MapFrom(source => source.EventTime)) .ForMember(dest => dest.IlrSubmissionDateTime, opt => opt.MapFrom(source => source.IlrSubmissionDateTime)) .ForMember(dest => dest.JobId, opt => opt.MapFrom(source => source.JobId)) .ForMember(dest => dest.IlrFileName, opt => opt.MapFrom(source => source.IlrFileName)) .ForMember(dest => dest.SfaContributionPercentage, opt => opt.MapFrom(source => source.SfaContributionPercentage)) .ForMember(dest => dest.PriceEpisodes, opt => opt.MapFrom(source => source.PriceEpisodes)) .ForMember(dest => dest.Learner, opt => opt.Ignore()) .ForMember(dest => dest.LearningAim, opt => opt.Ignore()) .ForMember(dest => dest.IncentiveEarnings, opt => opt.Ignore()) .ForMember(dest => dest.OnProgrammeEarnings, opt => opt.Ignore()); CreateMap <EarningEventPeriodModel, EarningPeriod>() .ForMember(dest => dest.PriceEpisodeIdentifier, opt => opt.MapFrom(source => source.PriceEpisodeIdentifier)) .ForMember(dest => dest.Period, opt => opt.MapFrom(source => source.DeliveryPeriod)) .ForMember(dest => dest.Amount, opt => opt.MapFrom(source => source.Amount)) .ForMember(dest => dest.SfaContributionPercentage, opt => opt.MapFrom(source => source.SfaContributionPercentage)) .ForMember(dest => dest.ApprenticeshipEmployerType, opt => opt.Ignore()) .ForMember(dest => dest.AccountId, opt => opt.Ignore()) .ForMember(dest => dest.ApprenticeshipId, opt => opt.Ignore()) .ForMember(dest => dest.ApprenticeshipPriceEpisodeId, opt => opt.Ignore()) .ForMember(dest => dest.TransferSenderAccountId, opt => opt.Ignore()) .ForMember(dest => dest.Priority, opt => opt.Ignore()) .ForMember(dest => dest.DataLockFailures, opt => opt.Ignore()) .ForMember(dest => dest.AgreedOnDate, opt => opt.Ignore()); CreateMap <EarningEventModel, Learner>() .ForMember(dest => dest.ReferenceNumber, opt => opt.MapFrom(source => source.LearnerReferenceNumber)) .ForMember(dest => dest.Uln, opt => opt.MapFrom(source => source.LearnerUln)); CreateMap <EarningEventModel, LearningAim>() .ForMember(dest => dest.Reference, opt => opt.MapFrom(source => source.LearningAimReference)) .ForMember(dest => dest.ProgrammeType, opt => opt.MapFrom(source => source.LearningAimProgrammeType)) .ForMember(dest => dest.StandardCode, opt => opt.MapFrom(source => source.LearningAimStandardCode)) .ForMember(dest => dest.FrameworkCode, opt => opt.MapFrom(source => source.LearningAimFrameworkCode)) .ForMember(dest => dest.PathwayCode, opt => opt.MapFrom(source => source.LearningAimPathwayCode)) .ForMember(dest => dest.FundingLineType, opt => opt.MapFrom(source => source.LearningAimFundingLineType)) .ForMember(dest => dest.SequenceNumber, opt => opt.MapFrom(source => source.LearningAimSequenceNumber)); CreateMap <EarningEventPriceEpisodeModel, SFA.DAS.Payments.Model.Core.PriceEpisode>() .ForMember(dest => dest.Identifier, opt => opt.MapFrom(source => source.PriceEpisodeIdentifier)) .ForMember(dest => dest.TotalNegotiatedPrice1, opt => opt.MapFrom(source => source.TotalNegotiatedPrice1)) .ForMember(dest => dest.TotalNegotiatedPrice2, opt => opt.MapFrom(source => source.TotalNegotiatedPrice2)) .ForMember(dest => dest.TotalNegotiatedPrice3, opt => opt.MapFrom(source => source.TotalNegotiatedPrice3)) .ForMember(dest => dest.TotalNegotiatedPrice4, opt => opt.MapFrom(source => source.TotalNegotiatedPrice4)) .ForMember(dest => dest.AgreedPrice, opt => opt.MapFrom(source => source.AgreedPrice)) .ForMember(dest => dest.CourseStartDate, opt => opt.MapFrom(source => source.CourseStartDate)) .ForMember(dest => dest.EffectiveTotalNegotiatedPriceStartDate, opt => opt.MapFrom(source => source.StartDate)) .ForMember(dest => dest.PlannedEndDate, opt => opt.MapFrom(source => source.PlannedEndDate)) .ForMember(dest => dest.ActualEndDate, opt => opt.MapFrom(source => source.ActualEndDate)) .ForMember(dest => dest.NumberOfInstalments, opt => opt.MapFrom(source => source.NumberOfInstalments)) .ForMember(dest => dest.InstalmentAmount, opt => opt.MapFrom(source => source.InstalmentAmount)) .ForMember(dest => dest.CompletionAmount, opt => opt.MapFrom(source => source.CompletionAmount)) .ForMember(dest => dest.Completed, opt => opt.MapFrom(source => source.Completed)) .ForMember(dest => dest.EmployerContribution, opt => opt.MapFrom(source => source.EmployerContribution)) .ForMember(dest => dest.CompletionHoldBackExemptionCode, opt => opt.MapFrom(source => source.CompletionHoldBackExemptionCode)) .ForMember(dest => dest.FundingLineType, opt => opt.Ignore()) .ForMember(dest => dest.LearningAimSequenceNumber, opt => opt.Ignore()) ; CreateMap <EarningEventModel, Act1FunctionalSkillEarningsEvent>() .ForMember(dest => dest.Ukprn, opt => opt.MapFrom(source => source.Ukprn)) .ForMember(dest => dest.CollectionPeriod, opt => opt.MapFrom(source => CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(source.AcademicYear, source.CollectionPeriod))) .ForMember(dest => dest.CollectionYear, opt => opt.MapFrom(source => source.AcademicYear)) .ForMember(dest => dest.EventId, opt => opt.MapFrom(source => source.EventId)) .ForMember(dest => dest.EventTime, opt => opt.MapFrom(source => source.EventTime)) .ForMember(dest => dest.IlrSubmissionDateTime, opt => opt.MapFrom(source => source.IlrSubmissionDateTime)) .ForMember(dest => dest.JobId, opt => opt.MapFrom(source => source.JobId)) .ForMember(dest => dest.IlrFileName, opt => opt.MapFrom(source => source.IlrFileName)) .ForMember(dest => dest.PriceEpisodes, opt => opt.MapFrom(source => source.PriceEpisodes)) .ForMember(dest => dest.StartDate, opt => opt.MapFrom(source => source.StartDate)) .ForMember(dest => dest.ContractType, opt => opt.UseValue(ContractType.Act1)) .ForMember(dest => dest.Learner, opt => opt.Ignore()) .ForMember(dest => dest.LearningAim, opt => opt.Ignore()) .ForMember(dest => dest.Earnings, opt => opt.Ignore()); }