Beispiel #1
0
        public void TestNestedBeginCancelEnd()
        {
            var stack      = new TransactionalActionStackTestContainer(5);
            int orderCheck = 0;

            stack.Stack.BeginTransaction();
            stack.Stack.Add(new SimpleActionItem());
            stack.Stack.BeginTransaction();
            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();
            stack.CheckRaiseCount(0, 0, 0, 0, 0);
            stack.CheckTransactionCount(2, 0, 1, 0);
            stack.Stack.Add(new SimpleActionItem());
            current = stack.Stack.GetCurrentTransactions();
            Assert.AreEqual(2, current.Count);
            stack.Stack.EndTransaction("Test");
            Assert.AreEqual(3, orderCheck);
            Assert.Throws <InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
            stack.CheckRaiseCount(1, 0, 0, 0, 0);
            stack.CheckTransactionCount(2, 1, 1, 0);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void TestNestedBeginEnd()
        {
            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());
            var current = stack.Stack.GetCurrentTransactions();

            Assert.AreEqual(2, current.Count);
            stack.Stack.EndTransaction("Test");
            stack.CheckRaiseCount(0, 0, 0, 0, 0);
            stack.CheckTransactionCount(2, 1, 0, 0);
            stack.Stack.Add(new SimpleActionItem());
            current = stack.Stack.GetCurrentTransactions();
            Assert.AreEqual(3, current.Count);
            stack.Stack.EndTransaction("Test");
            Assert.Throws <InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
            stack.CheckRaiseCount(1, 0, 0, 0, 0);
            stack.CheckTransactionCount(2, 2, 0, 0);
        }
Beispiel #4
0
        public void TestUsingBeginDiscard()
        {
            var stack      = new TransactionalActionStackTestContainer(5);
            int orderCheck = 0;

            using (stack.Stack.BeginDiscardTransaction())
            {
                var action1 = new SimpleActionItem(); action1.OnUndo += () => { orderCheck++; };
                var action2 = new SimpleActionItem(); action2.OnUndo += () => { orderCheck++; };
                var action3 = new SimpleActionItem(); action3.OnUndo += () => { orderCheck++; };
                stack.Stack.Add(action1);
                stack.Stack.Add(action2);
                stack.Stack.Add(action3);
                var current = stack.Stack.GetCurrentTransactions();
                Assert.AreEqual(3, current.Count);
            }
            Assert.AreEqual(0, orderCheck);
            Assert.Throws <InvalidOperationException>(() => stack.Stack.GetCurrentTransactions());
            stack.CheckRaiseCount(0, 0, 0, 0, 0);
            stack.CheckTransactionCount(1, 0, 0, 1);
        }