public IActionResult Withdraw(string accountNumber, string amount) { string errorMessage = CheckInputs(accountNumber, amount); if (errorMessage == null) { Account account = bankRepo.GetAccount(accountNumber); if (bankRepo.CheckIfWithdrawIsOk(account.Balance, amount) == false) { errorMessage = $"Saldo måste vara högre än summa. Aktuellt saldo: {account.Balance}"; } else { var newBalance = bankRepo.Withdraw(account, amount); TempData["responseSuccess"] = $"Konto: {accountNumber}, Nytt saldo: { newBalance }"; return(RedirectToAction("WithdrawAndDeposit", new { accountNumber })); } } TempData["responseFailed"] = errorMessage; return(RedirectToAction("WithdrawAndDeposit", new { accountNumber })); }
public void CheckIfWithdrawIsOk_Test(bool expectedValue, double balance, double amount) { var acutalValue = bankRepository.CheckIfWithdrawIsOk(balance, amount.ToString()); Assert.Equal(expectedValue, acutalValue); }