Пример #1
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());
        }
Пример #2
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());
        }
Пример #3
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());
        }
Пример #4
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());
        }