public async Task <List <DataLockEvent> > GetPaymentEvents(ApprenticeshipContractType1EarningEvent earningEvent, CancellationToken cancellationToken) { var dataLockEvents = new List <DataLockEvent>(); var learnerMatchResult = await learnerMatcher.MatchLearner(earningEvent.Ukprn, earningEvent.Learner.Uln).ConfigureAwait(false); if (learnerMatchResult.DataLockErrorCode.HasValue) { dataLockEvents = CreateDataLockEvents(earningEvent, learnerMatchResult.DataLockErrorCode.Value); return(dataLockEvents); } var apprenticeshipsForUln = learnerMatchResult.Apprenticeships; var onProgrammeEarning = GetOnProgrammeEarnings(earningEvent, apprenticeshipsForUln); var incentiveEarnings = GetIncentiveEarnings(earningEvent, apprenticeshipsForUln); if (onProgrammeEarning.validOnProgEarnings.Any()) { var payableEarningEvent = mapper.Map <PayableEarningEvent>(earningEvent); payableEarningEvent.OnProgrammeEarnings = onProgrammeEarning.validOnProgEarnings; payableEarningEvent.IncentiveEarnings = incentiveEarnings.validIncentiveEarnings; dataLockEvents.Add(payableEarningEvent); } if (onProgrammeEarning.invalidOnProgEarnings.Any()) { var earningFailedDataLockEvent = mapper.Map <EarningFailedDataLockMatching>(earningEvent); earningFailedDataLockEvent.OnProgrammeEarnings = onProgrammeEarning.invalidOnProgEarnings; earningFailedDataLockEvent.IncentiveEarnings = incentiveEarnings.invalidIncentiveEarning; dataLockEvents.Add(earningFailedDataLockEvent); } return(dataLockEvents); }
private ApprenticeshipContractType1EarningEvent CreateTestEarningEvent(byte periodsToCreate, decimal earningPeriodAmount, LearningAim testAim) { var testEarningEvent = new ApprenticeshipContractType1EarningEvent { Learner = new Learner { Uln = Uln, }, PriceEpisodes = new List <PriceEpisode>(), CollectionYear = AcademicYear, Ukprn = Ukprn }; testEarningEvent.OnProgrammeEarnings = new List <OnProgrammeEarning> { new OnProgrammeEarning { Periods = new ReadOnlyCollection <EarningPeriod>(GenerateEarningPeriod(periodsToCreate, earningPeriodAmount, testEarningEvent)) } }; testEarningEvent.IncentiveEarnings = new List <IncentiveEarning> { new IncentiveEarning { Periods = new ReadOnlyCollection <EarningPeriod>(GenerateEarningPeriod(periodsToCreate, earningPeriodAmount, testEarningEvent)) } }; testEarningEvent.LearningAim = testAim; return(testEarningEvent); }
public void MapperDoesNotChangeEventId() { var payment = new ApprenticeshipContractType1EarningEvent(); var requiredPayment = new CalculatedRequiredLevyAmount(); var expected = requiredPayment.EventId; mapper.Map(payment, requiredPayment); requiredPayment.EventId.Should().Be(expected); }
public void CreateRedundancyContractType_ForAct1ContractType_ShouldCreateANewEventId() { var factory = new RedundancyEarningEventFactory(Mapper.Instance); var earningEvent = new ApprenticeshipContractType1EarningEvent { EventId = Guid.NewGuid() }; var createdEvent = factory.CreateRedundancyContractTypeEarningsEvent(earningEvent); earningEvent.EventId.Should().NotBe(createdEvent.EventId); createdEvent.EventId.Should().NotBe(Guid.Empty); }
public async Task <List <DataLockEvent> > HandleEarning(ApprenticeshipContractType1EarningEvent message, CancellationToken cancellationToken) { using (var operation = telemetry.StartOperation("DataLockService.HandleEarning", message.EventId.ToString())) { var stopwatch = Stopwatch.StartNew(); await Initialise().ConfigureAwait(false); var dataLockEvents = await dataLockProcessor.GetPaymentEvents(message, cancellationToken); telemetry.TrackDuration("DataLockService.HandleEarning", stopwatch, message); telemetry.StopOperation(operation); return(dataLockEvents); } }
public void Setup() { apprenticeships = new List <ApprenticeshipModel> { new ApprenticeshipModel { Id = 1, AccountId = 456, Uln = Uln, Ukprn = Ukprn }, new ApprenticeshipModel { Id = 2, AccountId = 456, Uln = Uln, Ukprn = Ukprn } }; earningEvent = CreateTestEarningEvent(1, 100m, aim); earningEvent.LearningAim = aim; learnerMatcherMock = new Mock <ILearnerMatcher>(MockBehavior.Strict); onProgValidationMock = new Mock <IEarningPeriodsValidationProcessor>(MockBehavior.Strict); }
private EarningEvents.Messages.Events.EarningEvent CreateEarningEvent( Action <EarningEvents.Messages.Events.EarningEvent> action) { var earningEvent = new ApprenticeshipContractType1EarningEvent { JobId = 123, CollectionPeriod = new CollectionPeriod { AcademicYear = 1920, Period = 1 }, Ukprn = 1234, EventId = Guid.NewGuid(), Learner = new Learner { Uln = 123456, ReferenceNumber = "learner ref" }, EventTime = DateTimeOffset.Now, IlrSubmissionDateTime = DateTime.Now, SfaContributionPercentage = .95M, AgreementId = null, CollectionYear = 2020, IlrFileName = "somefile.ilr", IncentiveEarnings = new List <IncentiveEarning> { new IncentiveEarning { Type = IncentiveEarningType.First16To18EmployerIncentive, Periods = new List <EarningPeriod> { new EarningPeriod { Period = 1, Amount = 100, } }.AsReadOnly() } }, LearningAim = new LearningAim(), OnProgrammeEarnings = new List <OnProgrammeEarning>(), PriceEpisodes = new List <PriceEpisode>(), StartDate = DateTime.Today }; action?.Invoke(earningEvent); return(earningEvent); }
private List <DataLockEvent> CreateDataLockEvents(ApprenticeshipContractType1EarningEvent earningEvent, DataLockErrorCode dataLockErrorCode) { var dataLockEvents = new List <DataLockEvent>(); var nonPayableEarning = mapper.Map <EarningFailedDataLockMatching>(earningEvent); foreach (var onProgrammeEarning in nonPayableEarning.OnProgrammeEarnings) { var validPeriods = new List <EarningPeriod>(); var invalidPeriods = new List <EarningPeriod>(); foreach (var period in onProgrammeEarning.Periods) { period.DataLockFailures = new List <DataLockFailure> { new DataLockFailure { DataLockError = dataLockErrorCode } }; } } foreach (var incentiveEarning in nonPayableEarning.IncentiveEarnings) { foreach (var period in incentiveEarning.Periods) { period.DataLockFailures = new List <DataLockFailure> { new DataLockFailure { DataLockError = dataLockErrorCode } }; } } if (nonPayableEarning.OnProgrammeEarnings.Any() || nonPayableEarning.IncentiveEarnings.Any()) { dataLockEvents.Add(nonPayableEarning); } return(dataLockEvents); }
public void Setup() { mocker = AutoMock.GetLoose(); apprenticeships = new List <ApprenticeshipModel> { new ApprenticeshipModel { Id = 1, AccountId = 456, Uln = Uln, Ukprn = Ukprn }, new ApprenticeshipModel { Id = 2, AccountId = 456, Uln = Uln, Ukprn = Ukprn } }; earningEvent = CreateTestEarningEvent(1, 100m, aim); earningEvent.LearningAim = aim; mocker.Provide(mapper); learnerMatcherMock = mocker.Mock <ILearnerMatcher>(); onProgValidationMock = mocker.Mock <IOnProgrammeAndIncentiveEarningPeriodsValidationProcessor>(); functionalSkillsValidationMock = mocker.Mock <IFunctionalSkillEarningPeriodsValidationProcessor>(); mocker.Mock <IDuplicateEarningEventService>() .Setup(x => x.IsDuplicate(It.IsAny <IPaymentsEvent>(), It.IsAny <CancellationToken>())) .ReturnsAsync(false); }
public void Maps_Act1_Earnings() { var earningEvent = new ApprenticeshipContractType1EarningEvent { JobId = 123, CollectionPeriod = new CollectionPeriod { AcademicYear = 1920, Period = 1 }, Ukprn = 1234, EventId = Guid.NewGuid(), Learner = new Learner { Uln = 123456, ReferenceNumber = "learner ref" }, EventTime = DateTimeOffset.Now, IlrSubmissionDateTime = DateTime.Now, SfaContributionPercentage = .95M, AgreementId = null, CollectionYear = 2020, IlrFileName = "somefile.ilr", IncentiveEarnings = new List <IncentiveEarning> { new IncentiveEarning { Type = IncentiveEarningType.First16To18EmployerIncentive, Periods = new List <EarningPeriod> { new EarningPeriod { Period = 1, Amount = 100, } }.AsReadOnly() } }, LearningAim = new LearningAim { StartDate = DateTime.Now, FrameworkCode = 1, FundingLineType = "Levy 18+", Reference = "aim ref", SequenceNumber = 112 }, OnProgrammeEarnings = new List <OnProgrammeEarning> { new OnProgrammeEarning { Type = OnProgrammeEarningType.Learning, Periods = new List <EarningPeriod> { new EarningPeriod { Period = 1, Amount = 1000 }, new EarningPeriod { Period = 2, Amount = 1000 }, }.AsReadOnly() } }, PriceEpisodes = new List <PriceEpisode> { new PriceEpisode { Identifier = "01-01-29/1234", FundingLineType = "Levy 16-18", LearningAimSequenceNumber = 112 }, new PriceEpisode { Identifier = "02-02-29/1234" } }, StartDate = DateTime.Now }; var mapper = new EarningEventMapper(Mapper); var earningEventModel = mapper.Map(earningEvent); earningEventModel.Should().NotBeNull("Earning event model was null"); CompareCommonProperties(earningEvent, earningEventModel); //ComparePriceEpisodes(earningEvent, earningEventModel); //TODO: }
private static List <EarningPeriod> GenerateEarningPeriod(byte periodsToCreate, decimal earningPeriodAmount, ApprenticeshipContractType1EarningEvent testEarningEvent) { var earningPeriods = new List <EarningPeriod>(); for (byte i = 1; i <= periodsToCreate; i++) { testEarningEvent.PriceEpisodes.Add(new PriceEpisode { EffectiveTotalNegotiatedPriceStartDate = DateTime.UtcNow.AddDays(1), Identifier = $"pe-{i}" }); earningPeriods.Add(new EarningPeriod { Amount = earningPeriodAmount, Period = i, PriceEpisodeIdentifier = $"pe-{i}" }); } return(earningPeriods); }
public void Setup() { var earnings = new List <EarningPeriod>(); for (byte i = 1; i < 13; i++) { earnings.Add(new EarningPeriod { Amount = 100, Period = i, PriceEpisodeIdentifier = "p-1", SfaContributionPercentage = 0.9m }); } var incentiveEarnings = new List <IncentiveEarning>(); foreach (var incentiveEarningType in Enum.GetValues(typeof(IncentiveEarningType))) { incentiveEarnings.Add(new IncentiveEarning { CensusDate = DateTime.MaxValue, Periods = earnings.AsReadOnly(), Type = (IncentiveEarningType)incentiveEarningType }); } earningEventPayment = new ApprenticeshipContractType1EarningEvent() { Ukprn = 12345, SfaContributionPercentage = 0.9m, JobId = 123, CollectionPeriod = new CollectionPeriod { Period = 12, AcademicYear = 1819 }, Learner = new Learner { ReferenceNumber = "1234-ref", Uln = 123456 }, CollectionYear = 2019, LearningAim = new LearningAim { PathwayCode = 12, FrameworkCode = 1245, FundingLineType = "Non-DAS 16-18 Learner", StandardCode = 1209, ProgrammeType = 7890, Reference = "ZPROG001" }, IlrSubmissionDateTime = DateTime.MaxValue, EventTime = DateTimeOffset.MaxValue, AgreementId = "12120002", IncentiveEarnings = incentiveEarnings, OnProgrammeEarnings = (new List <OnProgrammeEarning> { new OnProgrammeEarning { CensusDate = DateTime.MaxValue, Type = OnProgrammeEarningType.Learning, Periods = earnings.AsReadOnly() }, new OnProgrammeEarning { CensusDate = DateTime.MaxValue, Type = OnProgrammeEarningType.Balancing, Periods = earnings.AsReadOnly() }, new OnProgrammeEarning { CensusDate = DateTime.MaxValue, Type = OnProgrammeEarningType.Completion, Periods = earnings.AsReadOnly() } }), PriceEpisodes = (new List <PriceEpisode> { new PriceEpisode { ActualEndDate = DateTime.MaxValue, Completed = true, CompletionAmount = 300m, Identifier = "p-1", EffectiveTotalNegotiatedPriceStartDate = DateTime.MinValue, InstalmentAmount = 100m, NumberOfInstalments = 12, PlannedEndDate = DateTime.MaxValue, TotalNegotiatedPrice1 = 25.0m, TotalNegotiatedPrice2 = 25.0m, TotalNegotiatedPrice3 = 25.0m, TotalNegotiatedPrice4 = 25.0m, FundingLineType = "19+ Apprenticeship Levy Contract (procured)", } }), EventId = Guid.NewGuid(), StartDate = DateTime.Today.AddDays(-5) }; var functionalSkillEarnings = new List <FunctionalSkillEarning> { new FunctionalSkillEarning { Type = FunctionalSkillType.OnProgrammeMathsAndEnglish, Periods = earnings.AsReadOnly() } }; functionalSkillEarningEvent = new Act1FunctionalSkillEarningsEvent { EventId = Guid.NewGuid(), Ukprn = 12345, JobId = 123, CollectionPeriod = new CollectionPeriod { Period = 12, AcademicYear = 1819 }, Learner = new Learner { ReferenceNumber = "1234-ref", Uln = 123456 }, CollectionYear = 2019, LearningAim = new LearningAim { PathwayCode = 12, FrameworkCode = 1245, FundingLineType = "Non-DAS 16-18 Learner", StandardCode = 1209, ProgrammeType = 7890, Reference = "ZPROG001" }, IlrSubmissionDateTime = DateTime.MaxValue, EventTime = DateTimeOffset.MaxValue, Earnings = functionalSkillEarnings.AsReadOnly(), PriceEpisodes = new List <PriceEpisode> { new PriceEpisode { ActualEndDate = DateTime.MaxValue, Completed = true, CompletionAmount = 300m, Identifier = "p-1", EffectiveTotalNegotiatedPriceStartDate = DateTime.MinValue, InstalmentAmount = 100m, NumberOfInstalments = 12, PlannedEndDate = DateTime.MaxValue, TotalNegotiatedPrice1 = 25.0m, TotalNegotiatedPrice2 = 25.0m, TotalNegotiatedPrice3 = 25.0m, TotalNegotiatedPrice4 = 25.0m } } }; }