public void CanUndoWhenACommandHasBeenExecuted()
        {
            var commandStack = new CommandStack();

            var mockCommand = new Mock<ICommand>();

            commandStack.Execute(mockCommand.Object);

            Assert.IsTrue(commandStack.CanUndo());
        }
        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());
        }
        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));
        }
        public void ExecuteCommandCallsApplyOnTheCommand()
        {
            var mockCommand = new Mock<ICommand>();
            var commandStack = new CommandStack();

            commandStack.Execute(mockCommand.Object);

            mockCommand.Verify(command => command.Apply(), Times.Exactly(1));
        }
        public void CanNotUndoWhenNoCommandsHaveBeenExecuted()
        {
            var commandStack = new CommandStack();

            Assert.IsFalse(commandStack.CanUndo());
        }
        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));
        }