private static OnProgrammeEarning CreateOnProgrammeEarning(OnProgrammeEarning onProgrammeEarning, List <EarningPeriod> periods)
 {
     return(new OnProgrammeEarning
     {
         CensusDate = onProgrammeEarning.CensusDate,
         Type = onProgrammeEarning.Type,
         Periods = periods.AsReadOnly()
     });
 }
        private OnProgrammeEarning CreateOnProgramEarning(OnProgrammeEarningType type)
        {
            var onProgrammeEarning = new OnProgrammeEarning()
            {
                Type    = type,
                Periods = CreatePeriods(12, 1000m)
            };

            return(onProgrammeEarning);
        }
示例#3
0
        public void ZeroAmountPeriodsAreAddedToValidPeriod()
        {
            var earning = new OnProgrammeEarning
            {
                Periods = new List <EarningPeriod> {
                    new EarningPeriod
                    {
                        Amount = 0, PriceEpisodeIdentifier = "pe-1", Period = 1
                    }
                }.AsReadOnly()
            };

            mocker.Mock <ICourseValidationProcessor>()
            .Setup(x => x.ValidateCourse(It.Is <DataLockValidationModel>(model => model.Apprenticeship.Id == 1)))
            .Returns(() => new CourseValidationResult {
                MatchedPriceEpisode = new ApprenticeshipPriceEpisodeModel {
                    Id = 90
                }
            });
            mocker.Mock <ICourseValidationProcessor>()
            .Setup(x => x.ValidateCourse(It.Is <DataLockValidationModel>(model => model.Apprenticeship.Id == 2)))
            .Returns(() => new CourseValidationResult {
                DataLockFailures = dataLockFailures
            });

            var periods = mocker.Create <EarningPeriodsValidationProcessor>().ValidatePeriods(
                ukprn,
                1,
                priceEpisodes,
                earning.Periods.ToList(),
                (TransactionType)earning.Type,
                apprenticeships,
                aim,
                AcademicYear);

            periods.ValidPeriods.Count.Should().Be(1);
        }
示例#4
0
        public async Task TestPriceEpisodeIdentifierPickedFromHistoryForRefunds2(ApprenticeshipEmployerType employerType, OnProgrammeEarning earning, PaymentHistoryEntity previousPayment)
        {
            // arrange
            var period         = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 3);
            var deliveryPeriod = (byte)2;

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

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

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

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

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

            var paymentHistory = ConditionalValue.WithArray(previousPayment);

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

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

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

            // assert
            actualRequiredPayment.Should().BeEquivalentTo(
                new
            {
                previousPayment.ApprenticeshipEmployerType,
                previousPayment.ApprenticeshipId,
                previousPayment.ApprenticeshipPriceEpisodeId,
            });
        }
示例#5
0
        public void MatchedPriceEpisodeIsReturnedInValidPeriods()
        {
            apprenticeships = new List <ApprenticeshipModel>
            {
                new ApprenticeshipModel
                {
                    Id        = 1,
                    AccountId = 21,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 90
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 91
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 92
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 93
                        },
                    },
                    EstimatedStartDate = new DateTime(2018, 8, 1),
                    Status             = ApprenticeshipStatus.Active
                },
                new ApprenticeshipModel
                {
                    Id        = 2,
                    AccountId = 22,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 94
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 95
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 96
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 97
                        },
                    },
                    EstimatedStartDate = new DateTime(2018, 9, 1),
                    Status             = ApprenticeshipStatus.Active
                }
            };

            var earning = new OnProgrammeEarning
            {
                Periods = new List <EarningPeriod> {
                    new EarningPeriod
                    {
                        Amount = 1,
                        PriceEpisodeIdentifier = "pe-1",
                        Period = 1
                    }
                }.AsReadOnly()
            };

            mocker.Mock <ICourseValidationProcessor>()
            .Setup(x => x.ValidateCourse(It.Is <DataLockValidationModel>(model => model.Apprenticeship.Id == 1)))
            .Returns(() => new CourseValidationResult {
                MatchedPriceEpisode = new ApprenticeshipPriceEpisodeModel {
                    Id = 90
                }
            });
            mocker.Mock <ICourseValidationProcessor>()
            .Setup(x => x.ValidateCourse(It.Is <DataLockValidationModel>(model => model.Apprenticeship.Id == 2)))
            .Returns(() => new CourseValidationResult {
                DataLockFailures = dataLockFailures
            });

            var periods = mocker.Create <EarningPeriodsValidationProcessor>().ValidatePeriods(
                ukprn,
                1,
                priceEpisodes,
                earning.Periods.ToList(),
                (TransactionType)earning.Type,
                apprenticeships,
                aim,
                AcademicYear);

            periods.ValidPeriods.Count.Should().Be(1);
            periods.ValidPeriods.All(p => p.ApprenticeshipPriceEpisodeId == 90).Should().Be(true);
        }
示例#6
0
        public void OnlyValidateMostRecentActiveApprenticeshipsWithinADeliveryPeriod()
        {
            AcademicYear     = 1920;
            aim.StandardCode = 403;
            apprenticeships  = new List <ApprenticeshipModel>
            {
                new ApprenticeshipModel
                {
                    Id        = 1,
                    AccountId = 21,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel
                        {
                            Id = 1,
                            ApprenticeshipId = 1,
                            StartDate        = new DateTime(2017, 6, 1),
                        },
                    },
                    EstimatedStartDate = new DateTime(2017, 6, 1),
                    EstimatedEndDate   = new DateTime(2018, 7, 1),
                    Status             = ApprenticeshipStatus.Active,
                },
                new ApprenticeshipModel
                {
                    Id        = 2,
                    AccountId = 21,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel
                        {
                            Id = 2,
                            ApprenticeshipId = 2,
                            StartDate        = new DateTime(2018, 9, 1),
                        },
                    },
                    EstimatedStartDate = new DateTime(2018, 9, 1),
                    EstimatedEndDate   = new DateTime(2020, 9, 1),
                    Status             = ApprenticeshipStatus.Active,
                }
            };

            var earning = new OnProgrammeEarning
            {
                Periods = new List <EarningPeriod>
                {
                    new EarningPeriod
                    {
                        Amount = 1,
                        PriceEpisodeIdentifier = "pe-1",
                        Period = 1
                    }
                }.AsReadOnly(),
            };

            mocker.Mock <ICalculatePeriodStartAndEndDate>()
            .Setup(x => x.GetPeriodDate(1, AcademicYear))
            .Returns(() => (new DateTime(2019, 8, 1), new DateTime(2019, 8, 31)));

            mocker.Mock <ICourseValidationProcessor>()
            .Setup(x => x.ValidateCourse(It.IsAny <DataLockValidationModel>()))
            .Returns(() => new CourseValidationResult
            {
                DataLockFailures    = new List <DataLockFailure>(),
                MatchedPriceEpisode = new ApprenticeshipPriceEpisodeModel()
            });

            var periods = mocker.Create <EarningPeriodsValidationProcessor>()
                          .ValidatePeriods(ukprn, 1, priceEpisodes, earning.Periods.ToList(), (TransactionType)earning.Type, apprenticeships, aim, AcademicYear);


            mocker.Mock <ICourseValidationProcessor>()
            .Verify(x => x.ValidateCourse(It.Is <DataLockValidationModel>(model => model.Apprenticeship.Id == 1)), Times.Never);

            mocker.Mock <ICourseValidationProcessor>()
            .Verify(x => x.ValidateCourse(It.Is <DataLockValidationModel>(model => model.Apprenticeship.Id == 2)), Times.Once);
        }
示例#7
0
        public void OnlyValidateMostRecentApprenticeshipsWithinADeliveryPeriods()
        {
            aim.StandardCode = 403;

            apprenticeships = new List <ApprenticeshipModel>
            {
                new ApprenticeshipModel
                {
                    Id        = 1,
                    AccountId = 21,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 90
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 91
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 92
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 93
                        },
                    },
                    EstimatedStartDate = new DateTime(2018, 9, 15),
                    StopDate           = new DateTime(2018, 9, 17),
                    Status             = ApprenticeshipStatus.Stopped,
                },
                new ApprenticeshipModel
                {
                    Id        = 2,
                    AccountId = 21,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 94
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 95
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 96
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 97
                        },
                    },
                    EstimatedStartDate = new DateTime(2018, 9, 15),
                    StopDate           = new DateTime(2018, 9, 15),
                    Status             = ApprenticeshipStatus.Stopped,
                    StandardCode       = aim.StandardCode
                },
                new ApprenticeshipModel
                {
                    Id        = 3,
                    AccountId = 21,
                    Ukprn     = ukprn,
                    ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel>
                    {
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 98
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 99
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 100
                        },
                        new ApprenticeshipPriceEpisodeModel {
                            Id = 101
                        },
                    },
                    EstimatedStartDate = new DateTime(2018, 9, 15),
                    StandardCode       = 404,
                    Status             = ApprenticeshipStatus.Active
                }
            };

            var earning = new OnProgrammeEarning
            {
                Periods = new List <EarningPeriod>
                {
                    new EarningPeriod
                    {
                        Amount = 1,
                        PriceEpisodeIdentifier = "pe-1",
                        Period = 2
                    }
                }.AsReadOnly(),
            };

            mocker.Mock <ICalculatePeriodStartAndEndDate>()
            .Setup(x => x.GetPeriodDate(2, AcademicYear))
            .Returns(() => (new DateTime(2018, 9, 1), new DateTime(2018, 9, 30)));

            mocker.Mock <ICourseValidationProcessor>()
            .Setup(x => x.ValidateCourse(It.Is <DataLockValidationModel>(o => o.Apprenticeship.Id == apprenticeships.Last().Id)))
            .Returns(() => new CourseValidationResult
            {
                DataLockFailures = new List <DataLockFailure>
                {
                    new DataLockFailure
                    {
                        ApprenticeshipId = apprenticeships.Last().Id,
                        ApprenticeshipPriceEpisodeIds = apprenticeships.Last().ApprenticeshipPriceEpisodes.Select(x => x.Id).ToList(),
                        DataLockError = DataLockErrorCode.DLOCK_04
                    }
                },
                MatchedPriceEpisode = new ApprenticeshipPriceEpisodeModel()
            });

            var periods = mocker.Create <EarningPeriodsValidationProcessor>()
                          .ValidatePeriods(ukprn, 1, priceEpisodes, earning.Periods.ToList(), (TransactionType)earning.Type, apprenticeships, aim, AcademicYear);

            mocker.Mock <ICourseValidationProcessor>()
            .Verify(x => x.ValidateCourse(It.Is <DataLockValidationModel>(o => o.Apprenticeship.Id == apprenticeships.Last().Id)),
                    Times.Once);

            periods.ValidPeriods.Count.Should().Be(0);
            periods.InValidPeriods.Count.Should().Be(1);
            periods.InValidPeriods.Any(p => p.DataLockFailures.Count() == 1 && p.DataLockFailures.All(d => d.DataLockError == DataLockErrorCode.DLOCK_04))
            .Should().Be(true);
        }