Пример #1
0
        public void _04_Creer_une_classe_abstraite_CommandBase_avec_une_methode_Do_et_Undo_pour_unifier_SumCommand_et_MultiplyCommand()
        {
            Calculator calculator = new Calculator();

            CommandBase sum = new SumCommand(calculator, 5);

            Assert.NotNull(sum);

            CommandBase multiply = new MultiplyCommand(calculator, 5);

            Assert.NotNull(multiply);
        }
Пример #2
0
        public void _02_Creer_une_classe_SumCommand_avec_une_methode_Do_et_Undo()
        {
            Calculator calculator = new Calculator();

            SumCommand sum = new SumCommand(calculator, 10);

            Assert.Equal(0, calculator.Result);

            sum.Do();

            Assert.Equal(10, calculator.Result);

            sum.Undo();

            Assert.Equal(0, calculator.Result);
        }
Пример #3
0
        public void Compute(char operation, int value)
        {
            CommandBase cmd = null;

            switch (operation)
            {
            case '+':
                cmd = new SumCommand(calculator, value);
                break;

            case '*':
                cmd = new MultiplyCommand(calculator, value);
                break;
            }

            if (cmd != null)
            {
                cmd.Do();
                commands.Push(cmd);
            }
        }
Пример #4
0
        public void _03_Creer_une_classe_MultiplyCommand_avec_une_methode_Do_et_Undo()
        {
            Calculator calculator = new Calculator();

            SumCommand sum = new SumCommand(calculator, 5);

            MultiplyCommand multiply = new MultiplyCommand(calculator, 10);

            Assert.Equal(0, calculator.Result);

            sum.Do();

            Assert.Equal(5, calculator.Result);

            multiply.Do();

            Assert.Equal(50, calculator.Result);

            multiply.Undo();

            Assert.Equal(5, calculator.Result);
        }