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_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 static void TransferToAccount(Account fromAccount, Account toAccount) { if (toAccount == null) { Console.WriteLine("There is no second account"); return; } var transferAmount = GetAmountFromUser("Enter the amount to transfer: "); var canTransfer = fromAccount.Transfer(toAccount, transferAmount); if (!canTransfer) { Console.WriteLine("Cannot transfer this amount"); } }
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(); } }
private static void MakeTransferAttempt(Account fromAccount, Account toAccount) { var transferAmount = GetAmountFromUser("Enter the amount to transfer: "); fromAccount.Transfer(toAccount, transferAmount); MessagesPrinter.SuccessMessage("Amount transfered successfully"); }