public void Undo_TransferSmallerAmountThanBalance_ValidateToBalance() { var from = new BankAccount(); from.Deposit(100); var to = new BankAccount(); var mtc = new MoneyTransferCommand(from, to, 70); mtc.Call(); mtc.Undo(); Assert.That(to.Balance, Is.EqualTo(0)); }
public static void Test() { // var ba = new BankAccount(); // var deposit = new BankAccountCommand(ba, BankAccountCommand.Action.Deposit, 100); // var withdraw = new BankAccountCommand(ba, BankAccountCommand.Action.Withdraw, 50); // var composite = new CompositeBankAccountCommand( // new []{deposit, withdraw}); // // composite.Call(); // Console.WriteLine(ba); // // composite.Undo(); // Console.WriteLine(ba); var from = new BankAccount(); from.Deposit(100); // we have deposited 100 dollars to this account var to = new BankAccount(); Console.WriteLine($"making transaction of 100 dollars"); var mtc = new MoneyTransferCommand(from, to, 100); // making a transaction of 100 dollars to another account mtc.Call(); Console.WriteLine(from); // the from account is left with 0 dollars Console.WriteLine(to); // the to account has received the 100 dollars // undoes all successful transactions Console.WriteLine("Undoing previous transaction"); mtc.Undo(); Console.WriteLine(from); Console.WriteLine(to); // Suppose we make a transaction of 1000 dollars while the user from only has 100 dollars in his account // In this case, the Call() of the transaction will catch the error and will fail, undoing the whole // transaction in the process Console.WriteLine($"making transaction of 1000 dollars, which will fail, due to insufficient resources"); var mtc2 = new MoneyTransferCommand(from, to, 1000); mtc2.Call(); Console.WriteLine(from); Console.WriteLine(to); }
public void TestCompositeTransferMoney() { var from = new BankAccount(); from.Deposit(1000); var to = new BankAccount(); var mtc = new MoneyTransferCommand(from, to, 250); mtc.Call(); Console.WriteLine(from); Console.WriteLine(to); mtc.Undo(); Console.WriteLine(from); Console.WriteLine(to); }
static void Main(string[] args) { var from = new BankAccount(); from.Deposit(100); var to = new BankAccount(); var mtc = new MoneyTransferCommand(from, to, 100); mtc.Call(); WriteLine(from); WriteLine(to); mtc.Undo(); WriteLine(from); WriteLine(to); }
public void Test_money_transfer() { var from = new BankAccount(); from.Deposit(100); var to = new BankAccount(); Debug.WriteLine($"From account: {from}"); Debug.WriteLine($"To account: {to}"); var transfer = new MoneyTransferCommand(from, to, 100); transfer.Call(); Debug.WriteLine($"From account: {from}"); Debug.WriteLine($"To account: {to}"); transfer.Undo(); Debug.WriteLine($"From account: {from}"); Debug.WriteLine($"To account: {to}"); Assert.True(transfer.Succeeded); }