public async Task Then_the_inlearning_flag_is_null_when_there_are_no_pending_payments()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <TrainingDto>(),
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .Create(),
                _fixture.Create <TrainingDto>()
            })
                                       .Create();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => l.SubmissionData.LearningData.IsInlearning == null)
                                                    ), Times.Once);
        }
예제 #2
0
        public async Task Then_the_learning_stopped_status_has_false_stopped_flag_when_there_are_no_matching_learner_records()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <TrainingDto>(),
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .Create(),
                _fixture.Create <TrainingDto>()
            })
                                       .Create();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => !l.SubmissionData.LearningData.StoppedStatus.LearningStopped)
                                                    ), Times.Once);
        }
        public async Task Then_a_Learner_record_is_updated_when_it_already_exist()
        {
            // Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

            // Act
            await _sut.Handle(command);

            // Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(_learner), Times.Once);
        }
        public async Task Then_the_startdate_is_set_when_one_exists_for_the_learner_data()
        {
            //Arrange

            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <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, _incentiveModel.Apprenticeship.Id)
                        .With(period => period.IsPayable, true)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _testStartDate)
                    .With(pe => pe.EndDate, _testStartDate.AddDays(2))
                    .Create()
                }
                      )
                .Create(),
                _fixture.Create <TrainingDto>()
            }
                                             )
                                       .Create();

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

            _censusDate = _testStartDate.AddDays(5);

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => l.SubmissionData.LearningData.StartDate == _testStartDate)
                                                    ), Times.Once);
        }
        public async Task Then_the_learner_submissionfound_is_false_when_the_learner_data_does_not_exist()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

            _mockLearnerService
            .Setup(m => m.Get(It.IsAny <Learner>()))
            .ReturnsAsync(null as LearnerSubmissionDto);

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => !l.SubmissionData.SubmissionFound)
                                                    ), Times.Once);
        }
        public async Task Then_the_learning_not_found_reason_is_logged() // EI-490
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);
            var learnerSubmissionDto = _fixture.Create <LearnerSubmissionDto>();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLogger.VerifyLogContains(LogLevel.Information, Times.Once(), $"Start Learner data refresh from Learner match service for ApprenticeshipIncentiveId: {_learner.ApprenticeshipIncentiveId}, ApprenticeshipId: {_learner.ApprenticeshipId}, UKPRN: {_learner.Ukprn}, ULN: {_learner.UniqueLearnerNumber}");
            _mockLogger.VerifyLogContains(LogLevel.Information, Times.Once(), $"End Learner data refresh from Learner match service for ApprenticeshipIncentiveId: {_learner.ApprenticeshipIncentiveId}, ApprenticeshipId: {_learner.ApprenticeshipId}, UKPRN: {_learner.Ukprn}, ULN: {_learner.UniqueLearnerNumber}");
            _mockLogger.VerifyLogContains(LogLevel.Information, Times.Once(), $"Matching ILR record not found for ApprenticeshipIncentiveId: {_learner.ApprenticeshipIncentiveId}, ApprenticeshipId: {_learner.ApprenticeshipId}, UKPRN: {_learner.Ukprn}, ULN: {_learner.UniqueLearnerNumber} with reason: {_learner.SubmissionData.LearningData.NotFoundReason}");
        }
        public async Task Then_the_learning_found_is_false_when_there_are_no_matching_training_entries_returned_from_the_learner_service()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);
            var learnerSubmissionDto = _fixture.Create <LearnerSubmissionDto>();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => !l.SubmissionData.LearningData.LearningFound)
                                                    ), Times.Once);
        }
        public async Task Then_the_learning_found_is_true_when_there_are_matching_training_entries_returned_from_the_learner_service()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);
            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <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(p => p.ApprenticeshipId, _apprenticeshipIncentive.Apprenticeship.Id)
                        .Create()
                    })
                    .With(pe => pe.StartDate, _testStartDate)
                    .With(pe => pe.EndDate, _testStartDate.AddDays(2))
                    .Create()
                })
                .Create(),
                _fixture.Create <TrainingDto>()
            })
                                       .Create();

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

            _censusDate = _testStartDate.AddDays(5);

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => l.SubmissionData.LearningData.LearningFound)
                                                    ), Times.Once);
        }
        public async Task Then_the_submission_date_is_true_the_learner_data_exists()
        {
            //Arrange
            var command  = new RefreshLearnerCommand(_apprenticeshipIncentiveId);
            var testDate = DateTime.Now.AddDays(-1);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.IlrSubmissionDate, testDate)
                                       .Create();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => l.SubmissionData.SubmissionDate == testDate)
                                                    ), Times.Once);
        }
        public async Task Then_the_LearningPeriods_are_set_when_there_are_price_episodes_with_periods_for_the_apprenticeship()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

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

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

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

            _mockApprenticeshipIncentiveDomainRepository
            .Setup(m => m.Find(_apprenticeshipIncentiveId))
            .ReturnsAsync(new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.ApplicationApprenticeshipId, apprenticeshipIncentiveModel));

            var apprenticeshipIncentive = new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.Id, apprenticeshipIncentiveModel);

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

            _mockLearnerDomainRepository
            .Setup(m => m.GetOrCreate(apprenticeshipIncentive))
            .ReturnsAsync(learner);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <TrainingDto>(),
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(t => t.PriceEpisodes,
                      new List <PriceEpisodeDto> {
                    _fixture
                    .Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods,
                          new List <PeriodDto> {
                        _fixture
                        .Build <PeriodDto>()
                        .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id)
                        .Create()
                    })
                    .Create()
                }).Create(),
                _fixture.Create <TrainingDto>()
            })
                                       .Create();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => l.GetModel().LearningPeriods.Count == 1)
                                                    ), Times.Once);
        }
        public async Task Then_the_inlearning_flag_is_true_when_there_is_a_pending_payment_with_a_matching_inlearning_period()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

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

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

            var pendingPaymentModel = _fixture.Create <PendingPaymentModel>();

            pendingPaymentModel.PaymentMadeDate = null;

            var apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                               .With(p => p.Apprenticeship, apprenticeship)
                                               .With(p => p.PendingPaymentModels, new List <PendingPaymentModel> {
                pendingPaymentModel
            })
                                               .Create();

            _mockApprenticeshipIncentiveDomainRepository
            .Setup(m => m.Find(_apprenticeshipIncentiveId))
            .ReturnsAsync(new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.ApplicationApprenticeshipId, apprenticeshipIncentiveModel));

            var apprenticeshipIncentive = new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.Id, apprenticeshipIncentiveModel);

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

            _mockLearnerDomainRepository
            .Setup(m => m.GetOrCreate(apprenticeshipIncentive))
            .ReturnsAsync(learner);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <TrainingDto>(),
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(t => t.PriceEpisodes,
                      new List <PriceEpisodeDto> {
                    _fixture
                    .Build <PriceEpisodeDto>()
                    .With(pe => pe.StartDate, pendingPaymentModel.DueDate.AddDays(-1))
                    .With(pe => pe.EndDate, pendingPaymentModel.DueDate.AddDays(1))
                    .With(pe => pe.Periods,
                          new List <PeriodDto> {
                        _fixture
                        .Build <PeriodDto>()
                        .With(p => p.Period, pendingPaymentModel.PeriodNumber)
                        .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id)
                        .Create()
                    })
                    .Create()
                }).Create(),
                _fixture.Create <TrainingDto>()
            })
                                       .Create();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => l.SubmissionData.LearningData.IsInlearning == true)
                                                    ), Times.Once);
        }
예제 #12
0
        public async Task Then_the_learning_stopped_status_has_false_stopped_flag_when_there_are_matching_learner_records_and_the_learning_has_resumed_from_stopped()
        {
            //Arrange
            var command = new RefreshLearnerCommand(_apprenticeshipIncentiveId);

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

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

            var apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                               .With(p => p.Apprenticeship, apprenticeship)
                                               .With(p => p.Status, Enums.IncentiveStatus.Stopped)
                                               .Create();

            _mockApprenticeshipIncentiveDomainRepository
            .Setup(m => m.Find(_apprenticeshipIncentiveId))
            .ReturnsAsync(new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.ApplicationApprenticeshipId, apprenticeshipIncentiveModel));

            var apprenticeshipIncentive = new ApprenticeshipIncentiveFactory().GetExisting(apprenticeshipIncentiveModel.Id, apprenticeshipIncentiveModel);

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

            _mockLearnerDomainRepository
            .Setup(m => m.GetOrCreate(apprenticeshipIncentive))
            .ReturnsAsync(learner);

            var learnerSubmissionDto = _fixture
                                       .Build <LearnerSubmissionDto>()
                                       .With(l => l.Training, new List <TrainingDto> {
                _fixture.Create <TrainingDto>(),
                _fixture
                .Build <TrainingDto>()
                .With(p => p.Reference, "ZPROG001")
                .With(t => t.PriceEpisodes,
                      new List <PriceEpisodeDto> {
                    _fixture
                    .Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods,
                          new List <PeriodDto> {
                        _fixture
                        .Build <PeriodDto>()
                        .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id)
                        .Create()
                    })
                    .With(pe => pe.StartDate, DateTime.Today.AddDays(-20))
                    .With(pe => pe.EndDate, DateTime.Today.AddDays(10))
                    .Create(),
                    _fixture
                    .Build <PriceEpisodeDto>()
                    .With(pe => pe.Periods,
                          new List <PeriodDto> {
                        _fixture
                        .Build <PeriodDto>()
                        .With(p => p.ApprenticeshipId, apprenticeshipIncentive.Apprenticeship.Id)
                        .Create()
                    })
                    .With(pe => pe.StartDate, DateTime.Today.AddDays(-10))
                    .With(pe => pe.EndDate, DateTime.Today)
                    .Create()
                }).Create(),
                _fixture.Create <TrainingDto>()
            })
                                       .Create();

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

            //Act
            await _sut.Handle(command);

            //Assert
            _mockLearnerDomainRepository.Verify(m => m.Save(
                                                    It.Is <Learner>(l => !l.SubmissionData.LearningData.StoppedStatus.LearningStopped &&
                                                                    l.SubmissionData.LearningData.StoppedStatus.DateResumed.HasValue &&
                                                                    !l.SubmissionData.LearningData.StoppedStatus.DateStopped.HasValue)
                                                    ), Times.Once);
        }