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 void BankAccountConstructorTest() { string customerName = "UnitTest01"; double balance = 0.99; var target = new BankAccount(customerName, balance); Assert.IsNotNull(target); Assert.AreEqual(target.CustomerName, customerName, true); Assert.AreEqual(target.Balance, balance); }
public void GetBankAccountTest() { string customerName = "UnitTest01"; double balance = 0.0; var expected = new BankAccount(customerName, balance); var actual = Program.GetBankAccount(customerName); Assert.IsNotNull(actual); Assert.AreEqual(expected.CustomerName, actual.CustomerName, true); Assert.AreEqual(expected.Balance, actual.Balance); }
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); }
public static BankAccount GetBankAccount(string customerName) { var balance = GetBalance(customerName); var result = new BankAccount(customerName, balance); return result; }