public void DebitTest() { string customerName = "UnitTest01"; double balance = 0.99; var target = new BankAccount(customerName, balance); double amount = -1.0; try { target.Debit(amount); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Assert.Fail("Unexpected exception type " + ex.GetType().Name); } amount = 1.0; try { target.Debit(amount); } catch (ArgumentOutOfRangeException) { } catch (Exception ex) { Assert.Fail("Unexpected exception type " + ex.GetType().Name); } amount = balance; target.Debit(amount); Assert.AreEqual(target.Balance, balance - amount); }
public static void TransferMoney(BankAccount debitAccount, BankAccount creditAccount, double amount) { try { debitAccount.Debit(amount); } catch (ArgumentOutOfRangeException ex) { throw new ArgumentException("Insufficient balance.", ex); } creditAccount.Credit(amount); }