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 WithdrawFromAccount(Account account) { var withdrawAmount = GetAmountFromUser("Enter the amount to withdraw: "); account.Withdraw(withdrawAmount); var successMessage = string.Format("{0}$ has been withdrawn from Account {1}",withdrawAmount,account.Id); MessagesPrinter.SuccessMessage(successMessage); }
public static void WithdrawFromAccount(Account account) { var withdrawAmount = GetAmountFromUser("Enter the amount to withdraw: "); var canWithdraw = account.Withdraw(withdrawAmount); if (!canWithdraw) { Console.WriteLine("Cannot withdraw this amount"); } }
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(); } }
public void Test_WithdrawNegative_Failed() { AccountsLib.Account acc = new AccountsLib.Account(3); acc.Deposit(3); try { acc.Withdraw(-2); Assert.Fail(); } catch (Exception e) { Assert.AreEqual("NegativeExc", e.Message); } }
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(); } }