Exemplo n.º 1
0
        public async Task Then_the_existing_learner_is_returned()
        {
            // Arrange
            var incentiveModel = _fixture.Create <ApprenticeshipIncentiveModel>();
            var payments       = _fixture.Build <PendingPaymentModel>()
                                 .With(pp => pp.ApprenticeshipIncentiveId, incentiveModel.ApplicationApprenticeshipId)
                                 .Without(pp => pp.PaymentMadeDate) // null for "not paid"
                                 .CreateMany(5).ToArray();

            payments[0].DueDate                 = DateTime.Parse("01/09/2020", new CultureInfo("en-GB"));
            payments[0].PaymentMadeDate         = DateTime.Parse("30/09/2020", new CultureInfo("en-GB"));
            payments[1].DueDate                 = DateTime.Parse("01/10/2020", new CultureInfo("en-GB")); // next pending payment
            payments[2].DueDate                 = DateTime.Parse("01/11/2020", new CultureInfo("en-GB"));
            payments[3].DueDate                 = DateTime.Parse("01/12/2020", new CultureInfo("en-GB"));
            payments[4].DueDate                 = DateTime.Parse("01/01/2021", new CultureInfo("en-GB"));
            incentiveModel.PendingPaymentModels = payments;

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

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

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

            _learnerDataRepositoryMock.Setup(r => r.GetByApprenticeshipIncentiveId(incentive.Id)).ReturnsAsync(learner);

            // Act
            var result = await _sut.GetOrCreate(incentive);

            // Assert
            result.Id.Should().Be(learner.Id, "should return existing");
        }
Exemplo n.º 2
0
        public async Task Handle(RefreshLearnerCommand command, CancellationToken cancellationToken = default)
        {
            var incentive = await _incentiveDomainRepository.Find(command.ApprenticeshipIncentiveId);

            var learner = await _learnerDomainRepository.GetOrCreate(incentive);

            _logger.LogInformation("Start Learner data refresh from Learner match service for ApprenticeshipIncentiveId: {ApprenticeshipIncentiveId}, ApprenticeshipId: {ApprenticeshipId}, UKPRN: {UKPRN}, ULN: {ULN}",
                                   learner.ApprenticeshipIncentiveId, learner.ApprenticeshipId, learner.Ukprn, learner.UniqueLearnerNumber);

            SubmissionData submissionData = new SubmissionData();
            var            learnerData    = await _learnerService.Get(learner);

            _logger.LogInformation("End Learner data refresh from Learner match service for ApprenticeshipIncentiveId: {ApprenticeshipIncentiveId}, ApprenticeshipId: {ApprenticeshipId}, UKPRN: {UKPRN}, ULN: {ULN}",
                                   learner.ApprenticeshipIncentiveId, learner.ApprenticeshipId, learner.Ukprn, learner.UniqueLearnerNumber);

            if (learnerData != null)
            {
                if (LearnerAndEarningsHaveNotChanged(learnerData, learner, incentive))
                {
                    return;
                }

                submissionData.SetSubmissionDate(learnerData.IlrSubmissionDate);

                var learningFoundStatus = learnerData.LearningFound(incentive);
                submissionData.SetLearningData(new LearningData(learningFoundStatus.LearningFound, learningFoundStatus.NotFoundReason));

                if (learningFoundStatus.LearningFound)
                {
                    submissionData.LearningData.SetStartDate(learnerData.LearningStartDate(incentive));
                    submissionData.LearningData.SetHasDataLock(learnerData.HasProviderDataLocks(incentive));
                    submissionData.LearningData.SetIsInLearning(learnerData.IsInLearning(incentive));
                    submissionData.LearningData.SetIsStopped(learnerData.IsStopped(incentive));
                }
                submissionData.SetRawJson(learnerData.RawJson);
            }

            if (submissionData.HasChangeOfCircumstances(learner.SubmissionData))
            {
                incentive.SetHasPossibleChangeOfCircumstances(true);
            }

            learner.SetSubmissionData(submissionData);
            incentive.LearnerRefreshCompleted();

            learner.SetLearningPeriods(learnerData.LearningPeriods(incentive));

            if (!learner.SubmissionData.LearningData.LearningFound)
            {
                _logger.LogInformation("Matching ILR record not found for ApprenticeshipIncentiveId: {ApprenticeshipIncentiveId}, ApprenticeshipId: {ApprenticeshipId}, UKPRN: {UKPRN}, ULN: {ULN} with reason: {NotFoundReason}",
                                       learner.ApprenticeshipIncentiveId, learner.ApprenticeshipId, learner.Ukprn, learner.UniqueLearnerNumber, learner.SubmissionData.LearningData.NotFoundReason);
            }

            await _learnerDomainRepository.Save(learner);

            await _incentiveDomainRepository.Save(incentive);
        }
Exemplo n.º 3
0
        public async Task Handle(LearnerChangeOfCircumstanceCommand command, CancellationToken cancellationToken = default)
        {
            var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId);

            if (!incentive.HasPossibleChangeOfCircumstances)
            {
                return;
            }

            var learner = await _learnerDomainRepository.GetOrCreate(incentive);

            incentive.SetChangeOfCircumstances(learner);

            await _domainRepository.Save(incentive);
        }
Exemplo n.º 4
0
        public async Task Handle(SetSuccessfulLearnerMatchCommand command, CancellationToken cancellationToken = default)
        {
            var incentive = await _incentiveDomainRepository.Find(command.ApprenticeshipIncentiveId);

            if (incentive == null)
            {
                return;
            }

            var learner = await _learnerDomainRepository.GetOrCreate(incentive);

            learner.SetSuccessfulLearnerMatch(command.Succeeded);

            await _learnerDomainRepository.Save(learner);
        }
Exemplo n.º 5
0
        public async Task Handle(ValidatePendingPaymentCommand command, CancellationToken cancellationToken = default)
        {
            var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId);

            var account = await _accountDomainRepository.Find(incentive.Account.Id);

            var learner = await _learnerDomainRepository.GetOrCreate(incentive);

            var calendar = await _collectionCalendarService.Get();

            var collectionPeriod = calendar.GetPeriod(command.CollectionYear, command.CollectionPeriod);

            incentive.ValidatePendingPaymentBankDetails(command.PendingPaymentId, account, collectionPeriod);
            incentive.ValidateLearningData(command.PendingPaymentId, learner, collectionPeriod);
            incentive.ValidatePaymentsNotPaused(command.PendingPaymentId, collectionPeriod);

            await _domainRepository.Save(incentive);
        }
 public Task <Learner> GetOrCreate(Domain.ApprenticeshipIncentives.ApprenticeshipIncentive incentive)
 {
     return(_domainRepository.GetOrCreate(incentive));
 }