Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 public void TestActionItemsCleared()
 {
     var stack = new ActionStackTestContainer(5);
     stack.Stack.ActionItemsCleared += (sender, e) =>
     {
         var localStack = (ActionStack)sender;
         Assert.AreEqual(false, localStack.CanUndo);
         Assert.AreEqual(false, localStack.CanRedo);
     };
     stack.Stack.AddRange(new[] { new SimpleActionItem(), new SimpleActionItem() });
     stack.Stack.Clear();
     Assert.AreEqual(0, stack.Stack.ActionItems.Count());
     stack.CheckRaiseCount(1, 1, 0, 0, 0);
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 public void TestActionItemsAddedTwoActions()
 {
     var stack = new ActionStackTestContainer(5);
     var actions = new[] { new SimpleActionItem(), new SimpleActionItem() };
     stack.Stack.ActionItemsAdded += (sender, e) =>
     {
         Assert.AreEqual(2, e.ActionItems.Length);
         Assert.AreEqual(actions[0], e.ActionItems.First());
         Assert.AreEqual(actions[1], e.ActionItems.Skip(1).First());
         Assert.IsInstanceOf(typeof(ActionStack), sender);
         var localStack = (ActionStack)sender;
         Assert.AreEqual(true, localStack.CanUndo);
         Assert.AreEqual(false, localStack.CanRedo);
     };
     stack.Stack.AddRange(actions);
     Assert.AreEqual(2, stack.Stack.ActionItems.Count());
     stack.CheckRaiseCount(1, 0, 0, 0, 0);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
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);
 }
Exemplo n.º 12
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);
 }