Exemple #1
0
        public void CancelableEventsOnCommandifiedListTests()
        {
            CommandifiedList <int> list = new CommandifiedList <int>()
            {
                1, 2, 3
            };
            EventHandler <CancelableListModificationEventArgs <int> > cancelableHandler = delegate(object sender, CancelableListModificationEventArgs <int> e) { e.Cancel = true; };

            list.ElementAdding   += cancelableHandler;
            list.ElementRemoving += cancelableHandler;
            list.ListClearing    += cancelableHandler;
            // reset command queue manager, so it will only undo commands issued after this reset
            CommandQueueManagerSingleton.GetInstance().ResetActiveCommandQueue();

            list.Add(4);
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(list.Contains(4));
            // undo shouldn't have any effect
            CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(list.Contains(4));

            list.Clear();
            Assert.AreEqual(3, list.Count);
            // undo shouldn't have any effect
            CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
            Assert.AreEqual(3, list.Count);

            list.Remove(1);
            Assert.AreEqual(3, list.Count);
            Assert.IsTrue(list.Contains(1));

            // undo shouldn't have any effect
            CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
            Assert.AreEqual(3, list.Count);
            Assert.IsTrue(list.Contains(1));

            list.ElementAdding   -= cancelableHandler;
            list.ElementRemoving -= cancelableHandler;
            list.ListClearing    -= cancelableHandler;

            list.Add(4);
            Assert.AreEqual(4, list.Count);
            Assert.IsTrue(list.Contains(4));

            list.Remove(1);
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(list.Contains(1));

            list.Clear();
            Assert.AreEqual(0, list.Count);
        }
Exemple #2
0
        public void CommandifiedListRemoveTest()
        {
            Guid sessionId = Guid.NewGuid();

            CQManager.ActivateCommandQueueStack(sessionId);

            CommandifiedList <string> toTest = new CommandifiedList <string>()
            {
                "Foo", "Bar"
            };

            Assert.AreEqual(2, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);
            Assert.AreEqual("Bar", toTest[1]);

            // perform a remove operation. We'll undo this later on.
            toTest.Remove("Foo");
            Assert.AreEqual(1, toTest.Count);
            Assert.AreEqual("Bar", toTest[0]);

            // undo operation.
            CQManager.UndoLastCommand();
            Assert.AreEqual(2, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);
            Assert.AreEqual("Bar", toTest[1]);

            toTest.RemoveAt(1);
            Assert.AreEqual(1, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);

            // undo operation.
            CQManager.UndoLastCommand();
            Assert.AreEqual(2, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);
            Assert.AreEqual("Bar", toTest[1]);

            CQManager.ActivateCommandQueueStack(Guid.Empty);
        }
        public void CommandifiedListRemoveTest()
        {
            Guid sessionId = Guid.NewGuid();
            CQManager.ActivateCommandQueueStack(sessionId);

            CommandifiedList<string> toTest = new CommandifiedList<string>() { "Foo", "Bar" };
            Assert.AreEqual(2, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);
            Assert.AreEqual("Bar", toTest[1]);

            // perform a remove operation. We'll undo this later on.
            toTest.Remove("Foo");
            Assert.AreEqual(1, toTest.Count);
            Assert.AreEqual("Bar", toTest[0]);

            // undo operation.
            CQManager.UndoLastCommand();
            Assert.AreEqual(2, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);
            Assert.AreEqual("Bar", toTest[1]);

            toTest.RemoveAt(1);
            Assert.AreEqual(1, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);

            // undo operation.
            CQManager.UndoLastCommand();
            Assert.AreEqual(2, toTest.Count);
            Assert.AreEqual("Foo", toTest[0]);
            Assert.AreEqual("Bar", toTest[1]);

            CQManager.ActivateCommandQueueStack(Guid.Empty);
        }
        public void CancelableEventsOnCommandifiedListTests()
        {
            CommandifiedList<int> list = new CommandifiedList<int>() { 1, 2, 3 };
            EventHandler<CancelableListModificationEventArgs<int>> cancelableHandler = delegate(object sender, CancelableListModificationEventArgs<int> e) { e.Cancel = true; };
            list.ElementAdding += cancelableHandler;
            list.ElementRemoving += cancelableHandler;
            list.ListClearing += cancelableHandler;
            // reset command queue manager, so it will only undo commands issued after this reset
            CommandQueueManagerSingleton.GetInstance().ResetActiveCommandQueue();

            list.Add(4);
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(list.Contains(4));
            // undo shouldn't have any effect
            CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(list.Contains(4));

            list.Clear();
            Assert.AreEqual(3, list.Count);
            // undo shouldn't have any effect
            CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
            Assert.AreEqual(3, list.Count);

            list.Remove(1);
            Assert.AreEqual(3, list.Count);
            Assert.IsTrue(list.Contains(1));

            // undo shouldn't have any effect
            CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
            Assert.AreEqual(3, list.Count);
            Assert.IsTrue(list.Contains(1));

            list.ElementAdding -= cancelableHandler;
            list.ElementRemoving -= cancelableHandler;
            list.ListClearing -= cancelableHandler;

            list.Add(4);
            Assert.AreEqual(4, list.Count);
            Assert.IsTrue(list.Contains(4));

            list.Remove(1);
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(list.Contains(1));

            list.Clear();
            Assert.AreEqual(0, list.Count);
        }