Exemplo n.º 1
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _collectionYear = _fixture.Create <short>();

            _collectionPeriod = new CollectionPeriod(1, _collectionYear);

            _fixture.Build <PendingPaymentModel>().With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create();

            _sutModel = _fixture
                        .Build <ApprenticeshipIncentiveModel>()
                        .With(a => a.PendingPaymentModels, new List <PendingPaymentModel>()
            {
                _fixture.Build <PendingPaymentModel>().With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create()
            })
                        .Create();

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

            _learner = Learner.New(
                Guid.NewGuid(),
                _sutModel.Id,
                _sutModel.Apprenticeship.Id,
                _sutModel.Apprenticeship.Provider.Ukprn,
                _sutModel.Apprenticeship.UniqueLearnerNumber);

            var submisssionData = new SubmissionData();

            submisssionData.SetSubmissionDate(DateTime.Now);
            _learner.SetSubmissionData(submisssionData);

            _sut = Sut(_sutModel);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

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

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

            _sutModel = _fixture.Build <ApprenticeshipIncentiveModel>().With(x => x.Status, IncentiveStatus.Active).Create();
            _sutModel.PendingPaymentModels = new List <PendingPaymentModel>();
            _sutModel.PendingPaymentModels.Add(_fixture.Build <PendingPaymentModel>().With(x => x.DueDate, new DateTime(2021, 1, 1)).With(x => x.ClawedBack, false).With(x => x.PaymentMadeDate, (DateTime?)null).Create());
            _sutModel.PendingPaymentModels.Add(_fixture.Build <PendingPaymentModel>().With(x => x.DueDate, new DateTime(2021, 2, 28)).With(x => x.ClawedBack, false).With(x => x.PaymentMadeDate, (DateTime?)null).Create());
            _sutModel.PaymentModels         = new List <PaymentModel>();
            _sutModel.ClawbackPaymentModels = new List <ClawbackPaymentModel>();
            _sut = Sut(_sutModel);

            var learningData = new LearningData(true);

            learningData.SetIsStopped(new LearningStoppedStatus(true, _sutModel.PendingPaymentModels.Last().DueDate.AddDays(-1)));
            var submissionData = new SubmissionData();

            submissionData.SetSubmissionDate(DateTime.Now);
            submissionData.SetLearningData(learningData);
            _learner = Learner.New(_fixture.Create <Guid>(), _sutModel.Id, _fixture.Create <long>(), _fixture.Create <long>(), _fixture.Create <long>());
            _learner.SetSubmissionData(submissionData);
        }
Exemplo n.º 3
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);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockCollectionCalendarService  = new Mock <ICollectionCalendarService>();
            _mockAccountDomainRepository    = new Mock <IAccountDomainRepository>();
            _mockLearnerDomainRepository    = new Mock <ILearnerDomainRepository>();

            _startDate       = DateTime.Today;
            _payment1DueDate = _startDate.AddDays(10);

            _collectionCalendarPeriods = new List <Domain.ValueObjects.CollectionCalendarPeriod>()
            {
                new Domain.ValueObjects.CollectionCalendarPeriod(
                    new Domain.ValueObjects.CollectionPeriod(1, (short)DateTime.Now.Year),
                    (byte)DateTime.Now.Month,
                    (short)DateTime.Now.Year,
                    DateTime.Now.AddDays(-1),
                    DateTime.Now,
                    true,
                    false)
            };

            _mockCollectionCalendarService
            .Setup(m => m.Get())
            .ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(_collectionCalendarPeriods));

            _vrfVendorId = Guid.NewGuid().ToString();
            var legalEntity = _fixture.Build <LegalEntityModel>()
                              .With(l => l.VrfVendorId, _vrfVendorId)
                              .With(l => l.SignedAgreementVersion, 5)
                              .Create();

            var accountModel = _fixture.Build <AccountModel>()
                               .With(a => a.LegalEntityModels, new List <LegalEntityModel>()
            {
                legalEntity
            })
                               .Create();

            var domainAccount = Domain.Accounts.Account.Create(accountModel);

            _account = new Account(accountModel.Id, legalEntity.AccountLegalEntityId);

            var pendingPayment1 = _fixture.Build <PendingPaymentModel>()
                                  .With(m => m.Account, _account)
                                  .With(m => m.DueDate, _payment1DueDate)
                                  .With(m => m.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create();

            var pendingPayment2 = _fixture.Build <PendingPaymentModel>()
                                  .With(m => m.Account, _account)
                                  .With(m => m.DueDate, _payment1DueDate.AddDays(2))
                                  .With(m => m.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create();

            var pendingPayments = new List <PendingPaymentModel>()
            {
                pendingPayment1, pendingPayment2
            };

            var model = _fixture.Build <ApprenticeshipIncentiveModel>()
                        .With(m => m.Account, _account)
                        .With(m => m.StartDate, _startDate)
                        .With(m => m.PendingPaymentModels, pendingPayments)
                        .With(m => m.PausePayments, false)
                        .With(m => m.MinimumAgreementVersion, new AgreementVersion(4))
                        .Create();

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

            _fixture.Register(() => incentive);

            _mockIncentiveDomainRespository
            .Setup(m => m.Find(incentive.Id))
            .ReturnsAsync(incentive);

            _mockAccountDomainRepository
            .Setup(m => m.Find(incentive.Account.Id))
            .ReturnsAsync(domainAccount);

            var submissionData = new SubmissionData();

            submissionData.SetSubmissionDate(DateTime.UtcNow);
            submissionData.SetLearningData(new LearningData(true));
            submissionData.LearningData.SetIsInLearning(true);

            _daysInLearning = new DaysInLearning(new Domain.ValueObjects.CollectionPeriod(1, (short)DateTime.Now.Year), 90);

            _learnerModel = _fixture.Build <LearnerModel>()
                            .With(m => m.ApprenticeshipId, incentive.Apprenticeship.Id)
                            .With(m => m.ApprenticeshipIncentiveId, incentive.Id)
                            .With(m => m.UniqueLearnerNumber, incentive.Apprenticeship.UniqueLearnerNumber)
                            .With(m => m.SubmissionData, submissionData)
                            .With(m => m.DaysInLearnings, new List <DaysInLearning>()
            {
                _daysInLearning
            })
                            .Create();

            _learner = new LearnerFactory().GetExisting(_learnerModel);

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

            _sut = new ValidatePendingPaymentCommandHandler(
                _mockIncentiveDomainRespository.Object,
                _mockAccountDomainRepository.Object,
                _mockCollectionCalendarService.Object,
                _mockLearnerDomainRepository.Object);
        }