コード例 #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);
        }
コード例 #2
0
        public void CommandifiedListClearTest()
        {
            Guid sessionId = Guid.NewGuid();

            CQManager.ActivateCommandQueueStack(sessionId);

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

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

            // perform a clear operation. We'll undo this later on.
            toTest.Clear();
            Assert.AreEqual(0, toTest.Count);

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

            CQManager.ActivateCommandQueueStack(Guid.Empty);
        }
コード例 #3
0
        public void CommandifiedListClearTest()
        {
            Guid sessionId = Guid.NewGuid();
            CQManager.ActivateCommandQueueStack(sessionId);

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

            // perform a clear operation. We'll undo this later on.
            toTest.Clear();
            Assert.AreEqual(0, toTest.Count);

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

            CQManager.ActivateCommandQueueStack(Guid.Empty);
        }
コード例 #4
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);
        }