Exemple #1
0
        public void TestCompositeCommand()
        {
            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);
        }
Exemple #2
0
        public void Undo_CreateAFewFailedCommandsAndCall_SetsCorrectBalance()
        {
            var ba       = new BankAccount();
            var commands = new List <BankAccountCommand>()
            {
                new BankAccountCommand(ba, BankAccountCommand.Action.Deposit, 100),
                new BankAccountCommand(ba, BankAccountCommand.Action.Withdraw, 20),
                new BankAccountCommand(ba, BankAccountCommand.Action.Withdraw, 1000)
            };
            var composite = new CompositeBankAccountCommand(commands);

            composite.Call();
            composite.Undo();

            Assert.That(ba.Balance, Is.EqualTo(0));
        }