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); }