Esempio n. 1
0
 public void TestConstruction()
 {
     var action = new SimpleActionItem();
     Assert.AreEqual(true, action.IsDone);
     Assert.AreEqual(false, action.IsFrozen);
     Assert.AreEqual(false, action.IsSaved);
 }
Esempio n. 2
0
 public void TestUndo()
 {
     var action = new SimpleActionItem();
     action.Undo();
     Assert.AreEqual(false, action.IsDone);
     Assert.AreEqual(false, action.IsFrozen);
     Assert.AreEqual(false, action.IsSaved);
 }
Esempio n. 3
0
 public void TestAddAction()
 {
     var stack = new ActionStackTestContainer(5);
     var action = new SimpleActionItem();
     stack.Stack.Add(action);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(false, stack.Stack.CanRedo);
     Assert.AreEqual(1, stack.Stack.ActionItems.Count());
     Assert.AreEqual(action, stack.Stack.ActionItems.First());
     stack.CheckRaiseCount(1, 0, 0, 0, 0);
 }
Esempio n. 4
0
 public void TestUndo()
 {
     int orderCheck = 0;
     var action1 = new SimpleActionItem(); action1.OnUndo += () => { Assert.AreEqual(2, orderCheck); orderCheck++; };
     var action2 = new SimpleActionItem(); action2.OnUndo += () => { Assert.AreEqual(1, orderCheck); orderCheck++; };
     var action3 = new SimpleActionItem(); action3.OnUndo += () => { Assert.AreEqual(0, orderCheck); orderCheck++; };
     var action = new AggregateActionItem("Test", action1, new AggregateActionItem("Test", action2, action3));
     action.Undo();
     Assert.AreEqual(false, action.IsDone);
     Assert.AreEqual(false, action1.IsDone);
     Assert.AreEqual(false, action2.IsDone);
     Assert.AreEqual(false, action3.IsDone);
 }
Esempio n. 5
0
 public void TestConstruction()
 {
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     var action3 = new SimpleActionItem();
     var action = new AggregateActionItem("Test", action1, new AggregateActionItem("Test", action2, action3));
     var inner = action.GetInnerActionItems().ToList();
     Assert.AreEqual(2, action.ActionItems.Count);
     Assert.AreEqual(5, inner.Count);
     Assert.AreEqual(true, action.ContainsAction(action1));
     Assert.AreEqual(true, action.ContainsAction(action2));
     Assert.Contains(action1, inner);
     Assert.Contains(action2, inner);
     Assert.Contains(action3, inner);
 }
Esempio n. 6
0
 public void TestActionItemsAddedOneAction()
 {
     var stack = new ActionStackTestContainer(5);
     var action = new SimpleActionItem();
     stack.Stack.ActionItemsAdded += (sender, e) =>
     {
         Assert.AreEqual(1, e.ActionItems.Length);
         Assert.AreEqual(action, e.ActionItems.First());
         Assert.IsInstanceOf(typeof(ActionStack), sender);
         var localStack = (ActionStack)sender;
         Assert.AreEqual(true, localStack.CanUndo);
         Assert.AreEqual(false, localStack.CanRedo);
     };
     stack.Stack.Add(action);
     Assert.AreEqual(1, stack.Stack.ActionItems.Count());
     stack.CheckRaiseCount(1, 0, 0, 0, 0);
 }
 public void TestBeginCancel()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     stack.Stack.BeginTransaction();
     int orderCheck = 0;
     var action1 = new SimpleActionItem(); action1.OnUndo += () => { Assert.AreEqual(2, orderCheck); orderCheck++; };
     var action2 = new SimpleActionItem(); action2.OnUndo += () => { Assert.AreEqual(1, orderCheck); orderCheck++; };
     var action3 = new SimpleActionItem(); action3.OnUndo += () => { Assert.AreEqual(0, orderCheck); orderCheck++; };
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     stack.Stack.Add(action3);
     var current = stack.Stack.GetCurrentTransactions();
     Assert.AreEqual(3, current.Count);
     stack.Stack.CancelTransaction();
     Assert.AreEqual(3, orderCheck);
     Assert.Throws<InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
     stack.CheckRaiseCount(0, 0, 0, 0, 0);
     stack.CheckTransactionCount(1, 0, 1, 0);
 }
Esempio n. 8
0
 public void TestSavePointEquity()
 {
     // Completely undo the stack
     var stack = new ActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     stack.Stack.Add(action1);
     var savePoint1 = stack.Stack.CreateSavePoint(false);
     var savePoint2 = stack.Stack.CreateSavePoint(true);
     Assert.AreEqual(savePoint1, savePoint2);
 }
Esempio n. 9
0
 public void TestSavePoint()
 {
     // Completely undo the stack
     var stack = new ActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     stack.Stack.Add(action1);
     var savePoint = stack.Stack.CreateSavePoint(true);
     stack.Stack.Add(action2);
     Assert.AreEqual(action1.Identifier, savePoint.ActionItemIdentifier);
     Assert.AreEqual(true, action1.IsSaved);
     Assert.AreEqual(false, action2.IsSaved);
 }
Esempio n. 10
0
 public void TestRedoEvent()
 {
     var stack = new ActionStackTestContainer(5);
     var action = new SimpleActionItem();
     stack.Stack.Redone += (sender, e) =>
     {
         Assert.AreEqual(1, e.ActionItems.Length);
         Assert.AreEqual(action, e.ActionItems.First());
         Assert.IsInstanceOf(typeof(ActionStack), sender);
         var localStack = (ActionStack)sender;
         var localAction = e.ActionItems.First();
         Assert.AreEqual(true, localAction.IsDone);
         Assert.AreEqual(false, localAction.IsFrozen);
         Assert.AreEqual(false, localAction.IsSaved);
         Assert.AreEqual(true, localStack.CanUndo);
         Assert.AreEqual(false, localStack.CanRedo);
     };
     stack.Stack.Add(action);
     stack.Stack.Undo();
     stack.Stack.Redo();
     stack.CheckRaiseCount(1, 0, 0, 1, 1);
 }
Esempio n. 11
0
 public void TestSwallowEvent()
 {
     // Completely undo the stack
     var stack = new ActionStackTestContainer(1);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     stack.Stack.ActionItemsDiscarded += (sender, e) =>
     {
         Assert.AreEqual(ActionItemDiscardType.Swallowed, e.Type);
         Assert.AreEqual(1, e.ActionItems.Length);
         Assert.AreEqual(action1, e.ActionItems.First());
         Assert.IsInstanceOf(typeof(ActionStack), sender);
         var localStack = (ActionStack)sender;
         Assert.AreEqual(1, localStack.ActionItems.Count());
     };
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     stack.CheckRaiseCount(2, 0, 1, 0, 0);
 }
Esempio n. 12
0
 public void TestDisbranchActions2()
 {
     // Completely undo the stack
     var stack = new ActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     var action3 = new SimpleActionItem();
     var action4 = new SimpleActionItem();
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     stack.Stack.Undo();
     stack.Stack.Undo();
     stack.Stack.Add(action3);
     stack.Stack.Add(action4);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(false, stack.Stack.CanRedo);
     Assert.AreEqual(2, stack.Stack.ActionItems.Count());
     Assert.AreEqual(action3, stack.Stack.ActionItems.First());
     Assert.AreEqual(action4, stack.Stack.ActionItems.Skip(1).First());
     stack.CheckRaiseCount(4, 0, 1, 2, 0);
 }
Esempio n. 13
0
 public void TestSwallowAndUndoActions()
 {
     var stack = new ActionStackTestContainer(2);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     var action3 = new SimpleActionItem();
     var action4 = new SimpleActionItem();
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     stack.Stack.Add(action3);
     stack.CheckRaiseCount(3, 0, 1, 0, 0);
     stack.Stack.Undo();
     stack.Stack.Add(action4);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(false, stack.Stack.CanRedo);
     Assert.AreEqual(2, stack.Stack.ActionItems.Count());
     Assert.AreEqual(action2, stack.Stack.ActionItems.First());
     Assert.AreEqual(action4, stack.Stack.ActionItems.Skip(1).First());
     stack.CheckRaiseCount(4, 0, 2, 1, 0);
 }
Esempio n. 14
0
 public void TestAddTwoActionsAndUndoRedo()
 {
     var stack = new ActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     stack.Stack.Undo();
     Assert.AreEqual(true, action1.IsDone);
     Assert.AreEqual(false, action1.IsFrozen);
     Assert.AreEqual(false, action1.IsSaved);
     Assert.AreEqual(false, action2.IsDone);
     Assert.AreEqual(false, action2.IsFrozen);
     Assert.AreEqual(false, action2.IsSaved);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(true, stack.Stack.CanRedo);
     stack.Stack.Undo();
     Assert.AreEqual(false, action1.IsDone);
     Assert.AreEqual(false, action1.IsFrozen);
     Assert.AreEqual(false, action1.IsSaved);
     Assert.AreEqual(false, action2.IsDone);
     Assert.AreEqual(false, action2.IsFrozen);
     Assert.AreEqual(false, action2.IsSaved);
     Assert.AreEqual(false, stack.Stack.CanUndo);
     Assert.AreEqual(true, stack.Stack.CanRedo);
     stack.Stack.Redo();
     Assert.AreEqual(true, action1.IsDone);
     Assert.AreEqual(false, action1.IsFrozen);
     Assert.AreEqual(false, action1.IsSaved);
     Assert.AreEqual(false, action2.IsDone);
     Assert.AreEqual(false, action2.IsFrozen);
     Assert.AreEqual(false, action2.IsSaved);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(true, stack.Stack.CanRedo);
     stack.Stack.Redo();
     Assert.AreEqual(true, action1.IsDone);
     Assert.AreEqual(false, action1.IsFrozen);
     Assert.AreEqual(false, action1.IsSaved);
     Assert.AreEqual(true, action2.IsDone);
     Assert.AreEqual(false, action2.IsFrozen);
     Assert.AreEqual(false, action2.IsSaved);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(false, stack.Stack.CanRedo);
     stack.CheckRaiseCount(2, 0, 0, 2, 2);
 }
Esempio n. 15
0
 public void TestAddTwoActions()
 {
     var stack = new ActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(false, stack.Stack.CanRedo);
     Assert.AreEqual(2, stack.Stack.ActionItems.Count());
     Assert.AreEqual(action1, stack.Stack.ActionItems.First());
     Assert.AreEqual(action2, stack.Stack.ActionItems.Skip(1).First());
     stack.CheckRaiseCount(2, 0, 0, 0, 0);
 }
 public void TestDiscardEvent()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     var action2 = new SimpleActionItem();
     stack.Stack.TransactionEnded += (sender, e) =>
     {
         Assert.IsInstanceOf(typeof(TransactionalActionStack), sender);
         var localStack = (TransactionalActionStack)sender;
         Assert.AreEqual(2, e.ActionItems.Length);
         Assert.AreEqual(action1, e.ActionItems.First());
         Assert.AreEqual(action2, e.ActionItems.Skip(1).First());
         Assert.DoesNotThrow(() => localStack.GetCurrentTransactions());
         Assert.Throws<InvalidOperationException>(() => localStack.GetCurrentTransactions());
     };
     stack.Stack.BeginTransaction();
     stack.Stack.Add(action1);
     stack.Stack.Add(action2);
     stack.Stack.DiscardTransaction();
     stack.CheckTransactionCount(1, 0, 0, 1);
 }
Esempio n. 17
0
 public void TestUndoRedoInProgressEvent()
 {
     // Completely undo the stack
     var stack = new ActionStackTestContainer(5);
     var action1 = new SimpleActionItem();
     var action2 = new AnonymousActionItem("test", Enumerable.Empty<IDirtiable>(), () => stack.Stack.Add(action1), () => { });
     stack.Stack.ActionItemsDiscarded += (sender, e) =>
     {
         Assert.AreEqual(ActionItemDiscardType.UndoRedoInProgress, e.Type);
         Assert.AreEqual(1, e.ActionItems.Length);
         Assert.AreEqual(action1, e.ActionItems.First());
         Assert.IsInstanceOf(typeof(ActionStack), sender);
         var localStack = (ActionStack)sender;
         var localAction = e.ActionItems.First();
         Assert.AreEqual(1, localStack.ActionItems.Count());
         Assert.AreEqual(action1, localAction);
     };
     stack.Stack.Add(action2);
     stack.Stack.Undo();
     stack.CheckRaiseCount(1, 0, 1, 1, 0);
 }
Esempio n. 18
0
 public void TestRedo()
 {
     var stack = new ActionStackTestContainer(5);
     var action = new SimpleActionItem();
     stack.Stack.Add(action);
     stack.Stack.Undo();
     stack.Stack.Redo();
     Assert.AreEqual(true, action.IsDone);
     Assert.AreEqual(false, action.IsFrozen);
     Assert.AreEqual(false, action.IsSaved);
     Assert.AreEqual(true, stack.Stack.CanUndo);
     Assert.AreEqual(false, stack.Stack.CanRedo);
     Assert.AreEqual(1, stack.Stack.ActionItems.Count());
     Assert.AreEqual(action, stack.Stack.ActionItems.First());
     stack.CheckRaiseCount(1, 0, 0, 1, 1);
 }