public void CreateAccountDetailsViewModelReturnsAccountData() { const string accountNumber = "1234678"; var bankAccount = new BankAccount { Id = 1, BankId = "TestBank", AccountNumber = accountNumber }; var accountDetails = new AccountDetails { AccountNumber = accountNumber, AccountName = "Current Account", SortCode = "079046", CurrentBalance = 350, OverdraftLimit = 50 }; var model = ViewModelUtility.CreateAccountDetailsViewModel(bankAccount, accountDetails); Assert.That(model, Is.Not.Null); Assert.That(model.AccountId, Is.EqualTo(bankAccount.Id)); Assert.That(model.BankId, Is.EqualTo(bankAccount.BankId)); Assert.That(model.AccountNumber, Is.EqualTo(bankAccount.AccountNumber)); Assert.That(model.AccountName, Is.EqualTo(accountDetails.AccountName)); Assert.That(model.SortCode, Is.EqualTo(accountDetails.SortCode)); Assert.That(model.CurrentBalance, Is.EqualTo(accountDetails.CurrentBalance)); Assert.That(model.OverdraftLimit, Is.EqualTo(accountDetails.OverdraftLimit)); }
public virtual async Task <IActionResult> ApiV1AccountsGetById( [FromRoute][Required] int?account_id ) { if (!account_id.HasValue) { return(ApiResponseUtility.ApiError( HttpStatusCode.BadRequest, "account_id is required" )); } var account = _accountRepository.GetAccountById(account_id.Value); if (account == null) { return(ApiResponseUtility.ApiError( HttpStatusCode.NotFound, $"Bank account with id '{account_id}' does not exist" )); } // when we are fetching account details for a known account, we use the account data service // rather than accessing the connection directly. this allows the service to perform caching // and additional post-processing on the account data before it is returned to the user var accountResult = await _accountDataProvider.GetAccountDetails(account.BankId, account.AccountNumber); if (!accountResult.Success) { var error = new ErrorViewModel { Status = accountResult.StatusCode, Message = accountResult.Error.ErrorMessage, ErrorCode = accountResult.Error.ErrorCode }; return(new ObjectResult(error) { StatusCode = accountResult.StatusCode }); } var model = ViewModelUtility.CreateAccountDetailsViewModel(account, accountResult.Result); return(Ok(model)); }