Exemplo n.º 1
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());
        }
Exemplo n.º 2
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());
        }
        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);
        }
Exemplo n.º 4
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);
        }