Beispiel #1
0
        public async Task Then_an_apprenticeship_incentive_created_event_is_raised_for_each_apprenticeship_in_the_application()
        {
            // Arrange
            var command = _fixture.Create <CreateIncentiveCommand>();

            Domain.ApprenticeshipIncentives.ApprenticeshipIncentive noExistingApprenticeshipIncentive = null;
            _mockIncentiveDomainRepository.Setup(x => x.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId)).ReturnsAsync(noExistingApprenticeshipIncentive);

            // Act
            await _sut.Handle(command);

            // Assert
            _mockIncentiveDomainRepository.Verify(r =>
                                                  r.Save(It.Is <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>(
                                                             i =>
                                                             i.Apprenticeship.Id == command.ApprenticeshipId &&
                                                             i.Apprenticeship.UniqueLearnerNumber == command.Uln &&
                                                             i.Apprenticeship.DateOfBirth == command.DateOfBirth &&
                                                             i.Apprenticeship.EmployerType == command.ApprenticeshipEmployerTypeOnApproval &&
                                                             i.Apprenticeship.FirstName == command.FirstName &&
                                                             i.Apprenticeship.LastName == command.LastName &&
                                                             i.Account.Id == command.AccountId &&
                                                             i.GetModel().SubmittedDate == command.SubmittedDate &&
                                                             i.GetModel().SubmittedByEmail == command.SubmittedByEmail &&
                                                             i.Apprenticeship.CourseName == command.CourseName &&
                                                             i.Apprenticeship.EmploymentStartDate == command.EmploymentStartDate &&
                                                             i.Phase.Identifier == command.Phase
                                                             )), Times.Once());
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _sut          = _fixture.Create <LearnerSubmissionDto>();
            _startDate    = DateTime.Now.AddMonths(-1);
            _endDate      = DateTime.Today.AddDays(-1);
            _periodNumber = 3;

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .Create();
            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startDate;
            _testPriceEpisodeDto.EndDate   = _endDate;

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testPeriodDto.Period           = _periodNumber;
            _testPeriodDto.IsPayable        = true;
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _sut = _fixture.Create <LearnerSubmissionDto>();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .Create();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testTrainingDto.PriceEpisodes.Clear();

            _testPriceEpisode1Dto = _fixture.Create <PriceEpisodeDto>();
            _testPriceEpisode1Dto.Periods.First().ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testTrainingDto.PriceEpisodes.Add(_testPriceEpisode1Dto);

            _testPriceEpisode2Dto         = _fixture.Create <PriceEpisodeDto>();
            _testPriceEpisode2Dto.EndDate = null;
            // probbaly not valid data but add multiple apprenticeship periods by price episode just in case
            _testPriceEpisode2Dto.Periods.ToList().ForEach(p => p.ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id);
            _testTrainingDto.PriceEpisodes.Add(_testPriceEpisode2Dto);

            _testTrainingDto.PriceEpisodes.Add(_fixture.Create <PriceEpisodeDto>()); // non matching

            _testPriceEpisode3Dto           = _fixture.Create <PriceEpisodeDto>();   // duplicate
            _testPriceEpisode3Dto.StartDate = _testPriceEpisode1Dto.StartDate;
            _testPriceEpisode3Dto.EndDate   = _testPriceEpisode1Dto.EndDate;
            _testPriceEpisode3Dto.Periods.First().ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testTrainingDto.PriceEpisodes.Add(_testPriceEpisode3Dto);
        }
        public async Task ArrangeAsync()
        {
            var today = new DateTime(2021, 1, 30);

            _fixture = new Fixture();

            _collectionPeriods = new List <Domain.ValueObjects.CollectionCalendarPeriod>()
            {
                new CollectionCalendarPeriod(
                    new Domain.ValueObjects.CollectionPeriod(1, (short)today.Year),
                    (byte)today.Month,
                    (short)today.Year,
                    today.AddDays(-1),
                    today.AddDays(-1),
                    false,
                    false),
                new CollectionCalendarPeriod(
                    new Domain.ValueObjects.CollectionPeriod(1, (short)today.AddMonths(1).Year),
                    (byte)today.AddMonths(1).Month,
                    (short)today.AddMonths(1).Year,
                    today.AddMonths(1).AddDays(-1),
                    today.AddMonths(1).AddDays(-1),
                    false,
                    false)
            };
            _firstCollectionPeriod = _collectionPeriods.First().CollectionPeriod;

            _mockIncentiveDomainRespository      = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockCollectionCalendarService       = new Mock <ICollectionCalendarService>();
            _mockIncentivePaymentProfilesService = new Mock <IIncentivePaymentProfilesService>();

            _incentive = await ApprenticeshipIncentiveCreator();

            _sut = new CreatePaymentCommandHandler(_mockIncentiveDomainRespository.Object);
        }
Beispiel #5
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _startDate = DateTime.Now;
            var dueDate = _startDate.AddMonths(1);

            var pendingPaymentModel = _fixture
                                      .Build <PendingPaymentModel>()
                                      .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                                      .With(p => p.DueDate, dueDate)
                                      .Create();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .With(p => p.PendingPaymentModels, new List <PendingPaymentModel> {
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, dueDate.AddMonths(1))
                .With(pp => pp.PaymentYear, (short?)null)
                .Create(),
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, dueDate.AddMonths(2))
                .With(pp => pp.PaymentYear, (short?)null)
                .Create(),
                pendingPaymentModel
            })
                                            .Create();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);
        }
Beispiel #6
0
        public void Then_is_false_when_the_incentive_is_null()
        {
            //Arrange
            _incentive = null;

            //Act
            var hasDataLock = _sut.HasProviderDataLocks(_incentive);

            //Assert
            hasDataLock.Should().BeFalse();
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _mockIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockLearnerDomainRepository   = new Mock <ILearnerDomainRepository>();

            var collectionPeriods = new List <CollectionCalendarPeriod>()
            {
                new CollectionCalendarPeriod(new Domain.ValueObjects.CollectionPeriod(1, _fixture.Create <short>()), _fixture.Create <byte>(), _fixture.Create <short>(), _fixture.Create <DateTime>(), _fixture.Create <DateTime>(), true, false),
            };
            var collectionCalendar = new Domain.ValueObjects.CollectionCalendar(collectionPeriods);

            _mockCollectionCalendarService = new Mock <ICollectionCalendarService>();
            _mockCollectionCalendarService.Setup(m => m.Get()).ReturnsAsync(collectionCalendar);

            _incentiveModel = _fixture
                              .Build <ApprenticeshipIncentiveModel>()
                              .With(p => p.Apprenticeship,
                                    new Apprenticeship(
                                        _fixture.Create <long>(),
                                        _fixture.Create <string>(),
                                        _fixture.Create <string>(),
                                        DateTime.Today.AddYears(-26),
                                        _fixture.Create <long>(),
                                        ApprenticeshipEmployerType.Levy,
                                        _fixture.Create <string>(),
                                        _fixture.Create <DateTime>()
                                        ))
                              .With(p => p.StartDate, DateTime.Today)
                              .With(p => p.Status, Enums.IncentiveStatus.Active)
                              .With(p => p.HasPossibleChangeOfCircumstances, true)
                              .With(p => p.Phase, new IncentivePhase(Phase.Phase1))
                              .With(p => p.MinimumAgreementVersion, new AgreementVersion(_fixture.Create <int>()))
                              .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>())
                              .Create();
            _incentiveModel.Apprenticeship.SetProvider(_fixture.Create <Provider>());
            _incentiveModel.HasPossibleChangeOfCircumstances = true;
            var incentive = new ApprenticeshipIncentiveFactory().GetExisting(_incentiveModel.Id, _incentiveModel);

            _fixture.Register(() => incentive);

            _sut = new LearnerChangeOfCircumstanceCommandHandler(_mockIncentiveDomainRepository.Object, _mockLearnerDomainRepository.Object, _mockCollectionCalendarService.Object);

            _incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();
            _learner   = new LearnerFactory().GetExisting(
                _fixture.Build <LearnerModel>()
                .With(x => x.SubmissionData, _fixture.Create <SubmissionData>())
                .With(x => x.ApprenticeshipIncentiveId, _incentive.Id)
                .Create());

            _mockIncentiveDomainRepository.Setup(x => x.Find(incentive.Id)).ReturnsAsync(_incentive);
            _mockLearnerDomainRepository.Setup(m => m.GetOrCreate(incentive)).ReturnsAsync(_learner);
        }
Beispiel #8
0
        public void Then_is_false_when_the_incentive_has_no_due_pending_payments()
        {
            //Arrange
            _apprenticeshipIncentiveModel.PendingPaymentModels.ToList().ForEach(p => p.PaymentMadeDate = _fixture.Create <DateTime>());
            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            //Act
            var hasDataLock = _sut.HasProviderDataLocks(_incentive);

            //Assert
            hasDataLock.Should().BeFalse();
        }
Beispiel #9
0
        public static bool IsInLearning(this LearnerSubmissionDto learnerData, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            // 1. For a given payment due date check whether due date falls in between
            // the start and end date of a price episode that contains a period with
            // a matching apprenticeship ID OR where there is no end date for the
            // price episode with a matching apprenticeship ID, the payment due date
            // is after the price episode start date
            // 2. If a price episode meeting criteria in step 1 is found, set InLearning
            // to True ELSE set InLearning to False

            if (incentive == null)
            {
                return(false);
            }
            var nextPayment = incentive.NextDuePayment;

            if (nextPayment == null)
            {
                return(false);
            }

            var matchedRecords =
                (from tr in learnerData.Training
                 where tr.Reference == PROGRAM_REFERENCE
                 from pe in tr.PriceEpisodes
                 from p in pe.Periods
                 where p.ApprenticeshipId == incentive.Apprenticeship.Id
                 select new
            {
                p.ApprenticeshipId,
                pe.StartDate,
                pe.EndDate,
                p.Period
            }).ToArray();

            var isInLearning = false;

            if (matchedRecords.Any())
            {
                foreach (var matchedRecord in matchedRecords)
                {
                    var endDate = matchedRecord.EndDate ?? nextPayment.DueDate;
                    if (nextPayment.DueDate >= matchedRecord.StartDate &&
                        nextPayment.DueDate <= endDate)
                    {
                        isInLearning = true;
                        break;
                    }
                }
            }

            return(isInLearning);
        }
Beispiel #10
0
        public void Then_is_false_when_the_next_pending_payment_due_has_a_null_periodNumber()
        {
            //Arrange
            _nextPendingPaymentDue.PeriodNumber = null;
            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            //Act
            var hasDataLock = _sut.HasProviderDataLocks(_incentive);

            //Assert
            hasDataLock.Should().BeFalse();
        }
        public void Then_false_is_returned_when_the_pending_payment_is_null()
        {
            //Arrange
            _apprenticeshipIncentiveModel.PendingPaymentModels.Clear();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            //Act
            var isInLearning = _sut.IsInLearning(_incentive);

            //Assert
            isInLearning.Should().BeFalse();
        }
Beispiel #12
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _dueDate = DateTime.Now.AddMonths(-1);
            short paymentYear = (short)DateTime.Now.Year;

            _periodNumber = _fixture.Create <byte>();

            _nextPendingPaymentDue = _fixture.Build <PendingPaymentModel>()
                                     .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                                     .With(pp => pp.PaymentYear, paymentYear)
                                     .With(pp => pp.PeriodNumber, _periodNumber)
                                     .With(pp => pp.DueDate, _dueDate)// earliest
                                     .Create();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(a => a.PendingPaymentModels, new List <PendingPaymentModel>()
            {
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, _dueDate.AddMonths(1))
                .With(pp => pp.PaymentYear, (short?)null)
                .Create(),
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, _dueDate.AddMonths(2))
                .With(pp => pp.PaymentYear, (short?)null)
                .Create(),
                _nextPendingPaymentDue
            })
                                            .Create();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            _sut       = _fixture.Create <LearnerSubmissionDto>();
            _startTime = _dueDate.AddDays(-10);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startTime;
            _testPriceEpisodeDto.EndDate   = _dueDate.AddDays(10);

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _incentive.Apprenticeship.Id;
            _testPeriodDto.IsPayable        = false;
            _testPeriodDto.Period           = _periodNumber;
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _sut          = _fixture.Create <LearnerSubmissionDto>();
            _startDate    = DateTime.Now;
            _endDate      = _startDate.AddMonths(2);
            _periodNumber = 3;
            var dueDate = _startDate.AddMonths(1);

            var pendingPaymentModel = _fixture
                                      .Build <PendingPaymentModel>()
                                      .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                                      .With(p => p.DueDate, dueDate)
                                      .Create();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .With(p => p.PendingPaymentModels, new List <PendingPaymentModel> {
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, dueDate.AddMonths(1))
                .With(pp => pp.CollectionPeriod, (Domain.ValueObjects.CollectionPeriod)null)
                .Create(),
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, dueDate.AddMonths(2))
                .With(pp => pp.CollectionPeriod, (Domain.ValueObjects.CollectionPeriod)null)
                .Create(),
                pendingPaymentModel
            })
                                            .Create();

            _incentive      = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);
            _pendingPayment = _incentive.PendingPayments.Single(p => p.Id == pendingPaymentModel.Id);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startDate;
            _testPriceEpisodeDto.EndDate   = _endDate;

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testPeriodDto.Period           = _periodNumber;
            _testPeriodDto.IsPayable        = true;
        }
        public void Arrange()
        {
            _fixture       = new Fixture();
            _testStartDate = _fixture.Create <DateTime>();
            _censusDate    = _testStartDate.AddDays(5);

            _mockApprenticeshipIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockLearnerDomainRepository = new Mock <ILearnerDomainRepository>();
            _mockLearnerService          = new Mock <ILearnerService>();
            _mockLogger = new Mock <ILogger <RefreshLearnerCommandHandler> >();

            var apprenticeship = _fixture.Create <Apprenticeship>();

            apprenticeship.SetProvider(_fixture.Create <Provider>());

            _incentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                              .With(p => p.Apprenticeship, apprenticeship)
                              .Create();

            _apprenticeshipIncentiveId = _incentiveModel.Id;
            _apprenticeshipIncentive   = new ApprenticeshipIncentiveFactory().GetExisting(_incentiveModel.Id, _incentiveModel);

            _mockApprenticeshipIncentiveDomainRepository
            .Setup(m => m.Find(_apprenticeshipIncentiveId))
            .ReturnsAsync(_apprenticeshipIncentive);

            _learnerSubmissionDto = _fixture.Create <LearnerSubmissionDto>();

            _mockLearnerService
            .Setup(m => m.Get(It.IsAny <Learner>()))
            .ReturnsAsync(_learnerSubmissionDto);

            _mockApprenticeshipIncentiveDomainRepository
            .Setup(m => m.Find(_apprenticeshipIncentiveId))
            .ReturnsAsync(_apprenticeshipIncentive);

            _learner = new LearnerFactory().GetExisting(_fixture.Create <LearnerModel>());

            _mockLearnerDomainRepository
            .Setup(m => m.GetOrCreate(_apprenticeshipIncentive))
            .ReturnsAsync(_learner);

            _sut = new RefreshLearnerCommandHandler(
                _mockLogger.Object,
                _mockApprenticeshipIncentiveDomainRepository.Object,
                _mockLearnerService.Object,
                _mockLearnerDomainRepository.Object);
        }
        public async Task <Learner> GetOrCreate(Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            var existing = await _learnerDataRepository.GetByApprenticeshipIncentiveId(incentive.Id);

            if (existing != null)
            {
                return(_learnerFactory.GetExisting(existing));
            }

            return(_learnerFactory.CreateNew(
                       Guid.NewGuid(),
                       incentive.Id,
                       incentive.Apprenticeship.Id,
                       incentive.Apprenticeship.Provider.Ukprn,
                       incentive.Apprenticeship.UniqueLearnerNumber
                       ));
        }
Beispiel #16
0
        public void Arrange()
        {
            _fixture = new Fixture();
            _mockIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockLearnerDomainRepository   = new Mock <ILearnerDomainRepository>();

            var incentiveModel = _fixture
                                 .Build <ApprenticeshipIncentiveModel>()
                                 .With(p => p.Apprenticeship,
                                       new Apprenticeship(
                                           _fixture.Create <long>(),
                                           _fixture.Create <string>(),
                                           _fixture.Create <string>(),
                                           DateTime.Today.AddYears(-26),
                                           _fixture.Create <long>(),
                                           ApprenticeshipEmployerType.Levy,
                                           _fixture.Create <string>(),
                                           _fixture.Create <DateTime>()
                                           ))
                                 .With(p => p.StartDate, DateTime.Today)
                                 .With(p => p.Status, Enums.IncentiveStatus.Active)
                                 .With(p => p.HasPossibleChangeOfCircumstances, true)
                                 .With(p => p.Phase, new IncentivePhase(Phase.Phase2))
                                 .With(p => p.MinimumAgreementVersion, new AgreementVersion(_fixture.Create <int>()))
                                 .With(p => p.PendingPaymentModels, new List <PendingPaymentModel>())
                                 .Create();

            var incentive = new ApprenticeshipIncentiveFactory().GetExisting(incentiveModel.Id, incentiveModel);

            _fixture.Register(() => incentive);
            _incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();
            _succeeded = _fixture.Create <bool>();

            _learner = new LearnerFactory().GetExisting(
                _fixture.Build <LearnerModel>()
                .With(x => x.SuccessfulLearnerMatch, !_succeeded)
                .With(x => x.ApprenticeshipIncentiveId, _incentive.Id)
                .Create());

            _mockIncentiveDomainRepository.Setup(x => x.Find(_incentive.Id)).ReturnsAsync(_incentive);
            _mockLearnerDomainRepository.Setup(m => m.GetOrCreate(_incentive)).ReturnsAsync(_learner);

            _sut = new SetSuccessfulLearnerMatchCommandHandler(
                _mockIncentiveDomainRepository.Object,
                _mockLearnerDomainRepository.Object);
        }
Beispiel #17
0
        // *** Conditions for Provider DataLock ***
        // 1. ZPROG001 reference
        // 2. PriceEpisode.StartDate <= NextPayment.DueDate => PriceEpisode.EndDate
        // 3. Period.Period == NextPayment.CollectionPeriod
        // 4. Period.ApprenticeshipId == ApprenticeshipIncentive.ApprenticeshipId
        // 5. Period.IsPayable == false
        public static bool HasProviderDataLocks(this LearnerSubmissionDto data, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            if (incentive == null)
            {
                return(false);
            }
            var nextPayment = incentive.NextDuePayment;

            if (nextPayment == null)
            {
                return(false);
            }

            var hasLock = data
                          .PaymentsForApprenticeship(incentive.Apprenticeship.Id, nextPayment.DueDate)
                          .Any(p => p.Period == nextPayment.PeriodNumber && !p.IsPayable);

            return(hasLock);
        }
Beispiel #18
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockLearnerDomainRespository   = new Mock <ILearnerDomainRepository>();

            var incentive = new ApprenticeshipIncentiveFactory()
                            .CreateNew(_fixture.Create <Guid>(),
                                       _fixture.Create <Guid>(),
                                       _fixture.Create <Account>(),
                                       new Apprenticeship(
                                           _fixture.Create <long>(),
                                           _fixture.Create <string>(),
                                           _fixture.Create <string>(),
                                           DateTime.Today.AddYears(-26),
                                           _fixture.Create <long>(),
                                           ApprenticeshipEmployerType.Levy,
                                           _fixture.Create <string>()
                                           ),
                                       DateTime.Today,
                                       _fixture.Create <DateTime>(),
                                       _fixture.Create <string>());

            incentive.SetHasPossibleChangeOfCircumstances(true);

            incentive.Apprenticeship.SetProvider(_fixture.Create <Provider>());

            _fixture.Register(() => incentive);

            _sut = new LearnerChangeOfCircumstanceCommandHandler(_mockIncentiveDomainRespository.Object, _mockLearnerDomainRespository.Object);

            _incentive = _fixture.Create <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>();
            _learner   = new LearnerFactory().GetExisting(
                _fixture.Build <LearnerModel>()
                .With(x => x.SubmissionData, _fixture.Create <SubmissionData>())
                .With(x => x.ApprenticeshipIncentiveId, _incentive.Id)
                .Create());

            _mockIncentiveDomainRespository.Setup(x => x.Find(incentive.Id)).ReturnsAsync(_incentive);
            _mockLearnerDomainRespository.Setup(m => m.GetOrCreate(incentive)).ReturnsAsync(_learner);
        }
        public async Task Save(Domain.ApprenticeshipIncentives.ApprenticeshipIncentive aggregate)
        {
            if (aggregate.IsNew)
            {
                await _apprenticeshipIncentiveDataRepository.Add(aggregate.GetModel());
            }
            else if (aggregate.IsDeleted)
            {
                await _apprenticeshipIncentiveDataRepository.Delete(aggregate.GetModel());
            }
            else
            {
                await _apprenticeshipIncentiveDataRepository.Update(aggregate.GetModel());
            }

            foreach (dynamic domainEvent in aggregate.FlushEvents())
            {
                await _domainEventDispatcher.Send(domainEvent);
            }
        }
Beispiel #20
0
        public void Arrange()
        {
            _fixture = new Fixture();

            var model = _fixture.Create <ApprenticeshipIncentiveModel>();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(model.Id, model);

            _sut       = _fixture.Create <LearnerSubmissionDto>();
            _startTime = DateTime.Now;

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startTime;

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _incentive.Apprenticeship.Id;
            _testPeriodDto.IsPayable        = true;
        }
 private bool LearnerAndEarningsHaveNotChanged(LearnerSubmissionDto learnerData, Learner learner, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
 {
     return(learnerData.IlrSubmissionDate == learner.SubmissionData?.SubmissionDate &&
            incentive.RefreshedLearnerForEarnings);
 }
        public static LearningStoppedStatus IsStopped(this LearnerSubmissionDto learnerData, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            var learningStoppedStatus = new LearningStoppedStatus(false);

            if (incentive == null)
            {
                return(learningStoppedStatus);
            }

            var matchedRecords =
                (from tr in learnerData.Training
                 where tr.Reference == PROGRAM_REFERENCE
                 from pe in tr.PriceEpisodes
                 from p in pe.Periods
                 where p.ApprenticeshipId == incentive.Apprenticeship.Id
                 select new
            {
                p.ApprenticeshipId,
                pe.StartDate,
                pe.EndDate,
            }).ToArray();

            if (matchedRecords.Any())
            {
                var latestPriceEpisode = matchedRecords.OrderByDescending(m => m.StartDate).First();

                if (latestPriceEpisode.EndDate.HasValue && latestPriceEpisode.EndDate.Value.Date < DateTime.Today.Date)
                {
                    learningStoppedStatus = new LearningStoppedStatus(true, latestPriceEpisode.EndDate.Value.AddDays(1));
                }
                else
                {
                    learningStoppedStatus = new LearningStoppedStatus(false, latestPriceEpisode.StartDate);
                }
            }

            return(learningStoppedStatus);
        }
Beispiel #23
0
        public static DateTime?LearningStartDate(this LearnerSubmissionDto learnerData, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            // To determine which price episode to look at requires looking at the Payable Periods within a Price Episode, because Payable Periods are labelled with the Apprenticeship ID.
            // searching for the earliest period with an apprenticeship Id that matches the commitment
            // the apprenticeship StartDate is the Start Date of the price episode to which that period belongs
            // this might be different to the “Start Date” for the “Training”, because the “Training” start date won’t update if there is a change of employer

            var matchedRecords =
                (from tr in learnerData.Training
                 where tr.Reference == PROGRAM_REFERENCE
                 from pe in tr.PriceEpisodes
                 from p in pe.Periods
                 where p.ApprenticeshipId == incentive.Apprenticeship.Id
                 select new
            {
                p.ApprenticeshipId,
                pe.StartDate
            }).ToArray();

            if (matchedRecords.Any())
            {
                return(matchedRecords.OrderBy(m => m.StartDate).First().StartDate);
            }

            return(null);
        }
Beispiel #24
0
        public static IEnumerable <LearningPeriod> LearningPeriods(this LearnerSubmissionDto learnerData, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            if (learnerData == null)
            {
                return(new List <LearningPeriod>());
            }

            return
                ((from tr in learnerData.Training
                  where tr.Reference == PROGRAM_REFERENCE
                  from pe in tr.PriceEpisodes
                  from p in pe.Periods
                  where p.ApprenticeshipId == incentive.Apprenticeship.Id
                  select new LearningPeriod(pe.StartDate, pe.EndDate)).Distinct());
        }
Beispiel #25
0
        public static LearningFoundStatus LearningFound(this LearnerSubmissionDto data, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
        {
            if (data.Training == null || !data.Training.Any())
            {
                return(new LearningFoundStatus("No learning aims were found"));
            }

            if (data.Training.All(t => t.Reference != PROGRAM_REFERENCE))
            {
                return(new LearningFoundStatus("Learning aims were found for the ULN, but none of them had a reference of ZPROG001"));
            }

            if (!data.Training.Any(t => t.Reference == PROGRAM_REFERENCE && t.PriceEpisodes.Count > 0))
            {
                return(new LearningFoundStatus("A ZPROG001 aim was found, but it had no price episodes"));
            }

            if (!data.PaymentsForApprenticeship(incentive.Apprenticeship.Id).Any())
            {
                return(new LearningFoundStatus("A ZPROG001 aim was found, with price episodes, but with no periods with the apprenticeship id that matches the commitment"));
            }

            return(new LearningFoundStatus());
        }
 public Task <Learner> Get(Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
 {
     return(_domainRepository.Get(incentive));
 }
 public async Task <Learner> Get(Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
 {
     return(_learnerFactory.GetExisting(await _learnerDataRepository.GetByApprenticeshipIncentiveId(incentive.Id)));
 }