Ejemplo n.º 1
0
        public void CanNotRedoWhenACommandIsUndoneThenAnotherCommandIsExecuted()
        {
            var commandStack = new CommandStack();

            var mockCommand = new Mock<ICommand>();
            var mockCommand2 = new Mock<ICommand>();

            commandStack.Execute(mockCommand.Object);
            commandStack.Undo();
            commandStack.Execute(mockCommand2.Object);

            Assert.IsFalse(commandStack.CanRedo());
        }
Ejemplo n.º 2
0
        public void ExecuteACommandUndoExecuteACommandThenRedoDoesNotCallApplyOnSecondCommand()
        {
            var commandStack = new CommandStack();

            var mockCommand1 = new Mock<ICommand>();
            var mockCommand2 = new Mock<ICommand>();

            commandStack.Execute(mockCommand1.Object);
            commandStack.Undo();
            commandStack.Execute(mockCommand2.Object);
            commandStack.Redo();

            mockCommand1.Verify(command => command.Apply(), Times.Exactly(1));
            mockCommand1.Verify(command => command.Revert(), Times.Exactly(1));
            mockCommand2.Verify(command => command.Apply(), Times.Exactly(1));
            mockCommand2.Verify(command => command.Revert(), Times.Exactly(0));
        }
Ejemplo n.º 3
0
        public void CanUndoWhenACommandHasBeenExecuted()
        {
            var commandStack = new CommandStack();

            var mockCommand = new Mock<ICommand>();

            commandStack.Execute(mockCommand.Object);

            Assert.IsTrue(commandStack.CanUndo());
        }
Ejemplo n.º 4
0
        public void ExecuteCommandCallsApplyOnTheCommand()
        {
            var mockCommand = new Mock<ICommand>();
            var commandStack = new CommandStack();

            commandStack.Execute(mockCommand.Object);

            mockCommand.Verify(command => command.Apply(), Times.Exactly(1));
        }
Ejemplo n.º 5
0
        public void UndoCallsRevertOnTheLastCommandExecuted()
        {
            var commandStack = new CommandStack();

            var mockCommand1 = new Mock<ICommand>();
            var mockCommand2 = new Mock<ICommand>();

            commandStack.Execute(mockCommand1.Object);
            commandStack.Execute(mockCommand2.Object);

            commandStack.Undo();

            mockCommand1.Verify(command => command.Apply(), Times.Exactly(1));
            mockCommand1.Verify(command => command.Revert(), Times.Exactly(0));
            mockCommand2.Verify(command => command.Apply(), Times.Exactly(1));
            mockCommand2.Verify(command => command.Revert(), Times.Exactly(1));
        }