예제 #1
0
        void NonUndoableTasksShouldNotBeUndoable(object key)
        {
            var task1  = new MockUnit();
            var target = new UndoService();

            Assert.IsFalse(target.CanUndo(key));
            target.PerformUnit(task1, "1", key);
            Assert.IsFalse(target.CanUndo(key));
        }
예제 #2
0
        void PerformingTaskShouldClearUndoableList(object key)
        {
            /* First set up some undoable tasks. */
            var task1  = new MockUndoableUnit();
            var target = new UndoService();

            target.PerformUnit(task1, "1", key);
            Assert.IsTrue(target.CanUndo(key));

            /* Perform a non-undoable unit. This must clear the undoable list. */
            var task2 = new MockUnit {
                RepeatableTest = true
            };

            target.PerformUnit(task2, "1", key);
            Assert.IsFalse(target.CanUndo(key));
        }
예제 #3
0
        void TaskServiceShouldUndoTasks(object key)
        {
            var mockTask1 = new MockUndoableUnit {
                RepeatableTest = true
            };
            string expectedValue1 = "1";
            string expectedValue2 = "2";
            var    target         = new UndoService();

            Assert.IsFalse(target.CanUndo(key));
            Assert.IsFalse(target.CanRedo(key));
            Assert.IsFalse(target.CanRepeat(key));

            target.PerformUnit(mockTask1, expectedValue1, key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 1);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsFalse(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Undo(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 0);

            Assert.IsFalse(target.CanUndo(key));
            Assert.IsTrue(target.CanRedo(key));
            Assert.IsFalse(target.CanRepeat(key));

            target.Redo(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 1);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsFalse(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Repeat(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 2);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsFalse(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Repeat(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 3);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsFalse(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Undo(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 2);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsTrue(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Undo(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 1);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsTrue(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Undo(key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 0);

            Assert.IsFalse(target.CanUndo(key));
            Assert.IsTrue(target.CanRedo(key));
            Assert.IsFalse(target.CanRepeat(key));

            var mockTask2 = new MockUndoableUnit {
                RepeatableTest = true
            };

            target.PerformUnit(mockTask1, expectedValue1, key);
            target.PerformUnit(mockTask2, expectedValue2, key);

            Assert.AreEqual(mockTask1.LastArgument, expectedValue1);
            Assert.AreEqual(mockTask1.ExecutionCount, 1);
            Assert.AreEqual(mockTask2.LastArgument, expectedValue2);
            Assert.AreEqual(mockTask2.ExecutionCount, 1);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsFalse(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            target.Undo(key);

            Assert.AreEqual(mockTask1.ExecutionCount, 1);
            Assert.AreEqual(mockTask2.ExecutionCount, 0);

            Assert.IsTrue(target.CanUndo(key));
            Assert.IsTrue(target.CanRedo(key));
            Assert.IsTrue(target.CanRepeat(key));

            var list = target.GetRepeatableUnits(key);

            Assert.IsNotNull(list);
            Assert.IsTrue(list.ToList().Count == 1);
        }