Ejemplo n.º 1
0
        public void CanAddComandInHistoryAndExecuteIt()
        {
            TestCommand c       = new TestCommand();
            History     history = new History();

            Assert.IsFalse(c.IsExecuted);
            history.AddAndExecuteCommand(c);
            Assert.IsTrue(c.IsExecuted);
        }
Ejemplo n.º 2
0
        public void CanUndo_WithIndexGreaterThanZero_ShouldReturnTrue()
        {
            var history = new History();
            var text    = new Text();
            var command = new ReplaceTextCommand(text, "text");

            history.AddAndExecuteCommand(command);
            Assert.IsTrue(history.CanUndo());
        }
Ejemplo n.º 3
0
        public void CanRedoCommand()
        {
            TestCommand c       = new TestCommand();
            History     history = new History();

            Assert.IsFalse(c.IsExecuted);
            history.AddAndExecuteCommand(c);
            Assert.IsTrue(c.IsExecuted);
            history.Undo();
            Assert.IsFalse(c.IsExecuted);
        }
Ejemplo n.º 4
0
        public void Redo_WithValidIndex_ShouldRedoCommand()
        {
            var history = new History();
            var text    = new Text();
            var command = new ReplaceTextCommand(text, "text");

            history.AddAndExecuteCommand(command);
            history.Undo();
            Assert.IsTrue(history.CanRedo());
            history.Redo();
        }
Ejemplo n.º 5
0
        public void DeletesAllCommandsUpToCurrentCommandWhenInsertsNewCommand()
        {
            TestCommand c1      = new TestCommand();
            TestCommand c2      = new TestCommand();
            TestCommand c3      = new TestCommand();
            TestCommand c4      = new TestCommand();
            TestCommand cNew2   = new TestCommand();
            History     history = new History();

            history.AddAndExecuteCommand(c1);
            history.AddAndExecuteCommand(c2);
            history.AddAndExecuteCommand(c3);
            history.AddAndExecuteCommand(c4);

            history.Undo();
            history.Undo();
            history.AddAndExecuteCommand(cNew2);
            Assert.IsTrue(c3.IsDeleted);
            Assert.IsTrue(c4.IsDeleted);
            Assert.IsTrue(cNew2.IsExecuted);
        }
Ejemplo n.º 6
0
        public void AddAndExecuteCommand_With_ShouldRemoveFirstCommand()
        {
            var history   = new History();
            var items     = new List <DocumentItem>();
            var paragraph = new Paragraph(history, "text");
            var command1  = new InsertParagraphCommand(items, paragraph, 0);
            var command2  = new InsertParagraphCommand(items, paragraph, 1);
            var command3  = new InsertParagraphCommand(items, paragraph, 1);
            var command4  = new InsertParagraphCommand(items, paragraph, 2);

            history.AddAndExecuteCommand(command1);
            history.AddAndExecuteCommand(command2);
            history.AddAndExecuteCommand(command3);
            history.AddAndExecuteCommand(command4);
            history.Undo();
            history.Undo();
            history.Undo();
            history.AddAndExecuteCommand(command2);
            history.AddAndExecuteCommand(command3);
        }
Ejemplo n.º 7
0
        public void DeleteFirstCommandIfCommandMoreThan10()
        {
            History     history = new History();
            TestCommand c1      = new TestCommand();
            TestCommand c2      = new TestCommand();
            TestCommand c3      = new TestCommand();
            TestCommand c4      = new TestCommand();
            TestCommand c5      = new TestCommand();
            TestCommand c6      = new TestCommand();
            TestCommand c7      = new TestCommand();
            TestCommand c8      = new TestCommand();
            TestCommand c9      = new TestCommand();
            TestCommand c10     = new TestCommand();
            TestCommand c11     = new TestCommand();

            history.AddAndExecuteCommand(c1);
            history.AddAndExecuteCommand(c2);
            history.AddAndExecuteCommand(c3);
            history.AddAndExecuteCommand(c4);
            history.AddAndExecuteCommand(c5);
            history.AddAndExecuteCommand(c6);
            history.AddAndExecuteCommand(c7);
            history.AddAndExecuteCommand(c8);
            history.AddAndExecuteCommand(c9);
            history.AddAndExecuteCommand(c10);
            history.AddAndExecuteCommand(c11);

            while (history.CanUndo())
            {
                history.Undo();
            }

            Assert.IsTrue(c1.IsExecuted);
            Assert.IsFalse(c11.IsExecuted);
        }
Ejemplo n.º 8
0
 public void SetTitle(string title)
 {
     _history.AddAndExecuteCommand(new ReplaceTextCommand(_title, title));
 }
Ejemplo n.º 9
0
        public void AddAndExecuteCommand_WithElevenCommands_ShouldRemoveFirstCommand()
        {
            var history = new History();
            var text    = new Text();
            var command = new ReplaceTextCommand(text, "text");

            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
            history.AddAndExecuteCommand(command);
        }