public void Arrange() { _mediator = new Mock <IMediator>(); _mapper = new Mock <IMapper>(); _log = new Mock <ILog>(); _hashingService = new Mock <IHashingService>(); _apiService = new Mock <IEmployerAccountsApiService>(); _orchestrator = new AccountsOrchestrator(_mediator.Object, _log.Object, _mapper.Object, _hashingService.Object, _apiService.Object); _expectedAccount = new AccountWithBalanceViewModel { AccountId = 124343 }; _expectedAccountBalance = new AccountBalance { AccountId = _expectedAccount.AccountId }; _apiService .Setup(x => x.GetAccounts(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new PagedApiResponseViewModel <AccountWithBalanceViewModel> { Data = new List <AccountWithBalanceViewModel> { _expectedAccount } }); _mediator.Setup(x => x.SendAsync(It.IsAny <GetAccountBalancesRequest>())) .ReturnsAsync(new GetAccountBalancesResponse { Accounts = new List <AccountBalance> { _expectedAccountBalance } }); }
public async Task <OrchestratorResponse <PagedApiResponseViewModel <AccountWithBalanceViewModel> > > GetAllAccountsWithBalances(string toDate, int pageSize, int pageNumber) { _logger.Info("Getting all account balances."); toDate = toDate ?? DateTime.MaxValue.ToString("yyyyMMddHHmmss"); var accountsResult = await _mediator.SendAsync(new GetPagedEmployerAccountsQuery { ToDate = toDate, PageSize = pageSize, PageNumber = pageNumber }); var transactionResult = await _mediator.SendAsync(new GetAccountBalancesRequest { AccountIds = accountsResult.Accounts.Select(account => account.Id).ToList() }); var data = new List <AccountWithBalanceViewModel>(); var accountBalanceHash = BuildAccountBalanceHash(transactionResult.Accounts); accountsResult.Accounts.ForEach(account => { var accountBalanceModel = new AccountWithBalanceViewModel { AccountId = account.Id, AccountName = account.Name, AccountHashId = account.HashedId, PublicAccountHashId = account.PublicHashedId, IsLevyPayer = true }; if (accountBalanceHash.TryGetValue(account.Id, out var accountBalance)) { accountBalanceModel.Balance = accountBalance.Balance; accountBalanceModel.RemainingTransferAllowance = accountBalance.RemainingTransferAllowance; accountBalanceModel.StartingTransferAllowance = accountBalance.StartingTransferAllowance; accountBalanceModel.IsLevyPayer = accountBalance.IsLevyPayer == 1; } data.Add(accountBalanceModel); }); return(new OrchestratorResponse <PagedApiResponseViewModel <AccountWithBalanceViewModel> > { Data = new PagedApiResponseViewModel <AccountWithBalanceViewModel> { Data = data, Page = pageNumber, TotalPages = (accountsResult.AccountsCount / pageSize) + 1 } }); }
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); }