public void ShouldNotMatchRemovedApprenticeshipPriceEpisodes() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { EffectiveTotalNegotiatedPriceStartDate = startDate, Identifier = priceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { StartDate = startDate.AddDays(-1), Removed = true } } } }; var validator = new StartDateValidator(calculatePeriodStartAndEndDate.Object); var result = validator.Validate(validation); result.DataLockErrorCode.Should().NotBeNull(); result.DataLockErrorCode.Should().Be(DataLockErrorCode.DLOCK_09); }
public void ShouldNotMatchRemovedApprenticeshipPriceEpisodes() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, Status = ApprenticeshipStatus.Active, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Removed = true } } }, }; var validator = new ApprenticeshipPauseValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes.Should().BeEmpty(); }
public void ShouldNotMatchRevmovedApprenticeshipPriceEpisodes() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { AgreedPrice = Price, Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Cost = Price, Id = 98 }, new ApprenticeshipPriceEpisodeModel { Cost = Price, Id = 99, Removed = true } } } }; var validator = new NegotiatedPriceValidator(); var result = validator.Validate(validation); result.ApprenticeshipPriceEpisodes.Any(ape => ape.Id == 98).Should().BeTrue(); result.ApprenticeshipPriceEpisodes.Should().HaveCount(1); }
public void WhenApprenticeshipIsNotEmployerALevyPayerButTransferReceiverReturnNoDataLockErrors() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, IsLevyPayer = false, AccountId = 50, TransferSendingEmployerAccountId = 100, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 100 } } } }; var validator = new ApprenticeshipLevyPayerValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes.Should().HaveCount(1); result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(100); }
public void WhenStatusIsNotPauseReturnNoDataLockErrors() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 100 } } } }; var validator = new ApprenticeshipPauseValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes.Should().HaveCount(1); result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(100); }
public CourseValidationResult ValidateCourse(DataLockValidationModel validationModel) { var allApprenticeshipPriceEpisodeIds = GetAllApprenticeshipPriceEpisodeIds(validationModel); var validationResult = Validate(courseValidators, validationModel, allApprenticeshipPriceEpisodeIds); return(validationResult); }
public void WhenPathwayCodeMatches_ThenNoDatalock() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 100 } }, PathwayCode = 123, }, Aim = new LearningAim { PathwayCode = 123, }, }; var validator = new PathwayCodeValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes.Should().HaveCount(1); result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(100); }
public void WhenPathwayCodeDoesNotMatch_ThenDLOCK_06() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 100 } }, PathwayCode = 123, }, Aim = new LearningAim { PathwayCode = 124, }, }; var validator = new PathwayCodeValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().Be(DataLockErrorCode.DLOCK_06); result.ApprenticeshipPriceEpisodes.Should().HaveCount(0); }
public CourseValidationResult ValidateCourse(DataLockValidationModel dataLockValidationModel) { var allApprenticeshipPriceEpisodeIds = GetAllApprenticeshipPriceEpisodeIds(dataLockValidationModel); var validationResults = Validate(learnerAimValidators, dataLockValidationModel, allApprenticeshipPriceEpisodeIds); return(validationResults); }
protected override List <ApprenticeshipPriceEpisodeModel> GetValidApprenticeshipPriceEpisodes( DataLockValidationModel dataLockValidationModel) { // Only DLOCK_10 when apprenticeship is stopped if (dataLockValidationModel.Apprenticeship.Status != ApprenticeshipStatus.Stopped) { return(dataLockValidationModel.Apprenticeship.ApprenticeshipPriceEpisodes); } // Only deal with Transaction Type 1 OnProgramme and incentives if (dataLockValidationModel.TransactionType == TransactionType.Balancing || dataLockValidationModel.TransactionType == TransactionType.Completion) { return(dataLockValidationModel.Apprenticeship.ApprenticeshipPriceEpisodes); } var periodDate = calculatePeriodStartAndEndDate.GetPeriodDate(dataLockValidationModel.EarningPeriod.Period, dataLockValidationModel.AcademicYear); if (dataLockValidationModel.Apprenticeship.StopDate >= periodDate.periodEndDate) { return(dataLockValidationModel.Apprenticeship.ApprenticeshipPriceEpisodes); } return(new List <ApprenticeshipPriceEpisodeModel>()); }
public void GivenAgreedPriceDoNotMatchReturnDataLockError07() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { AgreedPrice = Price, Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Cost = 200 } } } }; var validator = new NegotiatedPriceValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().Be(DataLockErrorCode.DLOCK_07); }
public void GivenAgreedPriceMatchReturnNoDataLockErrors() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { AgreedPrice = Price, Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Cost = Price + 10, Id = 97 }, new ApprenticeshipPriceEpisodeModel { Cost = Price, Id = 98 }, new ApprenticeshipPriceEpisodeModel { Cost = Price + 20, Id = 99 } } } }; var validator = new NegotiatedPriceValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); }
public void GivenStatusIsPausedReturnDataLockErrors() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, Status = ApprenticeshipStatus.Paused, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel() } } }; var validator = new ApprenticeshipPauseValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().Be(DataLockErrorCode.DLOCK_12); result.ApprenticeshipPriceEpisodes.Should().BeEmpty(); }
public void ScenariosThatDoNotProduceDatalocksBasedOnTransactionType(string errorMessage, byte testPeriod, DateTime commitmentStopDate, DateTime periodEndDate, TransactionType type) { period.Period = testPeriod; var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier, }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 100, }, }, StopDate = commitmentStopDate, Status = ApprenticeshipStatus.Stopped, }, AcademicYear = AcademicYear, TransactionType = type }; var validator = new OnProgrammeAndIncentiveStoppedValidator(calculatePeriodStartAndEndDate.Object); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(errorMessage); result.ApprenticeshipPriceEpisodes.Should().HaveCount(1, errorMessage); result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(100, errorMessage); }
public void GivenApprenticeshipEmployerIsNotALevyPayerReturnDataLock_11() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, IsLevyPayer = false, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel() } } }; var validator = new ApprenticeshipLevyPayerValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().Be(DataLockErrorCode.DLOCK_11); result.ApprenticeshipPriceEpisodes.Should().BeEmpty(); }
private bool ApprenticeshipIsWithinPeriod(DataLockValidationModel dataLockValidationModel) { var periodDates = calculatePeriodStartAndEndDate .GetPeriodDate(dataLockValidationModel.EarningPeriod.Period, dataLockValidationModel.AcademicYear); return(dataLockValidationModel.Apprenticeship.EstimatedStartDate <= periodDates.periodEndDate); }
protected bool CheckAndAddValidationResults( ICourseValidator courseValidator, DataLockValidationModel dataLockValidationModel, List <DataLockFailure> dataLockFailures, List <long> allApprenticeshipPriceEpisodeIds, List <long> invalidApprenticeshipPriceEpisodeIds) { var validatorResult = courseValidator.Validate(dataLockValidationModel); if (validatorResult.DataLockErrorCode.HasValue) { dataLockFailures.Add(new DataLockFailure { ApprenticeshipId = dataLockValidationModel.Apprenticeship.Id, DataLockError = validatorResult.DataLockErrorCode.Value, ApprenticeshipPriceEpisodeIds = allApprenticeshipPriceEpisodeIds }); } else { var validApprenticeshipPriceEpisodeIds = validatorResult.ApprenticeshipPriceEpisodes .Where(o => !o.Removed) .Select(x => x.Id) .ToList(); invalidApprenticeshipPriceEpisodeIds.AddRange( allApprenticeshipPriceEpisodeIds.Except(validApprenticeshipPriceEpisodeIds)); } return(validatorResult.DataLockErrorCode.HasValue); }
public void ScenariosThatDoNotCreateDlockErrors(string errorMessage, TransactionType transactionType, DateTime ilrDate, DateTime commitmentDate) { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { Identifier = PriceEpisodeIdentifier, ActualEndDate = ilrDate, }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, Status = ApprenticeshipStatus.Stopped, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 100, }, }, StopDate = commitmentDate, }, AcademicYear = 1920, TransactionType = transactionType, }; var validator = new CompletionStoppedValidator(); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes.Should().HaveCount(1); result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(100); }
public void ReturnsMatchedPriceEpisodes() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { EffectiveTotalNegotiatedPriceStartDate = startDate, Identifier = priceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 99, StartDate = startDate.AddDays(-1) } } } }; var validator = new StartDateValidator(calculatePeriodStartAndEndDate.Object); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes.Any(ape => ape.Id == 99).Should().BeTrue(); }
private ValidationResult CreateValidationResult(DataLockValidationModel dataLockValidationModel) { var result = new ValidationResult { ApprenticeshipId = dataLockValidationModel.Apprenticeship.Id, Period = dataLockValidationModel.EarningPeriod.Period, }; return(result); }
protected override bool FailedValidation(DataLockValidationModel dataLockValidationModel, List <ApprenticeshipPriceEpisodeModel> validApprenticeshipPriceEpisodes) { if (dataLockValidationModel.Apprenticeship.TransferSendingEmployerAccountId.HasValue && dataLockValidationModel.Apprenticeship.TransferSendingEmployerAccountId > 0) { return(false); } return(!dataLockValidationModel.Apprenticeship.IsLevyPayer); }
protected List <long> GetAllApprenticeshipPriceEpisodeIds(DataLockValidationModel dataLockValidationModel) { var allApprenticeshipPriceEpisodeIds = dataLockValidationModel .Apprenticeship .ApprenticeshipPriceEpisodes .Where(x => !x.Removed) .Select(x => x.Id) .ToList(); return(allApprenticeshipPriceEpisodeIds); }
public void ApprenticeshipsNotWithinADeliveryPeriodShouldReturnDLock09() { period = new EarningPeriod { Period = 1 }; var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { EffectiveTotalNegotiatedPriceStartDate = startDate, Identifier = priceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, AccountId = 21, 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) } }; calculatePeriodStartAndEndDate .Setup(x => x.GetPeriodDate(1, 1819)) .Returns(() => (new DateTime(2018, 8, 1), new DateTime(2018, 8, 31))); var validator = new StartDateValidator(calculatePeriodStartAndEndDate.Object); var result = validator.Validate(validation); result.DataLockErrorCode.Should().NotBeNull(); result.DataLockErrorCode.Should().Be(DataLockErrorCode.DLOCK_09); result.ApprenticeshipPriceEpisodes.Should().BeEmpty(); }
public void AssignsAllValidPriceEpisodes() { var validation = new DataLockValidationModel { PriceEpisode = new PriceEpisode { EffectiveTotalNegotiatedPriceStartDate = startDate, Identifier = priceEpisodeIdentifier }, EarningPeriod = period, Apprenticeship = new ApprenticeshipModel { Id = 1, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 1, StartDate = startDate.AddDays(-6), EndDate = startDate.AddDays(-5), }, new ApprenticeshipPriceEpisodeModel { Id = 2, StartDate = startDate.AddDays(-2), EndDate = startDate.AddDays(-1) }, new ApprenticeshipPriceEpisodeModel { Id = 3, StartDate = startDate }, new ApprenticeshipPriceEpisodeModel { Id = 4, StartDate = startDate.AddDays(-4), EndDate = startDate.AddDays(-3), }, } } }; var validator = new StartDateValidator(calculatePeriodStartAndEndDate.Object); var result = validator.Validate(validation); result.DataLockErrorCode.Should().BeNull(); result.ApprenticeshipPriceEpisodes[0].Id.Should().Be(1); result.ApprenticeshipPriceEpisodes[1].Id.Should().Be(2); result.ApprenticeshipPriceEpisodes[2].Id.Should().Be(3); result.ApprenticeshipPriceEpisodes[3].Id.Should().Be(4); }
public void Prepare() { mocker = AutoMock.GetStrict(); var earningPeriod = new EarningPeriod { Period = 1 }; dataLockValidationModel = new DataLockValidationModel { EarningPeriod = earningPeriod, PriceEpisode = new PriceEpisode(), Apprenticeship = new ApprenticeshipModel { Id = 1, Uln = 100, ApprenticeshipPriceEpisodes = new List <ApprenticeshipPriceEpisodeModel> { new ApprenticeshipPriceEpisodeModel { Id = 99, ApprenticeshipId = 1, Cost = 100, StartDate = DateTime.Today } } } }; mocker.Mock <IOnProgrammeAndIncentiveStoppedValidator>() .Setup(validator => validator.Validate(It.IsAny <DataLockValidationModel>())) .Returns(() => new ValidationResult()); mocker.Mock <ICompletionStoppedValidator>() .Setup(validator => validator.Validate(It.IsAny <DataLockValidationModel>())) .Returns(() => new ValidationResult()); mocker.Mock <IStartDateValidator>() .Setup(validator => validator.Validate(It.IsAny <DataLockValidationModel>())) .Returns(() => new ValidationResult()) .Verifiable(); negotiatedPriceValidator = new Mock <ICourseValidator>(); apprenticeshipPauseValidator = new Mock <ICourseValidator>(); courseValidators = new List <ICourseValidator> { negotiatedPriceValidator.Object, apprenticeshipPauseValidator.Object, }; mocker.Provide <List <ICourseValidator> >(courseValidators); }
protected override bool FailedValidation(DataLockValidationModel dataLockValidationModel, List <ApprenticeshipPriceEpisodeModel> validApprenticeshipPriceEpisodes) { //var apprenticeshipActualStartDate = GetApprenticeshipActualStartDate(dataLockValidationModel.Apprenticeship); //var apprenticeshipActualEndDate = GetApprenticeshipEstimatedEndDate(dataLockValidationModel.Apprenticeship); //var earningPeriodDate = calculatePeriodStartAndEndDate // .GetPeriodDate(dataLockValidationModel.EarningPeriod.Period, dataLockValidationModel.AcademicYear); //if (apprenticeshipActualStartDate >= earningPeriodDate.periodEndDate || // apprenticeshipActualEndDate <= earningPeriodDate.periodStartDate) // return false; //var allDuplicateApprenticeships = dataLockLearnerCache // .GetDuplicateApprenticeships() // .Result; //if (!allDuplicateApprenticeships.Any()) // return false; //// Apprenticeship has a duplicate //var duplicates = allDuplicateApprenticeships // .Where(x => x.Uln == dataLockValidationModel.Apprenticeship.Uln && // x.Status == ApprenticeshipStatus.Active && // x.Id != dataLockValidationModel.Apprenticeship.Id && // x.Ukprn != dataLockValidationModel.Apprenticeship.Ukprn) // .ToList(); //if (!duplicates.Any()) // return false; //foreach (var duplicate in duplicates) //{ // var duplicateActualStartDate = GetApprenticeshipActualStartDate(duplicate); // var duplicateActualEndDate = GetApprenticeshipEstimatedEndDate(duplicate); // if (duplicateActualStartDate >= earningPeriodDate.periodEndDate || // duplicateActualEndDate <= earningPeriodDate.periodStartDate) // continue; // // check if they have the same date range // if (apprenticeshipActualStartDate < duplicateActualEndDate && duplicateActualStartDate < apprenticeshipActualEndDate) // { // return true; // } //} return(false); }
private (List <DataLockFailure> dataLockFailures, List <long> invalidApprenticeshipPriceEpisodeIds) Validate( ICourseValidator courseValidator, DataLockValidationModel dataLockValidationModel, List <long> allApprenticeshipPriceEpisodeIds) { var dataLockFailures = new List <DataLockFailure>(); var invalidApprenticeshipPriceEpisodeIds = new List <long>(); CheckAndAddValidationResults( courseValidator, dataLockValidationModel, dataLockFailures, allApprenticeshipPriceEpisodeIds, invalidApprenticeshipPriceEpisodeIds); return(dataLockFailures, invalidApprenticeshipPriceEpisodeIds); }
public ValidationResult Validate(DataLockValidationModel dataLockValidationModel) { var result = CreateValidationResult(dataLockValidationModel); var validApprenticeshipPriceEpisodes = GetValidApprenticeshipPriceEpisodes(dataLockValidationModel); if (FailedValidation(dataLockValidationModel, validApprenticeshipPriceEpisodes)) { result.DataLockErrorCode = DataLockerErrorCode; } else { result.ApprenticeshipPriceEpisodes.AddRange(validApprenticeshipPriceEpisodes); } return(result); }
protected override CourseValidationResult ValidateApprenticeship( long uln, TransactionType transactionType, LearningAim aim, int academicYear, EarningPeriod period, ApprenticeshipModel apprenticeship, List <PriceEpisode> priceEpisodes = null) { var validationModel = new DataLockValidationModel { EarningPeriod = period, Apprenticeship = apprenticeship, TransactionType = transactionType, Aim = aim, AcademicYear = academicYear }; return(functionalSkillValidationProcessor.ValidateCourse(validationModel)); }
protected CourseValidationResult CreateValidationResult( DataLockValidationModel dataLockValidationModel, List <DataLockFailure> dataLockFailures, List <long> invalidApprenticeshipPriceEpisodeIds) { var result = new CourseValidationResult(); if (dataLockFailures.Any()) { result.DataLockFailures = dataLockFailures; } else { result.MatchedPriceEpisode = dataLockValidationModel.Apprenticeship .ApprenticeshipPriceEpisodes .FirstOrDefault(x => !x.Removed && !invalidApprenticeshipPriceEpisodeIds.Contains(x.Id)); } return(result); }