예제 #1
0
        public async Task Then_the_apprenticeship_incentive_is_added_to_the_data_store()
        {
            // Arrange
            var testIncentive = _fixture
                                .Build <ApprenticeshipIncentiveModel>()
                                .Create();

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

            // Act
            await _sut.Add(testIncentive);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.ApprenticeshipIncentives.Count().Should().Be(1);

            var storedApprenticeshipIncentive = _dbContext.ApprenticeshipIncentives.Single();

            storedApprenticeshipIncentive.Id.Should().Be(testIncentive.Id);
            storedApprenticeshipIncentive.AccountId.Should().Be(testIncentive.Account.Id);
            storedApprenticeshipIncentive.ApprenticeshipId.Should().Be(testIncentive.Apprenticeship.Id);
            storedApprenticeshipIncentive.FirstName.Should().Be(testIncentive.Apprenticeship.FirstName);
            storedApprenticeshipIncentive.LastName.Should().Be(testIncentive.Apprenticeship.LastName);
            storedApprenticeshipIncentive.ULN.Should().Be(testIncentive.Apprenticeship.UniqueLearnerNumber);
            storedApprenticeshipIncentive.DateOfBirth.Should().Be(testIncentive.Apprenticeship.DateOfBirth);
            storedApprenticeshipIncentive.EmployerType.Should().Be(testIncentive.Apprenticeship.EmployerType);
            storedApprenticeshipIncentive.UKPRN.Should().Be(testIncentive.Apprenticeship.Provider.Ukprn);
            storedApprenticeshipIncentive.SubmittedDate.Should().Be(testIncentive.SubmittedDate);
            storedApprenticeshipIncentive.SubmittedByEmail.Should().Be(testIncentive.SubmittedByEmail);
            storedApprenticeshipIncentive.CourseName.Should().Be(testIncentive.Apprenticeship.CourseName);
            storedApprenticeshipIncentive.EmploymentStartDate.Should().Be(testIncentive.Apprenticeship.EmploymentStartDate);
            storedApprenticeshipIncentive.Phase.Should().Be(testIncentive.Phase.Identifier);
        }
        public async Task Then_the_incentive_application_is_added_to_the_data_store()
        {
            // Arrange
            var testApplication = _fixture
                                  .Build <IncentiveApplicationModel>()
                                  .Create();

            // Act
            await _sut.Add(testApplication);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.Applications.Count().Should().Be(1);

            var storedApplication = _dbContext.Applications.Single();

            storedApplication.Id.Should().Be(testApplication.Id);
            storedApplication.AccountId.Should().Be(testApplication.AccountId);
            storedApplication.AccountLegalEntityId.Should().Be(testApplication.AccountLegalEntityId);
            storedApplication.DateCreated.Should().Be(testApplication.DateCreated);
            storedApplication.DateSubmitted.Should().Be(testApplication.DateSubmitted);
            storedApplication.Status.Should().Be(testApplication.Status);
            storedApplication.SubmittedByEmail.Should().Be(testApplication.SubmittedByEmail);
            storedApplication.SubmittedByName.Should().Be(testApplication.SubmittedByName);
        }
        public async Task Then_the_account_is_added_if_it_does_not_exist()
        {
            // Arrange
            var testLegalEntity = _fixture.Create <LegalEntityModel>();
            var testAccount     = _fixture
                                  .Build <AccountModel>()
                                  .With(f => f.LegalEntityModels, new List <LegalEntityModel> {
                testLegalEntity
            })
                                  .Create();

            // Act
            await _sut.Update(testAccount);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.Accounts.Count().Should().Be(1);

            var storedAccount = _dbContext.Accounts.Single();

            storedAccount.Id.Should().Be(testAccount.Id);
            storedAccount.LegalEntityId.Should().Be(testLegalEntity.Id);
            storedAccount.AccountLegalEntityId.Should().Be(testLegalEntity.AccountLegalEntityId);
            storedAccount.LegalEntityName.Should().Be(testLegalEntity.Name);
            storedAccount.HasSignedIncentivesTerms.Should().Be(testLegalEntity.HasSignedAgreementTerms);
            storedAccount.SignedAgreementVersion.Should().Be(testLegalEntity.SignedAgreementVersion);
            storedAccount.HashedLegalEntityId.Should().Be(testLegalEntity.HashedLegalEntityId);
        }
        public async Task Then_the_apprenticeship_incentive_is_deleted_from_the_database()
        {
            // Arrange
            var incentive = _fixture.Create <ApprenticeshipIncentiveModel>();
            var cpData    = _fixture.Build <ApprenticeshipIncentives.Models.CollectionPeriod>()
                            .With(x => x.Active, true)
                            .With(x => x.PeriodNumber, 2)
                            .With(x => x.CalendarMonth, 9)
                            .With(x => x.CalendarYear, 2020)
                            .With(x => x.EIScheduledOpenDateUTC, new DateTime(2020, 9, 6))
                            .With(x => x.CensusDate, new DateTime(2020, 9, 30))
                            .With(x => x.AcademicYear, "2021")
                            .Create();

            var cp = new CollectionPeriod(cpData.PeriodNumber, cpData.CalendarMonth, cpData.CalendarYear,
                                          cpData.EIScheduledOpenDateUTC, cpData.CensusDate, Convert.ToInt16(cpData.AcademicYear), true);

            var validationResults = _fixture.Build <PendingPaymentValidationResultModel>()
                                    .With(x => x.CollectionPeriod, cp)
                                    .CreateMany(4).ToList();

            var pendingPayments = _fixture
                                  .Build <PendingPaymentModel>()
                                  .With(p => p.ApprenticeshipIncentiveId, incentive.Id)
                                  .CreateMany(2).ToList();

            pendingPayments[0].PendingPaymentValidationResultModels = new[] { validationResults[0], validationResults[1] };
            pendingPayments[1].PendingPaymentValidationResultModels = new[] { validationResults[2], validationResults[3] };

            var payments = _fixture.Build <PaymentModel>()
                           .With(x => x.ApprenticeshipIncentiveId, incentive.Id)
                           .CreateMany(2).ToList();

            incentive.PendingPaymentModels = pendingPayments;
            incentive.PaymentModels        = payments;

            await _dbContext.AddAsync(cpData);

            await _sut.Add(incentive);

            await _dbContext.SaveChangesAsync();

            // Act
            var storedIncentive = await _sut.Get(incentive.Id);

            await _sut.Delete(storedIncentive);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.ApprenticeshipIncentives.Should().BeEmpty();
            _dbContext.PendingPayments.Should().BeEmpty();
            _dbContext.PendingPaymentValidationResults.Should().BeEmpty();
            _dbContext.Payments.Should().BeEmpty();
        }
예제 #5
0
        public async Task Then_a_single_apprenticeship_incentives_is_returned_using_a_filter()
        {
            // Arrange
            var apprenticeshipIncentives = _fixture.CreateMany <ApprenticeshipIncentives.Models.ApprenticeshipIncentive>().ToList();

            // Act
            await _context.AddRangeAsync(apprenticeshipIncentives);

            await _context.SaveChangesAsync();

            // Assert
            var actual = await _sut.Get(x => x.Id == apprenticeshipIncentives[0].Id);

            actual.Should().BeEquivalentTo(apprenticeshipIncentives[0]);
        }
예제 #6
0
        public async Task Then_clawback_send_date_is_updated_for_correct_clawbacks()
        {
            // Arrange
            var accountLegalEntityId = _fixture.Create <long>();
            var account = new Models.Account {
                AccountLegalEntityId = accountLegalEntityId, VrfVendorId = _fixture.Create <string>()
            };
            var clawbacks = _fixture
                            .Build <ClawbackPayment>()
                            .Without(p => p.DateClawbackSent)
                            .CreateMany(5).ToList();

            foreach (var clawback in clawbacks)
            {
                clawback.AccountLegalEntityId = accountLegalEntityId;
            }

            await _dbContext.AddAsync(account);

            await _dbContext.AddRangeAsync(clawbacks);

            await _dbContext.SaveChangesAsync();

            var clawbacksIds = clawbacks.Take(4).Select(p => p.Id).ToList();
            var expected     = _fixture.Create <DateTime>();

            // Act
            await _sut.RecordClawbacksSent(clawbacksIds, accountLegalEntityId, expected);

            // Assert
            var matching = _dbContext.ClawbackPayments.Where(p => clawbacksIds.Contains(p.Id));

            matching.Count().Should().Be(4);

            foreach (var clawback in matching)
            {
                clawback.DateClawbackSent.Should().Be(expected);
            }

            var nonMatching = _dbContext.ClawbackPayments.Where(p => !clawbacksIds.Contains(p.Id));

            nonMatching.Count().Should().Be(1);

            foreach (var clawback in nonMatching)
            {
                clawback.DateClawbackSent.Should().BeNull();
            }
        }
예제 #7
0
        public async Task Then_payment_paid_date_is_updated_for_correct_payments()
        {
            // Arrange
            var accountLegalEntityId = _fixture.Create <long>();
            var account = new Models.Account {
                AccountLegalEntityId = accountLegalEntityId, VrfVendorId = _fixture.Create <string>()
            };
            var payments = _fixture
                           .Build <Payment>()
                           .Without(p => p.PaidDate)
                           .CreateMany(5).ToList();

            foreach (var payment in payments)
            {
                payment.AccountLegalEntityId = accountLegalEntityId;
            }

            await _dbContext.AddAsync(account);

            await _dbContext.AddRangeAsync(payments);

            await _dbContext.SaveChangesAsync();

            var paymentIds = payments.Take(4).Select(p => p.Id).ToList();
            var expected   = _fixture.Create <DateTime>();

            // Act
            await _sut.RecordPaymentsSent(paymentIds, accountLegalEntityId, expected);

            // Assert
            var matching = _dbContext.Payments.Where(p => paymentIds.Contains(p.Id));

            matching.Count().Should().Be(4);

            foreach (var payment in matching)
            {
                payment.PaidDate.Should().Be(expected);
            }

            var nonMatching = _dbContext.Payments.Where(p => !paymentIds.Contains(p.Id));

            nonMatching.Count().Should().Be(1);

            foreach (var payment in nonMatching)
            {
                payment.PaidDate.Should().BeNull();
            }
        }
예제 #8
0
        public async Task Then_the_incentive_application_is_returned()
        {
            // Arrange
            var apps = _fixture.CreateMany <Models.IncentiveApplication>(3).ToList();

            apps[0].Status = IncentiveApplicationStatus.Submitted;
            apps[0].Apprenticeships.First().EarningsCalculated = false;

            apps[1].Status = IncentiveApplicationStatus.ComplianceWithdrawn;
            apps[1].Apprenticeships.First().EarningsCalculated = false;

            apps[2].Status = IncentiveApplicationStatus.Submitted;
            foreach (var apprenticeship in apps[2].Apprenticeships)
            {
                apprenticeship.EarningsCalculated = true;
            }

            await _dbContext.AddRangeAsync(apps);

            await _dbContext.SaveChangesAsync();

            // Act
            var actual = await _sut.FindApplicationsWithoutEarningsCalculated();

            // Assert
            actual.Should().BeEquivalentTo(new[] { apps[0] }, opt => opt.ExcludingMissingMembers());
        }
예제 #9
0
        public async Task Then_the_payment_model_is_added_to_the_data_store()
        {
            // Arrange
            var testPayment = _fixture
                              .Build <PaymentModel>()
                              .Create();

            // Act
            await _sut.Archive(testPayment);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.ArchivedPayments.Count().Should().Be(1);

            var storedPayment = _dbContext.ArchivedPayments.Single();

            storedPayment.PaymentId.Should().Be(testPayment.Id);
            storedPayment.ApprenticeshipIncentiveId.Should().Be(testPayment.ApprenticeshipIncentiveId);
            storedPayment.PendingPaymentId.Should().Be(testPayment.PendingPaymentId);
            storedPayment.AccountId.Should().Be(testPayment.Account.Id);
            storedPayment.AccountLegalEntityId.Should().Be(testPayment.Account.AccountLegalEntityId);
            storedPayment.Amount.Should().Be(testPayment.Amount);
            storedPayment.CalculatedDate.Should().Be(testPayment.CalculatedDate);
            storedPayment.PaidDate.Should().Be(testPayment.PaidDate);
            storedPayment.SubnominalCode.Should().Be(testPayment.SubnominalCode);
            storedPayment.PaymentPeriod.Should().Be(testPayment.PaymentPeriod);
            storedPayment.PaymentYear.Should().Be(testPayment.PaymentYear);
            storedPayment.ArchiveDateUTC.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMinutes(1));
        }
예제 #10
0
        public async Task Then_the_account_is_added_to_the_data_store()
        {
            // Arrange
            var testLegalEntity = _fixture.Create <LegalEntityModel>();
            var testAccount     = _fixture
                                  .Build <AccountModel>()
                                  .With(f => f.LegalEntityModels, new List <LegalEntityModel> {
                testLegalEntity
            })
                                  .Create();

            // Act
            await _sut.Add(testAccount);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.Accounts.Count().Should().Be(1);

            var storedAccount = _dbContext.Accounts.Single();

            storedAccount.Id.Should().Be(testAccount.Id);
            storedAccount.HashedLegalEntityId.Should().Be(testLegalEntity.HashedLegalEntityId);
            storedAccount.LegalEntityId.Should().Be(testLegalEntity.Id);
            storedAccount.AccountLegalEntityId.Should().Be(testLegalEntity.AccountLegalEntityId);
            storedAccount.LegalEntityName.Should().Be(testLegalEntity.Name);
            storedAccount.VrfCaseId.Should().Be(testLegalEntity.VrfCaseId);
            storedAccount.VrfCaseStatus.Should().Be(testLegalEntity.VrfCaseStatus);
            storedAccount.VrfVendorId.Should().Be(testLegalEntity.VrfVendorId);
            storedAccount.VrfCaseStatusLastUpdatedDateTime.Should().Be(testLegalEntity.VrfCaseStatusLastUpdatedDateTime);
        }
예제 #11
0
        public async Task Then_the_incentive_application_is_returned()
        {
            // Arrange
            var apps = _fixture.CreateMany <Models.IncentiveApplication>(3).ToList();

            apps[0].AccountLegalEntityId        = 123;
            apps[0].Apprenticeships.First().ULN = 12345678;

            apps[1].AccountLegalEntityId        = 456;
            apps[1].Apprenticeships.First().ULN = 12345678;

            apps[2].AccountLegalEntityId = 123;
            foreach (var apprenticeship in apps[2].Apprenticeships)
            {
                apprenticeship.ULN = 9877654;
            }

            await _dbContext.AddRangeAsync(apps);

            await _dbContext.SaveChangesAsync();

            // Act
            var actual = await _sut.FindApplicationsByAccountLegalEntityAndUln(123, 12345678);

            // Assert
            actual.Should().BeEquivalentTo(new[] { apps[0] }, opt => opt.ExcludingMissingMembers());
        }
예제 #12
0
        public async Task Then_an_eligible_apprenticeship_returns_expected_result_from_the_query(bool withdrawnByCompliance, bool withdrawnByEmployer, bool expected)
        {
            // Arrange
            var uln         = _fixture.Create <long>();
            var application = _fixture.Build <Models.IncentiveApplication>()
                              .With(a => a.Status, IncentiveApplicationStatus.Submitted).Create();
            var apprenticeship = _fixture.Build <Models.IncentiveApplicationApprenticeship>()
                                 .With(a => a.IncentiveApplicationId, application.Id)
                                 .With(a => a.ULN, uln)
                                 .With(a => a.WithdrawnByCompliance, withdrawnByCompliance)
                                 .With(a => a.WithdrawnByEmployer, withdrawnByEmployer)
                                 .Create();

            await _context.Applications.AddAsync(application);

            await _context.ApplicationApprenticeships.AddAsync(apprenticeship);

            await _context.SaveChangesAsync();

            // Act
            var result = await _sut.UlnAlreadyOnSubmittedIncentiveApplication(uln);

            //Assert
            result.Should().Be(expected);
        }
        public async Task Then_the_incentive_application_is_updated_with_new_values()
        {
            // Act
            var storedApplication = await _sut.Get(_testApplication.Id);

            storedApplication.DateSubmitted    = _fixture.Create <DateTime>();
            storedApplication.Status           = Enums.IncentiveApplicationStatus.Submitted;
            storedApplication.SubmittedByEmail = _fixture.Create <string>();

            await _sut.Update(storedApplication);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.Applications.Count().Should().Be(1);
            _dbContext.Applications.Count(x => x.DateSubmitted == storedApplication.DateSubmitted)
            .Should().Be(1);
        }
        public async Task Then_the_incentive_applications_for_the_account_legal_entity_are_returned()
        {
            // Arrange
            var apps = _fixture.CreateMany <Models.IncentiveApplication>(3).ToList();

            apps[0].AccountLegalEntityId = 123;
            apps[1].AccountLegalEntityId = 456;
            apps[2].AccountLegalEntityId = 123;

            await _dbContext.AddRangeAsync(apps);

            await _dbContext.SaveChangesAsync();

            // Act
            var result = await _sut.FindApplicationsByAccountLegalEntity(123);

            // Assert
            result.Should().NotBeNull();
            result.Count().Should().Be(2);
        }
예제 #15
0
        public async Task Then_the_max_vrf_update_date_time_is_returned_from_database()
        {
            // Arrange
            var testAccounts = _fixture.CreateMany <Models.Account>(100).ToList();

            testAccounts[25].VrfCaseStatusLastUpdatedDateTime = null;
            testAccounts[77].VrfCaseStatusLastUpdatedDateTime = null;

            await _dbContext.AddRangeAsync(testAccounts);

            await _dbContext.SaveChangesAsync();

            // ReSharper disable once PossibleInvalidOperationException
            var expected = testAccounts.OrderByDescending(x => x.VrfCaseStatusLastUpdatedDateTime).First()
                           .VrfCaseStatusLastUpdatedDateTime.Value;

            // Act
            var result = await _sut.GetLatestVendorRegistrationCaseUpdateDateTime();

            // Assert
            result.Should().Be(expected);
        }
        public async Task Then_apprenticeship_incentive_is_returned_if_exists()
        {
            // Arrange
            var expected = _fixture.Build <ApprenticeshipIncentives.Models.ApprenticeshipIncentive>().Without(x => x.BreakInLearnings).Create();
            await _dbContext.AddAsync(expected);

            await _dbContext.SaveChangesAsync();

            // Act
            var incentive = await _sut.FindByApprenticeshipId(expected.IncentiveApplicationApprenticeshipId);

            // Assert
            incentive.Should().NotBeNull();
        }
        private async Task AddApprenticeshipIncentiveModel(long accountLegalEntityId, long uln)
        {
            var account        = new Domain.ApprenticeshipIncentives.ValueTypes.Account(_fixture.Create <long>(), accountLegalEntityId);
            var apprenticeship = new Apprenticeship(_fixture.Create <long>(), _fixture.Create <string>(),
                                                    _fixture.Create <string>(), _fixture.Create <DateTime>(), uln,
                                                    _fixture.Create <ApprenticeshipEmployerType>(), _fixture.Create <string>());

            var incentive = _fixture.Build <ApprenticeshipIncentiveModel>().With(x => x.Apprenticeship, apprenticeship)
                            .With(x => x.Account, account).Create();

            await _sut.Add(incentive);

            await _dbContext.SaveChangesAsync();
        }
        public async Task Then_the_pending_payment_model_and_its_validation_results_are_added_to_the_data_store()
        {
            // Arrange
            var testPendingPaymentValidationResult = _fixture.Create <PendingPaymentValidationResultModel>();

            var testPendingPayment = _fixture
                                     .Build <PendingPaymentModel>()
                                     .With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()
            {
                testPendingPaymentValidationResult
            })
                                     .Create();

            // Act
            await _sut.Archive(testPendingPayment);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.ArchivedPendingPayments.Count().Should().Be(1);
            _dbContext.ArchivedPendingPaymentValidationResults.Count().Should().Be(1);

            var storedPendingPayment = _dbContext.ArchivedPendingPayments.Single();

            storedPendingPayment.PendingPaymentId.Should().Be(testPendingPayment.Id);
            storedPendingPayment.AccountId.Should().Be(testPendingPayment.Account.Id);
            storedPendingPayment.AccountLegalEntityId.Should().Be(testPendingPayment.Account.AccountLegalEntityId);
            storedPendingPayment.ApprenticeshipIncentiveId.Should().Be(testPendingPayment.ApprenticeshipIncentiveId);
            storedPendingPayment.Amount.Should().Be(testPendingPayment.Amount);
            storedPendingPayment.DueDate.Should().Be(testPendingPayment.DueDate);
            storedPendingPayment.CalculatedDate.Should().Be(testPendingPayment.CalculatedDate);
            storedPendingPayment.PaymentMadeDate.Should().Be(testPendingPayment.PaymentMadeDate);
            storedPendingPayment.PeriodNumber.Should().Be(testPendingPayment.PeriodNumber);
            storedPendingPayment.PaymentYear.Should().Be(testPendingPayment.PaymentYear);
            storedPendingPayment.EarningType.Should().Be(testPendingPayment.EarningType);
            storedPendingPayment.ClawedBack.Should().Be(testPendingPayment.ClawedBack);
            storedPendingPayment.ArchiveDateUTC.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMinutes(1));

            var storedValidationResult = _dbContext.ArchivedPendingPaymentValidationResults.Single();

            storedValidationResult.PendingPaymentId.Should().Be(testPendingPayment.Id);
            storedValidationResult.PendingPaymentValidationResultId.Should().Be(testPendingPaymentValidationResult.Id);
            storedValidationResult.PaymentYear.Should().Be(testPendingPaymentValidationResult.CollectionPeriod.AcademicYear);
            storedValidationResult.PeriodNumber.Should().Be(testPendingPaymentValidationResult.CollectionPeriod.PeriodNumber);
            storedValidationResult.Result.Should().Be(testPendingPaymentValidationResult.Result);
            storedValidationResult.Step.Should().Be(testPendingPaymentValidationResult.Step);
            storedValidationResult.CreatedDateUtc.Should().Be(testPendingPaymentValidationResult.CreatedDateUtc);
            storedValidationResult.ArchiveDateUTC.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMinutes(1));
        }
        public async Task Then_the_learner_is_retrieved()
        {
            var submissionData = _fixture.Create <SubmissionData>();

            submissionData.SetLearningData(new LearningData(true));
            submissionData.SetSubmissionDate(_fixture.Create <DateTime>());
            submissionData.LearningData.SetHasDataLock(true);
            submissionData.SetRawJson(_fixture.Create <string>());

            var testLearner =
                _fixture.Build <LearnerModel>()
                .With(l => l.SubmissionData, submissionData)
                .Create();

            // Act
            await _sut.Add(testLearner);

            await _dbContext.SaveChangesAsync();

            // Act
            var result = await _sut.GetByApprenticeshipIncentiveId(testLearner.ApprenticeshipIncentiveId);

            // Assert
            result.Id.Should().Be(testLearner.Id);
            result.ApprenticeshipIncentiveId.Should().Be(testLearner.ApprenticeshipIncentiveId);
            result.ApprenticeshipId.Should().Be(testLearner.ApprenticeshipId);
            result.Ukprn.Should().Be(testLearner.Ukprn);
            result.UniqueLearnerNumber.Should().Be(testLearner.UniqueLearnerNumber);
            result.SubmissionData.Should().NotBeNull();
            result.SubmissionData.SubmissionDate.Should().Be(testLearner.SubmissionData.SubmissionDate);
            result.SubmissionData.LearningData.IsInlearning.Should().Be(testLearner.SubmissionData.LearningData.IsInlearning);
            result.SubmissionData.LearningData.HasDataLock.Should().BeTrue();
            result.SubmissionData.LearningData.StartDate.Should().BeNull();
            result.SubmissionData.LearningData.IsInlearning.Should().BeNull();
            result.SubmissionData.RawJson.Should().Be(testLearner.SubmissionData.RawJson);
        }
        public async Task Then_the_incentive_application_is_returned()
        {
            // Arrange
            var expected = _fixture.Create <Models.IncentiveApplication>();
            await _dbContext.AddAsync(expected);

            await _dbContext.SaveChangesAsync();

            // Act
            var actual = await _sut.Get(expected.Id);

            // Assert
            actual.Should().BeEquivalentTo(expected, opt => opt
                                           .ExcludingMissingMembers());
        }
예제 #21
0
        public async Task Then_when_the_account_has_multiple_legal_entities_all_legal_entities_are_returned()
        {
            var accountId    = _fixture.Create <long>();
            var testAccounts = _fixture.Build <Models.Account>().With(x => x.Id, accountId).CreateMany(5);

            await _dbContext.AddRangeAsync(testAccounts);

            await _dbContext.SaveChangesAsync();

            // Act
            var accounts = await _sut.GetByHashedLegalEntityId(testAccounts.First().HashedLegalEntityId);

            // Assert
            accounts.Single().LegalEntityModels.Count.Should().Be(5);
        }
예제 #22
0
        public async Task Then_has_signed_agreement_version_is_set(int?signedAgreementVersion, bool expected)
        {
            // Arrange
            var account = _fixture.Create <Models.Account>();

            account.SignedAgreementVersion = signedAgreementVersion;

            await _context.Accounts.AddAsync(account);

            await _context.SaveChangesAsync();

            // Act
            var actual = (await _sut.GetList(x => x.AccountId == account.Id)).Single();

            // Assert
            actual.IsAgreementSigned.Should().Be(expected);
        }
        public async Task Arrange()
        {
            _fixture = new Fixture();

            var options = new DbContextOptionsBuilder <EmployerIncentivesDbContext>()
                          .UseInMemoryDatabase("EmployerIncentivesDbContext" + Guid.NewGuid()).Options;

            _dbContext = new EmployerIncentivesDbContext(options);

            _testApplication = _fixture
                               .Build <IncentiveApplicationModel>()
                               .Create();

            _sut = new IncentiveApplication.IncentiveApplicationDataRepository(new Lazy <EmployerIncentivesDbContext>(_dbContext));
            await _sut.Add(_testApplication);

            await _dbContext.SaveChangesAsync();
        }
        public async Task Then_an_existing_learner_is_updated_in_the_data_store()
        {
            // Arrange
            var existingLearner =
                _fixture.Build <ApprenticeshipIncentives.Models.Learner>()
                .Create();

            _dbContext.Learners.Add(existingLearner);
            await _dbContext.SaveChangesAsync();

            var submissionData = _fixture.Create <SubmissionData>();

            submissionData.SetSubmissionDate(_fixture.Create <DateTime>());
            submissionData.SetLearningData(new LearningData(true));
            submissionData.LearningData.SetHasDataLock(true);
            submissionData.SetRawJson(_fixture.Create <string>());
            submissionData.LearningData.SetStartDate(_fixture.Create <DateTime>());
            submissionData.LearningData.SetIsInLearning(true);
            submissionData.LearningData.SetIsStopped(new LearningStoppedStatus(false, _fixture.Create <DateTime>()));

            var testLearner =
                _fixture.Build <LearnerModel>()
                .With(l => l.Id, existingLearner.Id)
                .With(l => l.SubmissionData, submissionData)
                .Create();

            // Act
            await _sut.Update(testLearner);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.Learners.Count().Should().Be(1);
            var storedLearner = _dbContext.Learners.Single();

            storedLearner.Id.Should().Be(testLearner.Id);
            storedLearner.ApprenticeshipIncentiveId.Should().Be(testLearner.ApprenticeshipIncentiveId);
            storedLearner.ApprenticeshipId.Should().Be(testLearner.ApprenticeshipId);
            storedLearner.Ukprn.Should().Be(testLearner.Ukprn);
            storedLearner.ULN.Should().Be(testLearner.UniqueLearnerNumber);
            storedLearner.SubmissionFound.Should().Be(true);
            storedLearner.SubmissionDate.Should().Be(testLearner.SubmissionData.SubmissionDate);
            storedLearner.LearningFound.Should().Be(testLearner.SubmissionData.LearningData.LearningFound);
            storedLearner.StartDate.Should().Be(testLearner.SubmissionData.LearningData.StartDate);
            storedLearner.HasDataLock.Should().BeTrue();
            storedLearner.InLearning.Should().BeTrue();
            storedLearner.RawJSON.Should().Be(testLearner.SubmissionData.RawJson);
            storedLearner.LearningResumedDate.Should().Be(testLearner.SubmissionData.LearningData.StoppedStatus.DateResumed);
            storedLearner.LearningStoppedDate.Should().BeNull();
            storedLearner.SuccessfulLearnerMatch.Should().Be(testLearner.SuccessfulLearnerMatch);
        }
예제 #25
0
        public async Task Then_clawback_send_date_is_updated_for_correct_clawbacks()
        {
            // Arrange
            var accountLegalEntityId = _fixture.Create <long>();
            var clawbacks            = _fixture
                                       .Build <ClawbackPayment>()
                                       .Without(p => p.DateClawbackSent)
                                       .With(p => p.AccountLegalEntityId, accountLegalEntityId)
                                       .CreateMany(5).ToList();

            clawbacks.First().AccountLegalEntityId = accountLegalEntityId + 1;

            await _dbContext.AddRangeAsync(clawbacks);

            await _dbContext.SaveChangesAsync();

            var clawbacksIds = clawbacks.Take(4).Select(p => p.Id).ToList();
            var expected     = _fixture.Create <DateTime>();

            // Act
            await _sut.UpdateClawbackDateForClawbackIds(clawbacksIds, accountLegalEntityId, expected);

            // Assert
            var matching = _dbContext.ClawbackPayments.Where(p =>
                                                             clawbacksIds.Contains(p.Id) && p.AccountLegalEntityId == accountLegalEntityId);

            matching.Count().Should().Be(3);
            foreach (var clawback in matching)
            {
                clawback.DateClawbackSent.Should().Be(expected);
            }

            var nonMatching = _dbContext.ClawbackPayments.Where(p =>
                                                                !clawbacksIds.Contains(p.Id) || p.AccountLegalEntityId != accountLegalEntityId);

            nonMatching.Count().Should().Be(2);
            foreach (var clawback in nonMatching)
            {
                clawback.DateClawbackSent.Should().BeNull();
            }
        }
        public async Task Then_payment_paid_date_is_updated_for_correct_payments()
        {
            // Arrange
            var accountLegalEntityId = _fixture.Create <long>();
            var payments             = _fixture
                                       .Build <Payment>()
                                       .Without(p => p.PaidDate)
                                       .With(p => p.AccountLegalEntityId, accountLegalEntityId)
                                       .CreateMany(5).ToList();

            payments.First().AccountLegalEntityId = accountLegalEntityId + 1;

            await _dbContext.AddRangeAsync(payments);

            await _dbContext.SaveChangesAsync();

            var paymentIds = payments.Take(4).Select(p => p.Id).ToList();
            var expected   = _fixture.Create <DateTime>();

            // Act
            await _sut.UpdatePaidDateForPaymentIds(paymentIds, accountLegalEntityId, expected);

            // Assert
            var matching = _dbContext.Payments.Where(p =>
                                                     paymentIds.Contains(p.Id) && p.AccountLegalEntityId == accountLegalEntityId);

            matching.Count().Should().Be(3);
            foreach (var payment in matching)
            {
                payment.PaidDate.Should().Be(expected);
            }

            var nonMatching = _dbContext.Payments.Where(p =>
                                                        !paymentIds.Contains(p.Id) || p.AccountLegalEntityId != accountLegalEntityId);

            nonMatching.Count().Should().Be(2);
            foreach (var payment in nonMatching)
            {
                payment.PaidDate.Should().BeNull();
            }
        }
예제 #27
0
        public async Task Then_the_ChangeOfCircumstance_is_added_to_the_data_store()
        {
            // Arrange
            var testChange = _fixture.Create <ChangeOfCircumstance>();

            // Act
            await _sut.Save(testChange);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.ChangeOfCircumstances.Count().Should().Be(1);

            var storedChange = _dbContext.ChangeOfCircumstances.Single();

            storedChange.Id.Should().Be(testChange.Id);
            storedChange.ApprenticeshipIncentiveId.Should().Be(testChange.ApprenticeshipIncentiveId);
            storedChange.NewValue.Should().Be(testChange.NewValue);
            storedChange.PreviousValue.Should().Be(testChange.PreviousValue);
            storedChange.ChangedDate.Should().Be(testChange.ChangedDate);
        }
        public async Task Then_the_learner_is_added_to_the_data_store()
        {
            // Arrange
            var submissionData = _fixture.Create <SubmissionData>();

            submissionData.SetSubmissionDate(_fixture.Create <DateTime>());
            submissionData.SetLearningData(new LearningData(true));
            submissionData.LearningData.SetHasDataLock(true);
            submissionData.SetRawJson(_fixture.Create <string>());
            submissionData.LearningData.SetStartDate(_fixture.Create <DateTime>());
            submissionData.LearningData.SetIsInLearning(true);

            var testLearner =
                _fixture.Build <LearnerModel>()
                .With(l => l.SubmissionData, submissionData)
                .Create();

            // Act
            await _sut.Add(testLearner);

            await _dbContext.SaveChangesAsync();

            // Assert
            _dbContext.Learners.Count().Should().Be(1);

            var storedLearner = _dbContext.Learners.Single();

            storedLearner.Id.Should().Be(testLearner.Id);
            storedLearner.ApprenticeshipIncentiveId.Should().Be(testLearner.ApprenticeshipIncentiveId);
            storedLearner.ApprenticeshipId.Should().Be(testLearner.ApprenticeshipId);
            storedLearner.Ukprn.Should().Be(testLearner.Ukprn);
            storedLearner.ULN.Should().Be(testLearner.UniqueLearnerNumber);
            storedLearner.SubmissionFound.Should().BeTrue();
            storedLearner.SubmissionDate.Should().Be(testLearner.SubmissionData.SubmissionDate);
            storedLearner.LearningFound.Should().Be(testLearner.SubmissionData.LearningData.LearningFound);
            storedLearner.HasDataLock.Should().BeTrue();
            storedLearner.StartDate.Should().Be(testLearner.SubmissionData.LearningData.StartDate);
            storedLearner.InLearning.Should().BeTrue();
            storedLearner.RawJSON.Should().Be(testLearner.SubmissionData.RawJson);
        }
예제 #29
0
        public async Task Then_expected_data_returned()
        {
            // Arrange
            var incentives = _fixture.Build <ApprenticeshipIncentives.Models.ApprenticeshipIncentive>()
                             .Without(x => x.PendingPayments)
                             .Without(x => x.BreakInLearnings)
                             .CreateMany(3).ToList();

            var expected = (IncentiveWithPendingPayments : incentives[0].Id,
                            IncentivesWithoutPendingPyaments : new[] { incentives[1], incentives[2] });

            var cpData = _fixture.Build <CollectionCalendarPeriod>()
                         .With(x => x.Active, true)
                         .With(x => x.PeriodNumber, 2)
                         .With(x => x.CalendarMonth, 9)
                         .With(x => x.CalendarYear, 2020)
                         .With(x => x.EIScheduledOpenDateUTC, new DateTime(2020, 9, 6))
                         .With(x => x.CensusDate, new DateTime(2020, 9, 30))
                         .With(x => x.AcademicYear, "2021")
                         .Create();

            var pendingPayments = _fixture
                                  .Build <PendingPayment>()
                                  .With(p => p.ApprenticeshipIncentiveId, expected.IncentiveWithPendingPayments)
                                  .CreateMany(2).ToList();

            await _dbContext.AddAsync(cpData);

            await _dbContext.AddRangeAsync(pendingPayments);

            await _dbContext.AddRangeAsync(incentives);

            await _dbContext.SaveChangesAsync();

            // Act
            var result = await _sut.FindApprenticeshipIncentivesWithoutPendingPayments();

            // Assert
            result.Select(x => x.Id).Should().BeEquivalentTo(expected.IncentivesWithoutPendingPyaments.Select(x => x.Id));
        }
예제 #30
0
        private async Task AddCollectionPeriods()
        {
            _collectionPeriod = new[]
            {
                _fixture.Build <CollectionCalendarPeriod>()
                .With(x => x.Active, false)
                .With(x => x.PeriodEndInProgress, false)
                .With(x => x.PeriodNumber, 1)
                .With(x => x.CalendarMonth, 8)
                .With(x => x.CalendarYear, 2020)
                .With(x => x.EIScheduledOpenDateUTC, new DateTime(2020, 8, 6))
                .With(x => x.CensusDate, new DateTime(2020, 8, 30))
                .With(x => x.AcademicYear, "2021")
                .Create(),
                _fixture.Build <CollectionCalendarPeriod>()
                .With(x => x.Active, true)
                .With(x => x.PeriodEndInProgress, true)
                .With(x => x.PeriodNumber, 2)
                .With(x => x.CalendarMonth, 9)
                .With(x => x.CalendarYear, 2020)
                .With(x => x.EIScheduledOpenDateUTC, new DateTime(2020, 9, 6))
                .With(x => x.CensusDate, new DateTime(2020, 9, 30))
                .With(x => x.AcademicYear, "2021")
                .Create(),
                _fixture.Build <CollectionCalendarPeriod>()
                .With(x => x.Active, false)
                .With(x => x.PeriodEndInProgress, false)
                .With(x => x.PeriodNumber, 3)
                .With(x => x.CalendarMonth, 10)
                .With(x => x.CalendarYear, 2020)
                .With(x => x.EIScheduledOpenDateUTC, new DateTime(2020, 10, 6))
                .With(x => x.CensusDate, new DateTime(2020, 10, 30))
                .With(x => x.AcademicYear, "2021")
                .Create()
            };
            await _dbContext.AddRangeAsync(_collectionPeriod);

            await _dbContext.SaveChangesAsync();
        }