public void TestEmptyTransaction()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     stack.Stack.BeginTransaction();
     var current = stack.Stack.GetCurrentTransactions();
     Assert.AreEqual(0, current.Count);
     stack.Stack.EndTransaction("Test");
     Assert.Throws<InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
     stack.CheckRaiseCount(0, 0, 0, 0, 0);
     stack.CheckTransactionCount(1, 0, 0, 1);
 }
 public void TestExceptions()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     Assert.Throws<InvalidOperationException>(() => stack.Stack.EndTransaction(""));
     Assert.Throws<InvalidOperationException>(() => stack.Stack.DiscardTransaction());
     Assert.Throws<InvalidOperationException>(() => stack.Stack.CancelTransaction());
     stack.Stack.BeginTransaction();
     Assert.DoesNotThrow(() => stack.Stack.EndTransaction(""));
     stack.Stack.BeginTransaction();
     Assert.DoesNotThrow(() => stack.Stack.DiscardTransaction());
     stack.Stack.BeginTransaction();
     Assert.DoesNotThrow(() => stack.Stack.CancelTransaction());
 }
 public void TestUsingBeginEnd()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     using (stack.Stack.BeginEndTransaction("Test"))
     {
         stack.Stack.Add(new SimpleActionItem());
         stack.Stack.Add(new SimpleActionItem());
         stack.Stack.Add(new SimpleActionItem());
         var current = stack.Stack.GetCurrentTransactions();
         Assert.AreEqual(3, current.Count);
     }
     Assert.Throws<InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
     stack.CheckRaiseCount(1, 0, 0, 0, 0);
     stack.CheckTransactionCount(1, 1, 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);
 }
 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);
 }
 public void TestBeginEvent()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     stack.Stack.TransactionStarted += (sender, e) =>
     {
         Assert.IsInstanceOf(typeof(TransactionalActionStack), sender);
         var localStack = (TransactionalActionStack)sender;
         Assert.DoesNotThrow(() => localStack.GetCurrentTransactions());
         var current = localStack.GetCurrentTransactions();
         Assert.AreEqual(0, current.Count);
     };
     stack.Stack.BeginTransaction();
     stack.CheckTransactionCount(1, 0, 0, 0);
 }
 public void TestNestedBeginDiscardEnd()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     stack.Stack.BeginTransaction();
     stack.Stack.Add(new SimpleActionItem());
     stack.Stack.BeginTransaction();
     stack.Stack.Add(new SimpleActionItem());
     stack.Stack.Add(new SimpleActionItem());
     stack.Stack.Add(new SimpleActionItem());
     var current = stack.Stack.GetCurrentTransactions();
     Assert.AreEqual(3, current.Count);
     stack.Stack.DiscardTransaction();
     stack.CheckRaiseCount(0, 0, 0, 0, 0);
     stack.CheckTransactionCount(2, 0, 0, 1);
     stack.Stack.Add(new SimpleActionItem());
     current = stack.Stack.GetCurrentTransactions();
     Assert.AreEqual(2, current.Count);
     stack.Stack.EndTransaction("Test");
     Assert.Throws<InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
     stack.CheckRaiseCount(1, 0, 0, 0, 0);
     stack.CheckTransactionCount(2, 1, 0, 1);
 }
 public void TestConstruction()
 {
     var stack = new TransactionalActionStackTestContainer(5);
     Assert.AreEqual(false, stack.Stack.TransactionInProgress);
     Assert.AreEqual(0, stack.Stack.ActionItems.Count());
 }