Example #1
0
        public void NonRepeatableTaskShouldNotBeRepeatable()
        {
            var    task1  = new MockUnit();
            var    target = new UndoService();
            object key    = new object();

            Assert.IsFalse(target.CanRepeat(key));
            target.PerformUnit(task1, "1", key);
            Assert.IsFalse(target.CanRepeat(key));
        }
Example #2
0
        public void NonRepeatableGlobalTaskShouldNotBeRepeatable()
        {
            var    task1  = new MockUnit();
            var    target = new UndoService();
            string arg1   = "1";

            Assert.IsFalse(target.CanRepeat(null));
            target.PerformUnit(task1, arg1, null);
            Assert.IsFalse(target.CanRepeat(null));
        }
Example #3
0
        public void RepeatableTaskShouldBeRepeatable()
        {
            var task1 = new MockUnit {
                RepeatableTest = true
            };
            var    target = new UndoService();
            object key    = new object();

            Assert.IsFalse(target.CanRepeat(key));
            target.PerformUnit(task1, "1", key);
            Assert.IsTrue(target.CanRepeat(key));
            target.Repeat(key);
            Assert.IsTrue(task1.ExecutionCount == 2);
        }
Example #4
0
        public void RepeatableGlobalTaskShouldBeRepeatable()
        {
            var task1 = new MockUnit {
                RepeatableTest = true
            };
            var    target = new UndoService();
            string arg1   = "1";

            Assert.IsFalse(target.CanRepeat(null));
            target.PerformUnit(task1, arg1, null);
            Assert.IsTrue(target.CanRepeat(null));
            target.Repeat(null);
            Assert.IsTrue(task1.ExecutionCount == 2);
        }
Example #5
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);
        }