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);
        }
Esempio n. 3
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;
        }
Esempio n. 4
0
 private void SetupMockLearnerMatchResponse(LearnerSubmissionDto learnerMatchApiData)
 {
     _testContext.LearnerMatchApi.MockServer
     .Given(
         Request
         .Create()
         .WithPath($"/api/v1.0/{_apprenticeshipIncentive.UKPRN}/{_apprenticeshipIncentive.ULN}")
         .UsingGet()
         )
     .RespondWith(Response.Create()
                  .WithStatusCode(HttpStatusCode.OK)
                  .WithHeader("Content-Type", "application/json")
                  .WithBodyAsJson(learnerMatchApiData));
 }
        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);
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        public LearningStoppedSteps(TestContext testContext)
        {
            _testContext = testContext;
            _fixture     = new Fixture();

            _plannedStartDate = new DateTime(2020, 8, 1);
            _breakInLearning  = 15;
            _accountModel     = _fixture.Create <Account>();

            _apprenticeshipIncentive = _fixture.Build <ApprenticeshipIncentive>()
                                       .With(p => p.DateOfBirth, _plannedStartDate.AddYears(-24).AddMonths(-10)) // under 25
                                       .With(p => p.AccountId, _accountModel.Id)
                                       .With(p => p.AccountLegalEntityId, _accountModel.AccountLegalEntityId)
                                       .With(p => p.HasPossibleChangeOfCircumstances, false)
                                       .With(p => p.StartDate, new DateTime(2020, 11, 1))
                                       .With(p => p.Phase, Phase.Phase1)
                                       .Create();

            _pendingPayment = _fixture.Build <PendingPayment>()
                              .With(p => p.AccountId, _accountModel.Id)
                              .With(p => p.ApprenticeshipIncentiveId, _apprenticeshipIncentive.Id)
                              .With(p => p.DueDate, _plannedStartDate.AddMonths(1))
                              .With(p => p.ClawedBack, false)
                              .With(p => p.EarningType, EarningType.FirstPayment)
                              .Without(p => p.PaymentMadeDate)
                              .Create();

            _periodEndDate = DateTime.Today.AddDays(-10);

            _learner = _fixture
                       .Build <Learner>()
                       .With(p => p.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                       .With(p => p.ApprenticeshipIncentiveId, _apprenticeshipIncentive.Id)
                       .With(p => p.ULN, _apprenticeshipIncentive.ULN)
                       .With(p => p.Ukprn, _apprenticeshipIncentive.UKPRN)
                       .With(p => p.LearningFound, true)
                       .With(p => p.StartDate, _plannedStartDate.AddDays(-10))
                       .Create();

            _learningPeriod1 = _fixture
                               .Build <LearningPeriod>()
                               .With(p => p.LearnerId, _learner.Id)
                               .With(p => p.StartDate, _plannedStartDate.AddDays(-20).AddDays(_breakInLearning * -1))
                               .With(p => p.EndDate, _plannedStartDate.AddDays(-10).AddDays(_breakInLearning * -1))
                               .Create();

            _stoppedLearnerMatchApiData = _fixture
                                          .Build <LearnerSubmissionDto>()
                                          .With(s => s.Ukprn, _apprenticeshipIncentive.UKPRN)
                                          .With(s => s.Uln, _apprenticeshipIncentive.ULN)
                                          .With(l => l.Training, new List <TrainingDto> {
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(p => p.PriceEpisodes, new List <PriceEpisodeDto>()
                {
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _pendingPayment.PeriodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _plannedStartDate)
                    .With(pe => pe.EndDate, _periodEndDate)
                    .Create()
                }
                      )
                .Create()
            }
                                                )
                                          .Create();

            _resumedLearnerMatchApiData = _fixture
                                          .Build <LearnerSubmissionDto>()
                                          .With(s => s.Ukprn, _apprenticeshipIncentive.UKPRN)
                                          .With(s => s.Uln, _apprenticeshipIncentive.ULN)
                                          .With(l => l.Training, new List <TrainingDto> {
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(p => p.PriceEpisodes, new List <PriceEpisodeDto>()
                {
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _pendingPayment.PeriodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _plannedStartDate)
                    .With(pe => pe.EndDate, DateTime.Today.AddDays(10))
                    .Create()
                }
                      )
                .Create()
            }
                                                )
                                          .Create();

            _resumedLearnerWithBreakInLearningMatchApiData = _fixture
                                                             .Build <LearnerSubmissionDto>()
                                                             .With(s => s.Ukprn, _apprenticeshipIncentive.UKPRN)
                                                             .With(s => s.Uln, _apprenticeshipIncentive.ULN)
                                                             .With(l => l.Training, new List <TrainingDto> {
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(p => p.PriceEpisodes, new List <PriceEpisodeDto>()
                {
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _pendingPayment.PeriodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _plannedStartDate)
                    .With(pe => pe.EndDate, DateTime.Today.AddDays(_breakInLearning * -1))
                    .Create(),
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _pendingPayment.PeriodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, DateTime.Today)
                    .With(pe => pe.EndDate, DateTime.Today.AddDays(10))
                    .Create()
                }
                      )
                .Create()
            }
                                                                   )
                                                             .Create();

            _apprenticeshipBreakInLearning = _fixture
                                             .Build <ApprenticeshipBreakInLearning>()
                                             .With(b => b.ApprenticeshipIncentiveId, _apprenticeshipIncentive.Id)
                                             .With(b => b.StartDate, _plannedStartDate.AddDays(_breakInLearning * -1))
                                             .With(b => b.EndDate, (DateTime?)null)
                                             .Create();

            _resumedLearnerWithIncorrectlyRecordedBreakInLearningMatchApiData = _fixture
                                                                                .Build <LearnerSubmissionDto>()
                                                                                .With(s => s.Ukprn, _apprenticeshipIncentive.UKPRN)
                                                                                .With(s => s.Uln, _apprenticeshipIncentive.ULN)
                                                                                .With(l => l.Training, new List <TrainingDto>
            {
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(p => p.PriceEpisodes, new List <PriceEpisodeDto>()
                {
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId,
                              _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _pendingPayment.PeriodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _apprenticeshipBreakInLearning.StartDate)
                    .With(pe => pe.EndDate, DateTime.Today.AddMonths(12))
                    .Create(),
                }
                      )
                .Create()
            }
                                                                                      )
                                                                                .Create();
        }
Esempio n. 9
0
        public async Task GivenTheStoppedDateIsBeforeOnAfterTheOriginalFirstPaymentDueDate(string whenStopped)
        {
            switch (whenStopped)
            {
            case "Before":
                _stoppedDate = _pendingPayment.DueDate.AddDays(-1);
                break;

            case "On":
                _stoppedDate = _pendingPayment.DueDate;
                break;

            case "After":
                _stoppedDate = _pendingPayment.DueDate.AddDays(1);
                break;

            default:
                Assert.Fail();
                break;
            }

            _apprenticeshipBreakInLearning.StartDate = _stoppedDate.AddDays(1);

            using (var dbConnection = new SqlConnection(_testContext.SqlDatabase.DatabaseInfo.ConnectionString))
            {
                await dbConnection.InsertAsync(_apprenticeshipBreakInLearning);
            }

            _resumedLearnerMatchApiData = _fixture
                                          .Build <LearnerSubmissionDto>()
                                          .With(s => s.Ukprn, _apprenticeshipIncentive.UKPRN)
                                          .With(s => s.Uln, _apprenticeshipIncentive.ULN)
                                          .With(l => l.Training, new List <TrainingDto> {
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(p => p.PriceEpisodes, new List <PriceEpisodeDto>()
                {
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _periodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _plannedStartDate)
                    .With(pe => pe.EndDate, _stoppedDate)
                    .Create(),
                    _fixture.Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods, new List <PeriodDto>()
                    {
                        _fixture.Build <PeriodDto>()
                        .With(period => period.ApprenticeshipId, _apprenticeshipIncentive.ApprenticeshipId)
                        .With(period => period.IsPayable, true)
                        .With(period => period.Period, _periodNumber)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _stoppedDate.AddDays(_breakInLearning))
                    .With(pe => pe.EndDate, (DateTime?)null)
                    .Create()
                }
                      )
                .Create()
            }
                                                )
                                          .Create();

            SetupMockLearnerMatchResponse(_resumedLearnerMatchApiData);
        }
 private bool LearnerAndEarningsHaveNotChanged(LearnerSubmissionDto learnerData, Learner learner, Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
 {
     return(learnerData.IlrSubmissionDate == learner.SubmissionData?.SubmissionDate &&
            incentive.RefreshedLearnerForEarnings);
 }