Beispiel #1
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]);
        }
Beispiel #2
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();
            }
        }
Beispiel #3
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();
            }
        }
Beispiel #4
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());
        }
Beispiel #5
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());
        }
        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);
        }
Beispiel #7
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));
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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();
            }
        }
Beispiel #12
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();
        }
Beispiel #13
0
 public async Task Add(AccountModel account)
 {
     await _dbContext.AddRangeAsync(account.Map());
 }