Example #1
0
        public async Task ItShouldReturnTheEntireListOfAccounts()
        {
            AccountApiClient.Setup(x => x.GetPageOfAccounts(It.IsAny <int>(), 10, null))
            .ReturnsAsync(_pagedApiResponseViewModel);

            AccountApiClient
            .Setup(x => x.GetAccount(It.IsAny <string>()))
            .ReturnsAsync(new AccountDetailViewModel());

            _sut = new Services.AccountRepository(
                AccountApiClient.Object,
                PayeSchemeObfuscator.Object,
                DatetimeService.Object,
                Logger.Object,
                HashingService.Object);

            var actual = await _sut.FindAllDetails(10, 1);

            AccountApiClient.Verify(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), null), Times.Once);
            AccountApiClient.Verify(x => x.GetAccount(It.IsAny <string>()), Times.Exactly(2));
            Assert.IsNotNull(actual);
            var list = actual.ToList();

            CollectionAssert.IsNotEmpty(list);
            Assert.AreEqual(2, list.Count());
        }
Example #2
0
        public async Task ItShouldReturnAnEmptyListIfGetAccountsThrowsAnHttpRequestException()
        {
            AccountApiClient
            .Setup(x => x.GetPageOfAccounts(It.IsAny <int>(), 10, null))
            .ReturnsAsync(_pagedApiResponseViewModel);

            var e = new HttpRequestException("Some exception message");

            AccountApiClient
            .Setup(x => x.GetAccount(It.IsAny <string>()))
            .ThrowsAsync(e);

            _sut = new Services.AccountRepository(
                AccountApiClient.Object,
                PayeSchemeObfuscator.Object,
                DatetimeService.Object,
                Logger.Object,
                HashingService.Object);

            var actual = await _sut.FindAllDetails(10, 1);

            AccountApiClient.Verify(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), null), Times.AtLeastOnce);
            AccountApiClient.Verify(x => x.GetAccount(It.IsAny <string>()), Times.AtLeastOnce);
            Logger.Verify(x => x.Error(e, $"Exception while retrieving details for account ID {_accountWithBalanceViewModels.First().AccountHashId}"));
            Assert.IsNotNull(actual);
            CollectionAssert.IsEmpty(actual.ToList());
        }
        public async Task ItShouldReturnTheAccountAndTheTeamMembers()
        {
            var id = "123";

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(new AccountDetailViewModel()
            {
            });

            var fixture = new Fixture();

            AccountApiClient.Setup(x => x.GetAccountUsers(It.IsAny <string>())).ReturnsAsync(new List <TeamMemberViewModel>()
            {
                fixture.Create <TeamMemberViewModel>(),
                fixture.Create <TeamMemberViewModel>()
            });

            var actual = await _sut.Get(id, AccountFieldsSelection.TeamMembers);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));

            Assert.IsNotNull(actual);
            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.LegalEntities);
            Assert.IsNotEmpty(actual.TeamMembers);
            Assert.IsNull(actual.Transactions);
        }
Example #4
0
        public async Task ItShouldReturnTheAccountAndTheTeamMembers()
        {
            var id = "123";

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(new AccountDetailViewModel()
            {
            });


            AccountApiClient.Setup(x => x.GetAccountUsers(It.IsAny <string>())).ReturnsAsync(new List <TeamMemberViewModel>()
            {
                new TeamMemberViewModel()
                {
                    Status = InvitationStatus.Accepted, Role = "Role",
                    Email  = "*****@*****.**", Name = "Name1", CanReceiveNotifications = true, UserRef = ""
                },
                new TeamMemberViewModel()
                {
                    Status = InvitationStatus.Accepted, Role = "Role",
                    Email  = "*****@*****.**", Name = "Name2", CanReceiveNotifications = true, UserRef = ""
                }
            });

            var actual = await _sut.Get(id, AccountFieldsSelection.TeamMembers);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));

            Assert.IsNotNull(actual);
            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.LegalEntities);
            Assert.IsNotEmpty(actual.TeamMembers);
            Assert.IsNull(actual.Transactions);
        }
        public ProcessFullyApprovedCohortCommandFixture SetApprenticeshipEmployerType(ApprenticeshipEmployerType apprenticeshipEmployerType)
        {
            AccountApiClient.Setup(c => c.GetAccount(Command.AccountId))
            .ReturnsAsync(new AccountDetailViewModel
            {
                ApprenticeshipEmployerType = apprenticeshipEmployerType.ToString()
            });

            return(this);
        }
        public async Task ItShouldReturnTheMatchingAccountWithOutLegalEntitiesThatAreOutOfScope(
            EmployerAgreementStatus scope)
        {
            var id = "123";

            var accountResponse = new AccountDetailViewModel
            {
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel {
                        Href = "https://tempuri.org/legalEntity/{id}", Id = "ABC"
                    }
                })
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountResponse);

            var legalEntityResponse = new LegalEntityViewModel
            {
                AgreementStatus = scope
            };

            var legalEntity = accountResponse.LegalEntities[0];

            AccountApiClient.Setup(x => x.GetResource <LegalEntityViewModel>(legalEntity.Href))
            .ReturnsAsync(legalEntityResponse);

            var actual = await _sut.Get(id, AccountFieldsSelection.Organisations);


            Logger.Verify(
                x => x.Debug(
                    $"{nameof(IAccountApiClient)}.{nameof(IAccountApiClient.GetResource)}<{nameof(AccountDetailViewModel)}>(\"/api/accounts/{id}\");"),
                Times.Once);
            Logger.Verify(
                x => x.Debug(
                    $"{nameof(IAccountApiClient)}.{nameof(IAccountApiClient.GetResource)}<{nameof(LegalEntityViewModel)}>(\"{legalEntity.Href}\");"),
                Times.Once);

            AccountApiClient.Verify(x => x.GetResource <LegalEntityViewModel>(It.IsAny <string>()),
                                    Times.Exactly(accountResponse.LegalEntities.Count));

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.LegalEntities);
            Assert.AreEqual(0, actual.LegalEntities.Count());

            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.Transactions);
            Assert.IsNull(actual.TeamMembers);
        }
Example #7
0
        public async Task ThenThePayeSchemeIsReturned()
        {
            var expectedPayeScheme = new PayeSchemeViewModel();

            var payeSchemeHref = $"/api/accounts/2385/payeschemes/123456";

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(payeSchemeHref)).ReturnsAsync(expectedPayeScheme);

            var result = await AccountGateway.GetPayeScheme(payeSchemeHref);

            result.Should().Be(expectedPayeScheme);
            AccountApiClient.Verify(x => x.GetResource <PayeSchemeViewModel>(payeSchemeHref), Times.Once);
        }
Example #8
0
        public async Task ThenTheAccountDetailsAreReturned()
        {
            var expectedAccountInformation = new AccountDetailViewModelBuilder().Build();

            var accountHref = $"/api/accounts/2385";

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>(accountHref)).ReturnsAsync(expectedAccountInformation);

            var result = await AccountGateway.GetAccount(accountHref);

            result.Should().Be(expectedAccountInformation);
            AccountApiClient.Verify(x => x.GetResource <AccountDetailViewModel>(accountHref), Times.Once);
        }
Example #9
0
        public async Task ThenTheAgreementIsReturned()
        {
            var expectedAgreement = new EmployerAgreementView();

            var agreementHref = $"/api/accounts/2385/agreements/123456";

            AccountApiClient.Setup(x => x.GetResource <EmployerAgreementView>(agreementHref)).ReturnsAsync(expectedAgreement);

            var result = await AccountGateway.GetEmployerAgreement(agreementHref);

            result.Should().Be(expectedAgreement);
            AccountApiClient.Verify(x => x.GetResource <EmployerAgreementView>(agreementHref), Times.Once);
        }
Example #10
0
        public async Task ThenTheLevyDeclarationsAreReturned()
        {
            var expectedLevyDeclarations = new AccountResourceList <LevyDeclarationViewModel>(new List <LevyDeclarationViewModel>());

            var levyHref = $"/api/accounts/2385/levy/";

            AccountApiClient.Setup(x => x.GetResource <AccountResourceList <LevyDeclarationViewModel> >(levyHref)).ReturnsAsync(expectedLevyDeclarations);

            var result = await AccountGateway.GetLevyDeclarations(levyHref);

            result.Should().BeSameAs(expectedLevyDeclarations);
            AccountApiClient.Verify(x => x.GetResource <AccountResourceList <LevyDeclarationViewModel> >(levyHref), Times.Once);
        }
        public async Task ThenTheLegalEntityIsReturned()
        {
            var expectedLegalEntity = new LegalEntityViewModel();

            var legalEntityHref = $"/api/accounts/2385/legalentities/123456";

            AccountApiClient.Setup(x => x.GetResource <LegalEntityViewModel>(legalEntityHref)).ReturnsAsync(expectedLegalEntity);

            var result = await AccountGateway.GetLegalEntity(legalEntityHref);

            result.Should().Be(expectedLegalEntity);
            AccountApiClient.Verify(x => x.GetResource <LegalEntityViewModel>(legalEntityHref), Times.Once);
        }
Example #12
0
        public async Task ItShouldReturnNullOnException()
        {
            var id = "123";

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ThrowsAsync(new Exception());

            var actual = await _sut.Get(id, AccountFieldsSelection.PayeSchemes);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Once);
            Logger.Verify(x => x.Error(It.IsAny <Exception>(), $"Account with id {id} not found"));

            Assert.IsNull(actual);
        }
        public async Task ItShouldReturnJustTheAccount()
        {
            var id = "123";

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(new AccountDetailViewModel());

            var actual = await _sut.Get(id, AccountFieldsSelection.None);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Once);

            Assert.IsNotNull(actual);
            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.LegalEntities);
            Assert.IsNull(actual.TeamMembers);
            Assert.IsNull(actual.Transactions);
        }
Example #14
0
        public async Task ItShouldThrowsAnExceptionWhenAccountHasNoResourceForPayeScheme()
        {
            //Arrange
            AccountApiClient.Setup(x => x.GetPageOfAccounts(It.IsAny <int>(), 10, null))
            .ReturnsAsync(_pagedApiResponseViewModel);

            AccountApiClient
            .Setup(x => x.GetAccount(It.IsAny <string>()))
            .ReturnsAsync(new AccountDetailViewModel
            {
                PayeSchemes = new ResourceList(new[] { new ResourceViewModel {
                                                           Id = "1", Href = "/api/payeschemes/test1"
                                                       } })
            });

            var e = new Exception("Some exception message");

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>()))
            .ThrowsAsync(e);

            var obscuredPayePayeScheme = "123/123456";

            PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>()))
            .Returns(obscuredPayePayeScheme);

            _sut = new Services.AccountRepository(
                AccountApiClient.Object,
                PayeSchemeObfuscator.Object,
                DatetimeService.Object,
                Logger.Object,
                HashingService.Object);

            //Act
            var actual = await _sut.FindAllDetails(10, 1);

            //Assert
            AccountApiClient.Verify(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), null), Times.Once);
            AccountApiClient.Verify(x => x.GetAccount(It.IsAny <string>()), Times.Exactly(2));
            Logger.Verify(x => x.Error(e, $"Exception occured in Account API type of {nameof(PayeSchemeViewModel)} at /api/payeschemes/test1 id 1"));
            Assert.IsNotNull(actual);
            var list = actual.ToList();

            CollectionAssert.IsNotEmpty(list);
            Assert.AreEqual(2, list.Count());
        }
Example #15
0
        public async Task ItShouldReturnTheEntireListOfAccountsWhenAccountHasPayeScheme()
        {
            //Arrange
            AccountApiClient.Setup(x => x.GetPageOfAccounts(It.IsAny <int>(), 10, null))
            .ReturnsAsync(_pagedApiResponseViewModel);

            AccountApiClient
            .Setup(x => x.GetAccount(It.IsAny <string>()))
            .ReturnsAsync(new AccountDetailViewModel
            {
                PayeSchemes = new ResourceList(new[] { new ResourceViewModel {
                                                           Id = "1", Href = "/api/payeschemes/test1"
                                                       } })
            });

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>()))
            .ReturnsAsync(new PayeSchemeViewModel {
                Name = "Test", Ref = "123"
            });

            var obscuredPayePayeScheme = "123/123456";

            PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>()))
            .Returns(obscuredPayePayeScheme);

            _sut = new Services.AccountRepository(
                AccountApiClient.Object,
                PayeSchemeObfuscator.Object,
                DatetimeService.Object,
                Logger.Object,
                HashingService.Object);

            //Act
            var actual = await _sut.FindAllDetails(10, 1);

            //Assert
            AccountApiClient.Verify(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), null), Times.Once);
            AccountApiClient.Verify(x => x.GetAccount(It.IsAny <string>()), Times.Exactly(2));
            Assert.IsNotNull(actual);
            var list = actual.ToList();

            CollectionAssert.IsNotEmpty(list);
            Assert.AreEqual(2, list.Count());
        }
Example #16
0
        public async Task ItShouldReturnAZeroBalanceWhenTheClientThrowsAnException()
        {
            var id = "123";

            var exception = new Exception("Some exception");

            AccountApiClient
            .Setup(x => x.GetResource <AccountWithBalanceViewModel>($"/api/accounts/{id}"))
            .ThrowsAsync(exception);

            Logger.Setup(x => x.Debug(It.IsAny <string>()));
            Logger.Setup(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>()));

            var actual = await _sut.GetAccountBalance(id);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Never);
            Logger.Verify(x => x.Error(exception, $"Account Balance with id {id} not found"), Times.Once);

            Assert.AreEqual(0, actual);
        }
        public async Task ItShoudFailGracefullyAndLogErrorWhenClientThrowsExceptionOnGetResourceAccount()
        {
            var id = "123";


            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ThrowsAsync(new Exception());


            var actual = await _sut.Get(id, AccountFieldsSelection.Organisations);


            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Once);
            Logger.Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once);


            AccountApiClient.Verify(x => x.GetResource <AccountDetailViewModel>(It.IsAny <string>()), Times.Once);
            AccountApiClient.Verify(x => x.GetResource <LegalEntityViewModel>(It.IsAny <string>()), Times.Never);

            Assert.IsNull(actual);
        }
Example #18
0
        ItShouldReturnTheMatchingAccountWithAnEmptyListOfTeamMembersWhenAnExceptionIsThrownObtainingTheTeeamMembers()
        {
            var id = "123";

            var accountDetailViewModel = new AccountDetailViewModel
            {
                HashedAccountId = "ASDAS",
                AccountId       = 123
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            var teamMemberResponse = new List <TeamMemberViewModel>
            {
                new TeamMemberViewModel {
                    Email = "*****@*****.**"
                },
                new TeamMemberViewModel {
                    Email = "*****@*****.**"
                }
            };

            AccountApiClient.Setup(x => x.GetAccountUsers(accountDetailViewModel.HashedAccountId))
            .ThrowsAsync(new Exception("Some Exception"));

            var actual = await _sut.Get(id, AccountFieldsSelection.TeamMembers);


            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));


            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.TeamMembers);
            CollectionAssert.IsEmpty(actual.TeamMembers);
            Assert.IsNull(actual.Transactions);
            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.LegalEntities);
        }
Example #19
0
        public async Task ItShouldReturnTheMatchingAccountWithTeamMembers()
        {
            var id = "123";

            var accountDetailViewModel = new AccountDetailViewModel
            {
                HashedAccountId = "ASDAS",
                AccountId       = 123
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            var teamMemberResponse = new List <TeamMemberViewModel>
            {
                new TeamMemberViewModel {
                    Email = "*****@*****.**"
                },
                new TeamMemberViewModel {
                    Email = "*****@*****.**"
                }
            };

            AccountApiClient.Setup(x => x.GetAccountUsers(accountDetailViewModel.HashedAccountId))
            .ReturnsAsync(teamMemberResponse);

            var actual = await _sut.Get(id, AccountFieldsSelection.TeamMembers);


            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));


            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.TeamMembers);
            Assert.AreEqual(teamMemberResponse.Count, actual.TeamMembers.Count);
            Assert.IsNull(actual.Transactions);
            Assert.IsNull(actual.PayeSchemes);
            Assert.IsNull(actual.LegalEntities);
        }
Example #20
0
        public async Task ItShouldReturnTheMatchingAccountBalanceValue()
        {
            var id       = "123";
            var response = new AccountWithBalanceViewModel
            {
                AccountId     = 123,
                AccountHashId = "ERWERW",
                AccountName   = "Test Account",
                Balance       = 0m,
                Href          = "https://tempuri.org/account/{id}",
                IsLevyPayer   = true
            };

            AccountApiClient.Setup(x => x.GetResource <AccountWithBalanceViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(response);

            var actual = await _sut.GetAccountBalance(id);

            Logger.Verify(x =>
                          x.Debug(
                              $"{nameof(IAccountApiClient)}.{nameof(IAccountApiClient.GetResource)}<{nameof(AccountWithBalanceViewModel)}>(\"/api/accounts/{id}\"); {response.Balance}"));
            Assert.AreEqual(response.Balance, actual);
        }
        public async Task ItShoudFailGracefullyAndLogErrorWhenClientThrowsExceptionOnGetResourceLegalEntity()
        {
            var id = "123";

            var accountResponse = new AccountDetailViewModel
            {
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel {
                        Href = "https://tempuri.org/legalEntity/{id}", Id = "ABC"
                    }
                })
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountResponse);


            var legalEntity = accountResponse.LegalEntities[0];

            AccountApiClient.Setup(x => x.GetResource <LegalEntityViewModel>(legalEntity.Href))
            .ThrowsAsync(new Exception());

            var actual = await _sut.Get(id, AccountFieldsSelection.Organisations);


            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));
            Logger.Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>()), Times.Once);


            AccountApiClient.Verify(x => x.GetResource <LegalEntityViewModel>(It.IsAny <string>()),
                                    Times.Exactly(accountResponse.LegalEntities.Count));

            Assert.IsNotNull(actual);
            Assert.IsEmpty(actual.LegalEntities);
        }
        public async Task ItShouldReturnTheMatchingAccountWithTransaction()
        {
            var id = "123";

            var accountDetailViewModel = new AccountDetailViewModel
            {
                AccountId   = 123,
                Balance     = 0m,
                PayeSchemes = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "123/123456",
                        Href = "https://tempuri.org/payescheme/{1}"
                    }
                }),
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "TempUri Limited",
                        Href = "https://tempuri.org/organisation/{1}"
                    }
                }),

                HashedAccountId = "DFGH",
                DateRegistered  = DateTime.Today.AddYears(-2),
                OwnerEmail      = "*****@*****.**",
                DasAccountName  = "Test Account 1"
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            var obscuredPayePayeScheme = "123/123456";

            PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>()))
            .Returns(obscuredPayePayeScheme);


            var payeSchemeViewModel = new PayeSchemeViewModel
            {
                AddedDate    = DateTime.Today.AddMonths(-4),
                Ref          = "123/123456",
                Name         = "123/123456",
                DasAccountId = "123",
                RemovedDate  = null
            };

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>()))
            .ReturnsAsync(payeSchemeViewModel);


            /*
             * This is a testing HACK to avoid using a concrete datetime service
             * because our collegues used DateTime.Now in the code!
             * See ASCS-83 for a fix
             */
            var now = DateTime.Now.Date;
            var startOfFirstFinancialYear = new DateTime(2017, 4, 1);
            var monthsToQuery             = (now.Year - startOfFirstFinancialYear.Year) * 12 +
                                            (now.Month - startOfFirstFinancialYear.Month) + 1;

            DatetimeService.Setup(x => x.GetBeginningFinancialYear(startOfFirstFinancialYear))
            .Returns(startOfFirstFinancialYear);


            var isNotZero             = 100m;
            var isTxDateCreated       = DateTime.Today;
            var transactionsViewModel = new TransactionsViewModel
            {
                new TransactionViewModel
                {
                    Description = "Is Not Null",
                    Amount      = isNotZero,
                    DateCreated = isTxDateCreated
                },
                new TransactionViewModel
                {
                    Description = "Is Not Null 2",
                    Amount      = isNotZero,
                    DateCreated = isTxDateCreated
                }
            };

            AccountApiClient.Setup(x => x.GetTransactions(accountDetailViewModel.HashedAccountId,
                                                          It.IsAny <int>(),
                                                          It.IsAny <int>()))
            .ReturnsAsync(transactionsViewModel
                          );

            var actual = await _sut.Get(id, AccountFieldsSelection.Finance);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));

            PayeSchemeObfuscator
            .Verify(x => x.ObscurePayeScheme(It.IsAny <string>()), Times.Exactly(2));

            AccountApiClient
            .Verify(x => x.GetTransactions(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()),
                    Times.Exactly(monthsToQuery));

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.PayeSchemes);
            Assert.AreEqual(1, actual.PayeSchemes.Count());
            Assert.IsNotNull(actual.Transactions);
            Assert.AreEqual(2 * monthsToQuery, actual.Transactions.Count());

            Assert.IsNull(actual.LegalEntities);
            Assert.IsNull(actual.TeamMembers);
        }
Example #23
0
        public async Task ItShouldReturnTheAccountWithTheChallengedPayeSchemes()
        {
            var id = "123";

            var accountDetailViewModel = new AccountDetailViewModel
            {
                AccountId   = 123,
                Balance     = 0m,
                PayeSchemes = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "123/123456",
                        Href = "https://tempuri.org/payescheme/{1}"
                    }
                }),
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "TempUri Limited",
                        Href = "https://tempuri.org/organisation/{1}"
                    }
                }),
                HashedAccountId = "DFGH",
                DateRegistered  = DateTime.Today.AddYears(-2),
                OwnerEmail      = "*****@*****.**",
                DasAccountName  = "Test Account 1"
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            var obscuredPayePayeScheme = "123/123456";

            PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>()))
            .Returns(obscuredPayePayeScheme);


            var payeSchemeViewModel = new PayeSchemeViewModel
            {
                AddedDate    = DateTime.Today.AddMonths(-4),
                Ref          = "123/123456",
                Name         = "123/123456",
                DasAccountId = "123",
                RemovedDate  = null
            };

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>()))
            .ReturnsAsync(payeSchemeViewModel);

            var actual = await _sut.Get(id, AccountFieldsSelection.PayeSchemes);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));

            PayeSchemeObfuscator.Verify(x => x.ObscurePayeScheme(It.IsAny <string>()), Times.Exactly(2));


            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.PayeSchemes);
            Assert.AreEqual(1, actual.PayeSchemes.Count());

            Assert.IsNull(actual.LegalEntities);
            Assert.IsNull(actual.TeamMembers);
            Assert.IsNull(actual.Transactions);
        }