public void ContractTypeIsCorrectForFunctionalSkills(Type requiredPaymentEventType, ContractType expectedContractType) { var requiredPaymentEvent = Activator.CreateInstance(requiredPaymentEventType) as PeriodisedRequiredPaymentEvent; requiredPaymentEvent.ContractType = expectedContractType; IFunctionalSkillEarningEvent earningEvent = null; switch (expectedContractType) { case ContractType.Act1: earningEvent = new PayableFunctionalSkillEarningEvent { PriceEpisodes = new List <PriceEpisode>(), LearningAim = new LearningAim() }; break; case ContractType.Act2: earningEvent = new Act2FunctionalSkillEarningsEvent { PriceEpisodes = new List <PriceEpisode>(), LearningAim = new LearningAim() }; break; } var actual = mapper.Map(earningEvent, requiredPaymentEvent); actual.ContractType.Should().Be(expectedContractType); }
public void CreateRedundancyContractType_ForAct2RedundancyFunctionalSkillEarningsEvent_ShouldCreateANewEventId() { var factory = new RedundancyEarningEventFactory(Mapper.Instance); var earningEvent = new Act2FunctionalSkillEarningsEvent { EventId = Guid.NewGuid(), Earnings = new ReadOnlyCollection <FunctionalSkillEarning>(new List <FunctionalSkillEarning>()) }; var createdEvent = factory.CreateRedundancyFunctionalSkillTypeEarningsEvent(earningEvent); earningEvent.EventId.Should().NotBe(createdEvent.EventId); createdEvent.EventId.Should().NotBe(Guid.Empty); }
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 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 <ReadOnlyCollection <PeriodisedRequiredPaymentEvent> > HandleFunctionalSkillEarningsEvent(Act2FunctionalSkillEarningsEvent earningEvent, CancellationToken cancellationToken) { paymentLogger.LogVerbose($"Handling FunctionalSkillEarningsEvent for {apprenticeshipKeyString}"); using (var operation = telemetry.StartOperation()) { var stopwatch = Stopwatch.StartNew(); await ResetPaymentHistoryCacheIfDifferentCollectionPeriod(earningEvent.CollectionPeriod) .ConfigureAwait(false); await Initialise().ConfigureAwait(false); var requiredPaymentEvents = await functionalSkillEarningsEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCache, cancellationToken).ConfigureAwait(false); Log(requiredPaymentEvents); telemetry.TrackDuration("RequiredPaymentsService.HandleFunctionalSkillEarningsEvent", stopwatch, earningEvent); telemetry.StopOperation(operation); return(requiredPaymentEvents); } }