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);
        }
        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));
        }