コード例 #1
0
        public void BankAccountCommand_Withdraw_Once_Undo_Twice()
        {
            var cashToDeposit       = 100;
            var account             = new BankAccount();
            var bankCommand         = new BankAccountCommand(account, TransactionType.WITHDRAW, cashToDeposit);
            var expectedBankBalance = account.Amount;

            bankCommand.Execute();
            bankCommand.Undo();
            bankCommand.Undo();

            Assert.Equal(expectedBankBalance, account.Amount);
        }
コード例 #2
0
        public void Run(string[] args)
        {
            var ba         = new BankAccount();
            var cmdDeposit = new BankAccountCommand(ba,
                                                    BankAccountCommand.Action.Deposit, 100);
            var cmdWithdraw = new BankAccountCommand(ba,
                                                     BankAccountCommand.Action.Withdraw, 1000);

            cmdDeposit.Call();
            cmdWithdraw.Call();
            Console.WriteLine(ba);
            cmdWithdraw.Undo();
            cmdDeposit.Undo();
            Console.WriteLine(ba);


            var from = new BankAccount();

            from.Deposit(100);
            var to = new BankAccount();

            var mtc = new MoneyTransferCommand(from, to, 1000);

            mtc.Call();


            // Deposited $100, balance is now 100
            // balance: 100
            // balance: 0

            Console.WriteLine(from);
            Console.WriteLine(to);
        }
コード例 #3
0
        public void BankAccountCommand_Undo(TransactionType transactionType)
        {
            var cashToWithdraw      = 100;
            var account             = new BankAccount();
            var bankCommand         = new BankAccountCommand(account, transactionType, cashToWithdraw);
            var expectedBankBalance = account.Amount;

            bankCommand.Execute();
            bankCommand.Undo();

            Assert.Equal(expectedBankBalance, account.Amount);
        }
コード例 #4
0
        public void BankAccountCommand_Undo_Many_Transactions()
        {
            var cashToDeposit       = 100;
            var cashToWithdraw      = 50;
            var account             = new BankAccount();
            var depositCommand      = new BankAccountCommand(account, TransactionType.DEPOSIT, cashToDeposit);
            var withdrawCommand     = new BankAccountCommand(account, TransactionType.WITHDRAW, cashToWithdraw);
            var expectedBankBalance = account.Amount;

            depositCommand.Execute();
            withdrawCommand.Execute();
            depositCommand.Undo();
            withdrawCommand.Undo();

            Assert.Equal(expectedBankBalance, account.Amount);
        }