Exemple #1
0
        void CompositeUndoableTasksShouldBePerformedInParallel(object contextKey)
        {
            var tasks = new Dictionary <UndoableUnitBase <string>, string>();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(new MockUndoableUnit(), i.ToString());
            }
            var compositeTask = new CompositeUndoableUnit <string>(tasks, "1")
            {
                Parallel = true
            };
            var target = new UndoService();

            target.PerformUnit(compositeTask, null, contextKey);
            foreach (KeyValuePair <UndoableUnitBase <string>, string> keyValuePair in tasks)
            {
                var mockTask = (MockUndoableUnit)keyValuePair.Key;
                Assert.AreEqual(1, mockTask.ExecutionCount);
            }

            /* Test undo. */
            target.Undo(contextKey);

            foreach (KeyValuePair <UndoableUnitBase <string>, string> keyValuePair in tasks)
            {
                var mockTask = (MockUndoableUnit)keyValuePair.Key;
                Assert.AreEqual(0, mockTask.ExecutionCount);
            }
        }
Exemple #2
0
        void UndoableTaskShouldBeRedoable(object key)
        {
            var task1  = new MockUndoableUnit();
            var target = new UndoService();

            Assert.IsFalse(target.CanRedo(key));
            target.PerformUnit(task1, "1", key);
            target.Undo(key);
            Assert.IsTrue(target.CanRedo(key));
        }
Exemple #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);
        }