Example #1
0
        private async Task <ApprenticeshipIncentiveModel> SaveAndGetApprenticeshipIncentive()
        {
            var incentive = _fixture.Build <ApprenticeshipIncentives.Models.ApprenticeshipIncentive>()
                            .With(p => p.Phase, Enums.Phase.NotSet)
                            .Create();

            foreach (var breakInLearning in incentive.BreakInLearnings)
            {
                breakInLearning.EndDate = breakInLearning.StartDate.AddDays(_fixture.Create <int>());
            }

            foreach (var pendingPayment in incentive.PendingPayments)
            {
                pendingPayment.PaymentYear  = Convert.ToInt16(_collectionCalendarPeriod.AcademicYear);
                pendingPayment.PeriodNumber = _collectionCalendarPeriod.PeriodNumber;
                foreach (var validationResult in pendingPayment.ValidationResults)
                {
                    validationResult.PaymentYear  = Convert.ToInt16(_collectionCalendarPeriod.AcademicYear);
                    validationResult.PeriodNumber = _collectionCalendarPeriod.PeriodNumber;
                }
            }

            await _dbContext.AddAsync(incentive);

            await _dbContext.SaveChangesAsync();

            return(await _sut.Get(incentive.Id));
        }
        public async Task Then_existing_learning_periods_are_updated_in_the_data_store()
        {
            // Arrange
            var existingLearner = _fixture.Create <ApprenticeshipIncentives.Models.Learner>();
            await _dbContext.AddAsync(existingLearner);

            await _dbContext.SaveChangesAsync();

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

            var lp       = existingLearner.LearningPeriods.First();
            var expected = new LearningPeriod(lp.StartDate, existingLearner.LearningPeriods.First().StartDate.AddMonths(10));

            testLearner.LearningPeriods.Add(expected);

            // Act
            await _sut.Update(testLearner);

            await _dbContext.SaveChangesAsync();

            // Assert
            var storedLearner = _dbContext.Learners.Single();

            storedLearner.LearningPeriods.Should().HaveCount(4);
            storedLearner.LearningPeriods.Any(x => x.StartDate == expected.StartDate && x.EndDate == expected.EndDate).Should().BeTrue();
        }
Example #3
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();
            }
        }
Example #4
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();
            }
        }
        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();
        }
        private async Task <ApprenticeshipIncentiveModel> SaveAndGetApprenticeshipIncentive()
        {
            var incentive = _fixture.Create <ApprenticeshipIncentives.Models.ApprenticeshipIncentive>();

            foreach (var pendingPayment in incentive.PendingPayments)
            {
                pendingPayment.PaymentYear  = Convert.ToInt16(_collectionPeriod.AcademicYear);
                pendingPayment.PeriodNumber = _collectionPeriod.PeriodNumber;
                foreach (var validationResult in pendingPayment.ValidationResults)
                {
                    validationResult.PaymentYear  = Convert.ToInt16(_collectionPeriod.AcademicYear);
                    validationResult.PeriodNumber = _collectionPeriod.PeriodNumber;
                }
            }

            await _dbContext.AddAsync(incentive);

            await _dbContext.SaveChangesAsync();

            return(await _sut.Get(incentive.Id));
        }
        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();
        }
        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());
        }
        public async Task Then_the_learner_is_retrieved_when_learning_found_is_null()
        {
            var testLearner = _fixture.Create <ApprenticeshipIncentives.Models.Learner>();

            testLearner.SubmissionFound = false;
            testLearner.SubmissionDate  = null;
            testLearner.LearningFound   = null;

            // Act
            await _dbContext.AddAsync(testLearner);

            await _dbContext.SaveChangesAsync();

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

            // Assert
            result.Should().NotBeNull();
        }
Example #10
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));
        }