public void Test_Deposit_Success() { AccountsLib.Account acc = new AccountsLib.Account(3); acc.Deposit(3); acc.Deposit(2); Assert.AreEqual(5, acc.Balance); }
public void Test_DepositMax_Failed() { AccountsLib.Account acc = new AccountsLib.Account(3); acc.Deposit(3); try { acc.Deposit(int.MaxValue); Assert.Fail(); } catch (OverflowException) { Assert.Pass(); } }
public void Test_DepositNegative_Failed() { AccountsLib.Account acc = new AccountsLib.Account(3); acc.Deposit(3); try { acc.Deposit(-2); Assert.Fail(); } catch (Exception e) { Assert.AreEqual("NegativeExc", e.Message); } }
public void Test_TransferNegative_Failed() { AccountsLib.Account acc = new AccountsLib.Account(3); AccountsLib.Account acc2 = new AccountsLib.Account(5); acc.Deposit(3); Assert.AreEqual(false, acc.Transfer(acc2, 4)); }
public void Test_Withdraw_Success() { AccountsLib.Account acc = new AccountsLib.Account(3); acc.Deposit(3); acc.Withdraw(2); Assert.AreEqual(1, acc.Balance); }
public static void DepositToAccount(Account account) { var depositAmount = GetAmountFromUser("Enter the amount to deposit: "); account.Deposit(depositAmount); var successMessage = string.Format("{0}$ has been deposited to Account {1}", depositAmount, account.Id); MessagesPrinter.SuccessMessage(successMessage); }
public void Test_Transfer_Success() { AccountsLib.Account acc = new AccountsLib.Account(3); AccountsLib.Account acc2 = new AccountsLib.Account(5); acc.Deposit(3); Assert.AreEqual(true, acc.Transfer(acc2, 2)); Assert.AreEqual(1, acc.Balance); Assert.AreEqual(2, acc2.Balance); }
public void Test_WithdrawTooMuch_Failed() { AccountsLib.Account acc = new AccountsLib.Account(3); acc.Deposit(2); try { acc.Withdraw(3); Assert.Fail(); } catch (InsufficentFundsException) { Assert.Pass(); } }
static void Main(string[] args) { AccountsLib.Account newAcc = AccountsLib.AccountFactory.CreateAccount(0); newAcc.Deposit(50); try { newAcc.Withdraw(51); } //You are not handling the ArgumentOutOfRangeException/Exception that you throwed if the amount is negative. catch (InsufficentFundsException e) { //You should have used the message from the exception Console.WriteLine("there has been an InsufficentFundsException"); } finally //didn't understood why we need the finally now but i did it { newAcc.Withdraw(29); AccountsLib.Account newAcc2 = AccountsLib.AccountFactory.CreateAccount(0); newAcc.Transfer(newAcc2, 5); Console.WriteLine("{0} {1}", newAcc.Balance, newAcc2.Balance); Console.ReadLine(); } }
} // Balance property public void Transfer(Account acc, int amount) { acc.Deposit(Withdraw(amount)); } // Transfer
public static void DepositToAccount(Account account) { var depositAmount = GetAmountFromUser("Enter the amount to deposit: "); account.Deposit(depositAmount); }