public async Task ThenEmployerUsersAreReturned()
        {
            var pageNumber     = 123;
            var pageSize       = 9485;
            var criteria       = "abc";
            var expectedResult = new PagedApiResponseViewModel <UserSummaryViewModel>
            {
                Page       = pageNumber,
                TotalPages = pageNumber + 2,
                Data       = new List <UserSummaryViewModel>
                {
                    new UserSummaryViewModel
                    {
                        FirstName = "Joe",
                        LastName  = "Bloggs",
                        Id        = "ABC123",
                        Href      = "api/users/ABC123",
                        Email     = "*****@*****.**",
                        IsActive  = true,
                        IsLocked  = false
                    }
                }
            };

            HttpClient.Setup(x => x.GetAsync(It.IsAny <string>())).ReturnsAsync(JsonConvert.SerializeObject(expectedResult));


            var response = await Client.SearchEmployerUsers(criteria, pageNumber, pageSize);

            HttpClient.Verify(x => x.GetAsync(Configuration.ApiBaseUrl + $"api/users/search/{criteria}/?pageNumber={pageNumber}&pageSize={pageSize}"));
            response.ShouldBeEquivalentTo(expectedResult);
        }
Exemplo n.º 2
0
        public void InitialiseTest()
        {
            _accountWithBalanceViewModels = new List <AccountWithBalanceViewModel>
            {
                new AccountWithBalanceViewModel
                {
                    AccountId     = 123,
                    AccountHashId = "ERERE",
                    Balance       = 1000m,
                    Href          = "http://tempuri.org/account/ERERE",
                    AccountName   = "Test Account",
                    IsLevyPayer   = true
                },
                new AccountWithBalanceViewModel
                {
                    AccountId     = 345,
                    AccountHashId = "CNDFJ",
                    Balance       = 1000m,
                    Href          = "http://tempuri.org/account/CNDFJ",
                    AccountName   = "Test Account 2",
                    IsLevyPayer   = true
                }
            };

            _pagedApiResponseViewModel = new PagedApiResponseViewModel <AccountWithBalanceViewModel>
            {
                Data       = _accountWithBalanceViewModels,
                Page       = 1,
                TotalPages = 2
            };

            Setup();
        }
        public async Task ThenAccountsAreReturnedWithTheirBalanceAndAUriToGetAccountDetails()
        {
            var accountsResponse = new PagedApiResponseViewModel <AccountWithBalanceViewModel>()
            {
                Page       = 123,
                TotalPages = 123,
                Data       = new List <AccountWithBalanceViewModel>
                {
                    new AccountWithBalanceViewModel {
                        AccountHashId = "ABC123", AccountId = 123, AccountName = "Test 1", IsLevyPayer = true
                    },
                    new AccountWithBalanceViewModel {
                        AccountHashId = "ABC999", AccountId = 987, AccountName = "Test 2", IsLevyPayer = true
                    }
                }
            };

            ApiService.Setup(s => s.GetAccounts(null, 1000, 1, It.IsAny <CancellationToken>()))
            .ReturnsAsync(accountsResponse);

            var result = await Controller.GetAccounts();

            result.Should().NotBeNull();
            result.Should().BeOfType <OkNegotiatedContentResult <PagedApiResponseViewModel <AccountWithBalanceViewModel> > >();

            var okResult = (OkNegotiatedContentResult <PagedApiResponseViewModel <AccountWithBalanceViewModel> >)result;

            okResult.Content.Should().NotBeNull();
            okResult.Content.ShouldBeEquivalentTo(accountsResponse);
        }
        public async Task FoundNotLevyPayerEmployerAccount_Event_Is_Not_Published_If_All_Employer_Is_Marked_As_IsLevyPayer()
        {
            int batchSize = 5;
            var pagedOneApiResponseViewModel = new PagedApiResponseViewModel <AccountWithBalanceViewModel>
            {
                TotalPages = 1,
                Data       = new List <AccountWithBalanceViewModel>
                {
                    new AccountWithBalanceViewModel
                    {
                        AccountId = 1,
                        Balance   = 100m,
                        RemainingTransferAllowance = 10m,
                        AccountName = "Test Ltd",
                        IsLevyPayer = true
                    }
                }
            };

            accountApiClient
            .SetupSequence(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime?>()))
            .ReturnsAsync(new PagedApiResponseViewModel <AccountWithBalanceViewModel>
            {
                TotalPages = pagedOneApiResponseViewModel.TotalPages
            })
            .ReturnsAsync(pagedOneApiResponseViewModel);

            bulkWriter
            .Setup(x => x.Write(It.IsAny <LevyAccountModel>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

            bulkWriter
            .Setup(x => x.DeleteAndFlush(It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);


            var service = new ManageLevyAccountBalanceService
                          (
                repository.Object,
                accountApiClient.Object,
                logger,
                bulkWriter.Object,
                batchSize,
                endpointInstanceFactory.Object
                          );

            await service.RefreshLevyAccountDetails(CancellationToken.None).ConfigureAwait(false);

            endpointInstance
            .Verify(svc => svc.Publish(It.Is <FoundNotLevyPayerEmployerAccount>(x => x.AccountId == 1),
                                       It.IsAny <PublishOptions>()),
                    Times.Never);
        }
Exemplo n.º 5
0
        private List <LevyAccountModel> MapToLevyAccountModel(PagedApiResponseViewModel <AccountWithBalanceViewModel> pagedAccountWithBalanceViewModel)
        {
            var levyAccountModels = pagedAccountWithBalanceViewModel.Data.Select(accountDetail => new LevyAccountModel
            {
                AccountId         = accountDetail.AccountId,
                IsLevyPayer       = accountDetail.IsLevyPayer,
                AccountName       = accountDetail.AccountName,
                Balance           = accountDetail.Balance,
                TransferAllowance = accountDetail.RemainingTransferAllowance,
            }).ToList();

            return(levyAccountModels);
        }
        public AccountLegalEntitiesControllerTestsFixture()
        {
            Query = new GetAccountLegalEntitiesQuery {
                PageSize = 1000, PageNumber = 1
            };
            Mediator             = new Mock <IMediator>();
            AccountLegalEntities = new PagedApiResponseViewModel <AccountLegalEntityViewModel>();
            Response             = new GetAccountLegalEntitiesResponse {
                AccountLegalEntities = AccountLegalEntities
            };

            Mediator.Setup(m => m.SendAsync(Query)).ReturnsAsync(Response);

            Controller = new AccountLegalEntitiesController(Mediator.Object);
        }
Exemplo n.º 7
0
        public void Arrange()
        {
            _mediator       = new Mock <IMediator>();
            _log            = new Mock <ILog>();
            _hashingService = new Mock <IHashingService>();
            _apiService     = new Mock <IEmployerAccountsApiService>();
            _mapper         = new Mock <IMapper>();
            _orchestrator   = new AccountsOrchestrator(_mediator.Object, _log.Object, _mapper.Object, _hashingService.Object, _apiService.Object);

            var accountsResponse = new PagedApiResponseViewModel <AccountWithBalanceViewModel>()
            {
                Page       = 123,
                TotalPages = 123,
                Data       = new List <AccountWithBalanceViewModel>
                {
                    new AccountWithBalanceViewModel {
                        AccountHashId = "ABC123", AccountId = 123, AccountName = "Test 1", IsLevyPayer = true
                    },
                    new AccountWithBalanceViewModel {
                        AccountHashId = "ABC999", AccountId = 987, AccountName = "Test 2", IsLevyPayer = true
                    }
                }
            };

            var balanceResponse = new GetAccountBalancesResponse
            {
                Accounts = new List <AccountBalance>
                {
                    new AccountBalance {
                        AccountId = 123, Balance = 20, RemainingTransferAllowance = 20, StartingTransferAllowance = 10
                    },
                    new AccountBalance {
                        AccountId = 987, Balance = 200, RemainingTransferAllowance = 200, StartingTransferAllowance = 100
                    },
                }
            };

            _apiService.Setup(s => s.GetAccounts(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(accountsResponse);

            _mediator
            .Setup(x => x.SendAsync(It.IsAny <GetAccountBalancesRequest>()))
            .ReturnsAsync(balanceResponse);
        }
Exemplo n.º 8
0
        public async Task ItShouldRetrieveAllOfTheAvailableUsers()
        {
            var firstPage = new PagedApiResponseViewModel <UserSummaryViewModel>
            {
                TotalPages = 2,
                Page       = 1,
                Data       = new List <UserSummaryViewModel> {
                    new UserSummaryViewModel()
                }
            };


            _employerUserApiClient
            .Setup(x => x.GetPageOfEmployerUsers(1, 50))
            .Returns(Task.FromResult(firstPage));

            var actual = await _unit.FindAllDetails(50, 1);

            _employerUserApiClient
            .Verify(x => x.GetPageOfEmployerUsers(1, 50), Times.Once);

            Assert.AreEqual(1, actual.Count());
        }
        public async Task Refresh_All_Levy_Account_Details_Correctly()
        {
            var accountIds = new List <long> {
                1, 2, 3
            };
            int batchSize = 2;

            var pagedOneApiResponseViewModel = new PagedApiResponseViewModel <AccountWithBalanceViewModel>
            {
                TotalPages = 2,
                Data       = new List <AccountWithBalanceViewModel>
                {
                    new AccountWithBalanceViewModel
                    {
                        AccountId = 1,
                        Balance   = 100m,
                        RemainingTransferAllowance = 10m,
                        AccountName = "Test Ltd",
                        IsLevyPayer = true
                    }
                }
            };

            var pagedTwoApiResponseViewModel = new PagedApiResponseViewModel <AccountWithBalanceViewModel>
            {
                TotalPages = 2,
                Data       = new List <AccountWithBalanceViewModel>
                {
                    new AccountWithBalanceViewModel
                    {
                        AccountId = 2,
                        Balance   = 200m,
                        RemainingTransferAllowance = 20m,
                        AccountName = "Test 2 Ltd",
                        IsLevyPayer = true
                    },
                    new AccountWithBalanceViewModel
                    {
                        AccountId = 3,
                        Balance   = 300m,
                        RemainingTransferAllowance = 30m,
                        AccountName = "Test 3 Ltd",
                        IsLevyPayer = false
                    }
                }
            };


            accountApiClient
            .SetupSequence(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime?>()))
            .ReturnsAsync(new PagedApiResponseViewModel <AccountWithBalanceViewModel>
            {
                TotalPages = 2
            })
            .ReturnsAsync(pagedOneApiResponseViewModel)
            .ReturnsAsync(pagedTwoApiResponseViewModel);

            bulkWriter
            .Setup(x => x.Write(It.IsAny <LevyAccountModel>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

            bulkWriter
            .Setup(x => x.DeleteAndFlush(It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);


            var service = new ManageLevyAccountBalanceService
                          (
                repository.Object,
                accountApiClient.Object,
                logger,
                bulkWriter.Object,
                batchSize,
                endpointInstanceFactory.Object
                          );

            await service.RefreshLevyAccountDetails(new CancellationToken()).ConfigureAwait(false);

            accountApiClient
            .Verify(x => x.GetPageOfAccounts(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime?>()), Times.Exactly(3));

            bulkWriter
            .Verify(x => x.Write(It.IsAny <LevyAccountModel>(), It.IsAny <CancellationToken>()), Times.Exactly(3));

            bulkWriter
            .Verify(x => x.DeleteAndFlush(It.IsAny <CancellationToken>()), Times.Exactly(2));
        }