Exemple #1
0
        public async Task Then_first_id_is_returned_when_has_submitted_applications()
        {
            // Arrange
            var accountId            = _fixture.Create <long>();
            var accountLegalEntityId = _fixture.Create <long>();
            var account = _fixture.Build <Models.Account>().With(x => x.Id, accountId).With(x => x.AccountLegalEntityId, accountLegalEntityId).Create();

            var allApplications = _fixture.CreateMany <Models.IncentiveApplication>(5).ToArray();

            foreach (var application in allApplications)
            {
                application.AccountId            = accountId;
                application.AccountLegalEntityId = accountLegalEntityId;
                application.Status = IncentiveApplicationStatus.Submitted;
            }

            _context.Accounts.Add(account);
            _context.Applications.AddRange(allApplications);

            var expectedId = allApplications.OrderBy(x => x.DateSubmitted).First().Id;

            _context.SaveChanges();

            // Act
            var result = await _sut.GetFirstSubmittedApplicationId(accountLegalEntityId);

            // Assert
            result.Should().Be(expectedId);
        }
Exemple #2
0
        public async Task Then_data_is_fetched_from_database_for_an_account_with_a_single_legal_entity(string vrfCaseStatus)
        {
            // Arrange
            var        allAccounts = _fixture.CreateMany <Models.Account>(10).ToArray();
            const long accountId   = -1;

            allAccounts[0].Id            = accountId;
            allAccounts[0].VrfCaseStatus = vrfCaseStatus;

            _context.Accounts.AddRange(allAccounts);

            var allApplications = _fixture.CreateMany <Models.IncentiveApplication>(10).ToArray();

            for (var i = 0; i < 10; i++)
            {
                allApplications[i].AccountId            = allAccounts[i].Id;
                allApplications[i].AccountLegalEntityId = allAccounts[i].AccountLegalEntityId;
            }
            _context.Applications.AddRange(allApplications);

            _context.SaveChanges();

            // Act
            var actual = (await _sut.GetByVrfCaseStatus(vrfCaseStatus)).ToArray();

            //Assert
            actual.All(x => x.AccountId == accountId).Should().BeTrue();
            actual.Length.Should().Be(1);
            actual[0].LegalEntities.Count(x => x.AccountLegalEntityId == allAccounts[0].AccountLegalEntityId).Should().Be(1);
        }
        private void SetupPendingPayments()
        {
            _pendingPayment1 = _fixture.Build <PendingPayment>().Create();


            var pendingPayments = new List <PendingPayment>
            {
                _pendingPayment1
            };

            _context.PendingPayments.AddRange(pendingPayments);
            _context.SaveChanges();
        }
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var pendingPayment = _fixture.Create <PendingPayment>();

            _context.PendingPayments.Add(pendingPayment);
            _context.SaveChanges();

            // Act
            var actual = await _sut.Get(x => x.Id == pendingPayment.Id);

            //Assert
            actual.Should().BeEquivalentTo(pendingPayment, opts => opts.ExcludingMissingMembers());
        }
Exemple #5
0
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var accounts = _fixture.CreateMany <Models.Account>(3);

            _context.Accounts.AddRange(accounts);
            _context.SaveChanges();

            // Act
            var actual = await _sut.Get(x => x.LegalEntityId == accounts.First().LegalEntityId);

            //Assert
            actual.Should().BeEquivalentTo(accounts.First(), opts => opts.ExcludingMissingMembers());
        }
        public async Task Then_data_is_fetched_from_database()
        {
            var allApprenticeships = _fixture.Build <Models.IncentiveApplicationApprenticeship>().CreateMany(10).ToArray();
            var apprenticeshipId   = Guid.NewGuid();

            allApprenticeships[1].Id = apprenticeshipId;

            _context.ApplicationApprenticeships.AddRange(allApprenticeships);
            _context.SaveChanges();

            // Act
            var actual = await _sut.Get(x => x.Id == apprenticeshipId);

            //Assert
            actual.Should().BeEquivalentTo(allApprenticeships[1], opts => opts.ExcludingMissingMembers());
        }
        public async Task Then_the_account_is_updated_if_it_already_exists()
        {
            // Arrange
            var testAccount = _fixture.Create <Models.Account>();

            _dbContext.Add(_fixture.Create <Models.Account>());
            _dbContext.Add(testAccount);
            _dbContext.Add(_fixture.Create <Models.Account>());
            _dbContext.SaveChanges();
            var newName           = testAccount.LegalEntityName + "changed";
            var newHasSignedTerms = !testAccount.HasSignedIncentivesTerms;
            var newSignedVersion  = testAccount.SignedAgreementVersion + 1;

            var legalEntities = new List <LegalEntityModel>
            {
                new LegalEntityModel
                {
                    Id = testAccount.LegalEntityId,
                    AccountLegalEntityId = testAccount.AccountLegalEntityId,
                    Name = newName,
                    HasSignedAgreementTerms = newHasSignedTerms,
                    SignedAgreementVersion  = newSignedVersion
                }
            };

            var accountModel = new AccountModel {
                Id = testAccount.Id, LegalEntityModels = legalEntities
            };

            // Act
            await _sut.Update(accountModel);

            await _dbContext.SaveChangesAsync();

            // Assert
            var addedAccount = _dbContext.Accounts.Single(a => a.Id == testAccount.Id && a.AccountLegalEntityId == testAccount.AccountLegalEntityId);

            addedAccount.LegalEntityId.Should().Be(testAccount.LegalEntityId);
            addedAccount.LegalEntityName.Should().Be(newName);
            addedAccount.HasSignedIncentivesTerms.Should().Be(newHasSignedTerms);
            addedAccount.SignedAgreementVersion.Should().Be(newSignedVersion);
            addedAccount.VrfCaseId.Should().Be(testAccount.VrfCaseId);
            addedAccount.VrfCaseStatus.Should().Be(testAccount.VrfCaseStatus);
            addedAccount.VrfVendorId.Should().Be(testAccount.VrfVendorId);
            addedAccount.VrfCaseStatusLastUpdatedDateTime.Should().Be(testAccount.VrfCaseStatusLastUpdatedDateTime);
            addedAccount.HashedLegalEntityId.Should().Be(testAccount.HashedLegalEntityId);
        }
Exemple #8
0
        public async Task Then_the_expected_account_is_returned_if_it_exists()
        {
            // Arrange
            var testAccount = _fixture.Create <Models.Account>();

            _dbContext.Add(testAccount);
            _dbContext.SaveChanges();

            // Act
            var account = await _sut.Find(testAccount.Id);

            // Assert
            account.Should().NotBeNull();
            account.Id.Should().Be(testAccount.Id);
            var legalEntity = account.LegalEntityModels.Single();

            legalEntity.Id.Should().Be(testAccount.LegalEntityId);
            legalEntity.Name.Should().Be(testAccount.LegalEntityName);
            legalEntity.AccountLegalEntityId.Should().Be(testAccount.AccountLegalEntityId);
            legalEntity.HashedLegalEntityId.Should().Be(testAccount.HashedLegalEntityId);
            legalEntity.VrfCaseStatusLastUpdatedDateTime.Should().Be(testAccount.VrfCaseStatusLastUpdatedDateTime);
            legalEntity.VrfCaseStatus.Should().Be(testAccount.VrfCaseStatus);
            legalEntity.VrfVendorId.Should().Be(testAccount.VrfVendorId);
            legalEntity.VrfCaseId.Should().Be(testAccount.VrfCaseId);
        }
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var        account         = _fixture.Create <Models.Account>();
            var        allApplications = _fixture.Build <Models.IncentiveApplication>().With(x => x.AccountLegalEntityId, account.AccountLegalEntityId).CreateMany <Models.IncentiveApplication>(10).ToArray();
            const long accountId       = -1;

            allApplications[0].AccountId = accountId;
            allApplications[3].AccountId = accountId;

            _context.Accounts.Add(account);
            _context.Applications.AddRange(allApplications);
            _context.SaveChanges();

            // Act
            var actual = (await _sut.GetList(x => x.AccountId == accountId)).ToArray();

            //Assert
            actual.All(x => x.AccountId == accountId).Should().BeTrue();
            actual.Should().BeEquivalentTo(new[] { allApplications[0], allApplications[3] }, opts => opts.ExcludingMissingMembers());
        }
        public async Task Then_all_apprenticeship_incentives_are_returned()
        {
            var apprenticeshipIncentives =
                _fixture.CreateMany <ApprenticeshipIncentives.Models.ApprenticeshipIncentive>().ToList();

            foreach (var incentive in apprenticeshipIncentives)
            {
                incentive.Status = IncentiveStatus.Active;
            }

            _context.ApprenticeshipIncentives.AddRange(apprenticeshipIncentives);
            _context.SaveChanges();

            var actual = await _sut.GetList();

            actual.Count.Should().Be(apprenticeshipIncentives.Count);
            actual.Should().Contain(x => x.Id == apprenticeshipIncentives[0].Id);
            actual.Should().Contain(x => x.ApprenticeshipId == apprenticeshipIncentives[0].ApprenticeshipId);
            actual.Should().Contain(x => x.ULN == apprenticeshipIncentives[0].ULN);
            actual.Should().Contain(x => x.UKPRN == apprenticeshipIncentives[0].UKPRN);
        }
        public async Task Then_legal_entities_with_unsent_clawbacks_in_the_current_period_are_returned_when_isSent_if_false()
        {
            short collectionPeriodYear = 2020;
            byte  collectionPeriod     = 5;
            var   clawbackPayments     = new List <ClawbackPayment>
            {
                _fixture.Build <ClawbackPayment>().With(x => x.CollectionPeriodYear, collectionPeriodYear).With(x => x.CollectionPeriod, collectionPeriod).With(x => x.DateClawbackSent, (DateTime?)null).Create(),
                _fixture.Build <ClawbackPayment>().With(x => x.CollectionPeriodYear, collectionPeriodYear).With(x => x.CollectionPeriod, collectionPeriod).With(x => x.DateClawbackSent, (DateTime?)null).Create(),
                _fixture.Build <ClawbackPayment>().With(x => x.CollectionPeriodYear, collectionPeriodYear).With(x => x.CollectionPeriod, collectionPeriod).With(x => x.DateClawbackSent).Create(),
                _fixture.Build <ClawbackPayment>().With(x => x.CollectionPeriodYear, collectionPeriodYear).With(x => x.CollectionPeriod, (byte)(collectionPeriod + 1)).With(x => x.DateClawbackSent, (DateTime?)null).Create(),
            };

            _context.ClawbackPayments.AddRange(clawbackPayments);
            _context.SaveChanges();

            var actual = await _sut.GetClawbackLegalEntities(collectionPeriodYear, collectionPeriod, false);

            actual.Count.Should().Be(2);
            actual.Should().Contain(x => x.AccountLegalEntityId == clawbackPayments[0].AccountLegalEntityId &&
                                    x.AccountId == clawbackPayments[0].AccountId &&
                                    !x.IsSent);
            actual.Should().Contain(x => x.AccountLegalEntityId == clawbackPayments[1].AccountLegalEntityId &&
                                    x.AccountId == clawbackPayments[1].AccountId &&
                                    !x.IsSent);
        }
Exemple #12
0
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var account         = _fixture.Create <Models.Account>();
            var allApplications = _fixture.Build <Models.IncentiveApplication>().With(x => x.AccountLegalEntityId, account.AccountLegalEntityId).CreateMany <Models.IncentiveApplication>(10).ToArray();
            var applicationId   = Guid.NewGuid();

            allApplications[1].Id = applicationId;

            _context.Accounts.Add(account);
            _context.Applications.AddRange(allApplications);
            _context.SaveChanges();

            // Act
            var actual = await _sut.Get(x => x.ApplicationId == applicationId);

            //Assert
            actual.ApplicationId.Should().Be(applicationId);
            actual.ApplicationStatus.Should().Be(allApplications[1].Status);
            actual.LegalEntityId.Should().Be(account.LegalEntityId);
            actual.VrfCaseId.Should().Be(account.VrfCaseId);
        }
Exemple #13
0
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var expectedAccounts    = _fixture.Build <Models.Account>().With(x => x.VrfCaseStatus, "To Process").CreateMany(5);
            var notExpectedAccounts = _fixture.Build <Models.Account>().With(x => x.VrfCaseId, (string)null).CreateMany(5);

            _context.Accounts.AddRange(expectedAccounts);
            _context.Accounts.AddRange(notExpectedAccounts);
            _context.SaveChanges();

            // Act
            var actual = await _sut.GetList(x => x.VrfCaseStatus != "Case Request completed" && x.VrfCaseId != null);

            //Assert
            actual.Should().BeEquivalentTo(expectedAccounts, opts => opts.ExcludingMissingMembers());
        }
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var accountLegalEntityId = _fixture.Create <long>();
            var allPendingPayments   = _fixture.CreateMany <PendingPayment>(10).ToArray();

            allPendingPayments[0].AccountLegalEntityId = accountLegalEntityId;
            allPendingPayments[3].AccountLegalEntityId = accountLegalEntityId;

            _context.PendingPayments.AddRange(allPendingPayments);
            _context.SaveChanges();

            // Act
            var actual = (await _sut.GetList(x => x.AccountLegalEntityId == accountLegalEntityId)).ToArray();

            //Assert
            actual.All(x => x.AccountLegalEntityId == accountLegalEntityId).Should().BeTrue();
            actual.Should().BeEquivalentTo(new[] { allPendingPayments[0], allPendingPayments[3] }, opts => opts.ExcludingMissingMembers());
        }
Exemple #15
0
        public async Task Then_the_expected_account_is_returned_if_it_exists()
        {
            // Arrange
            const string legalEntityId = "XYZ123__";
            var          testAccounts  = _fixture.CreateMany <Models.Account>(4).ToList();

            testAccounts.First().HashedLegalEntityId = legalEntityId;
            testAccounts.Last().HashedLegalEntityId  = legalEntityId;

            _dbContext.AddRange(testAccounts);
            _dbContext.SaveChanges();

            // Act
            var accounts = await _sut.GetByHashedLegalEntityId(legalEntityId);

            // Assert
            accounts.Should().BeEquivalentTo(testAccounts.Where(x => x.HashedLegalEntityId == legalEntityId),
                                             opt => opt.ExcludingMissingMembers());
        }
Exemple #16
0
        public async Task Then_data_is_fetched_from_database()
        {
            // Arrange
            var        allAccounts = _fixture.CreateMany <Models.Account>(10).ToArray();
            const long accountId   = -1;

            allAccounts[0].Id = accountId;
            allAccounts[1].Id = accountId;

            _context.Accounts.AddRange(allAccounts);
            _context.SaveChanges();

            // Act
            var actual = (await _sut.GetList(x => x.AccountId == accountId)).ToArray();

            //Assert
            actual.All(x => x.AccountId == accountId).Should().BeTrue();
            actual.Should().BeEquivalentTo(new [] { allAccounts[0], allAccounts[1] },
                                           opts => opts.ExcludingMissingMembers());
        }
        public async Task Then_legal_entities_with_pending_payments_in_the_current_period_are_returned()
        {
            short collectionPeriodYear = 2020;
            byte  collectionPeriod     = 5;
            var   pendingPayments      = new List <PendingPayment>
            {
                _fixture.Build <PendingPayment>().With(x => x.PaymentYear, collectionPeriodYear).With(x => x.PeriodNumber, collectionPeriod).With(x => x.PaymentMadeDate, (DateTime?)null).Create(),
                _fixture.Build <PendingPayment>().With(x => x.PaymentYear, collectionPeriodYear).With(x => x.PeriodNumber, collectionPeriod).With(x => x.PaymentMadeDate, (DateTime?)null).Create(),
                _fixture.Build <PendingPayment>().With(x => x.PaymentYear, collectionPeriodYear).With(x => x.PeriodNumber, (byte)(collectionPeriod + 1)).With(x => x.PaymentMadeDate, (DateTime?)null).Create(),
            };

            _context.PendingPayments.AddRange(pendingPayments);
            _context.SaveChanges();

            var actual = await _sut.GetPayableLegalEntities(collectionPeriodYear, collectionPeriod);

            actual.Count.Should().Be(2);
            actual.Should().Contain(x => x.AccountLegalEntityId == pendingPayments[0].AccountLegalEntityId);
            actual.Should().Contain(x => x.AccountLegalEntityId == pendingPayments[1].AccountLegalEntityId);
        }