Ejemplo n.º 1
0
        public void Redo()
        {
            var target = new UndoRedoList <int, List <int> > {
                100, 200
            };

            Assert.IsFalse(target.CanRedo);
            Assert.IsFalse(target.Redo());

            target.Undo();
            Assert.IsTrue(target.CanRedo);

            Assert.IsTrue(target.Redo());
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);

            target.Undo();
            Assert.IsTrue(target.CanRedo);
            target.Add(300);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(300, target[1]);
            Assert.IsFalse(target.CanRedo);

            target.RemoveAt(0);
            target.Undo();
            Assert.IsTrue(target.CanRedo);

            Assert.IsTrue(target.Redo());
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(300, target[0]);

            target.Add(500);
            target[target.Count - 1] = 600;
            Assert.AreEqual(2, target.Count);
            target.Undo();
            Assert.IsTrue(target.CanRedo);
            Assert.IsTrue(target.Redo());
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(600, target[target.Count - 1]);

            target.Clear();
            target.Undo();
            Assert.IsTrue(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(600, target[1]);
            Assert.IsTrue(target.Redo());
            Assert.AreEqual(0, target.Count);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
        }
Ejemplo n.º 2
0
        public void AnotherUndoRedoList()
        {
            // List which support undo/redo.
            var target = new UndoRedoList <int>(maximumUndoTimes: 2);

            target.Add(100);
            target.RemoveAt(0);
            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.Undo());
            Assert.IsTrue(target.Redo());
            Assert.IsTrue(target.Redo());
            Assert.IsFalse(target.Redo());
        }
Ejemplo n.º 3
0
        public void UndoRedoTest()
        {
            // list which support undo/redo.
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            // Modify target
            target.Add(100);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            // Undo
            Assert.IsTrue(target.Undo());

            Assert.AreEqual(0, target.Count);
            Assert.IsFalse(target.CanUndo);
            Assert.IsTrue(target.CanRedo);

            // Redo
            Assert.IsTrue(target.Redo());

            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
        }
Ejemplo n.º 4
0
        public void ActionScope()
        {
            var target = new UndoRedoList <int, List <int> > {
                100, 200
            };

            using (var scope = new UndoRedoList <int, List <int> > .ActionScope(target)) {
                target.Add(300);
                target.RemoveAt(0);
                target.RemoveAt(1);
                target.Add(400);
                target.Add(500);
            }
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(200, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);

            Assert.IsTrue(target.Redo());
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(200, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
        }
Ejemplo n.º 5
0
        public void MaximumUndoTimes()
        {
            // List which support undo/redo.
            // maximumUndoTimes is 2.
            var target = new UndoRedoList <int>(maximumUndoTimes: 2);

            // Add an element 3 times.
            target.Add(100);
            target.Add(200);
            target.Add(300);

            // You can undo 2 times.
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.IsTrue(target.Undo());

            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.IsTrue(target.Undo());

            // You can redo 2 times also.
            Assert.IsFalse(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.IsTrue(target.Redo());

            //Assert.IsTrue (target.CanUndo);
            //Assert.IsTrue (target.CanRedo);
            //Assert.IsTrue (target.Redo());

            //Assert.IsTrue (target.CanUndo);
            //Assert.IsFalse(target.CanRedo);
        }
Ejemplo n.º 6
0
        public void TestUndoRedoTwoTimes()
        {
            Action undo = mockRepo.CreateMock <Action>();
            Action redo = mockRepo.CreateMock <Action>();

            Expect.Call(() => undo()).Repeat.Twice();
            Expect.Call(() => redo()).Repeat.Twice();
            mockRepo.ReplayAll();
            UndoRedoList sut = new UndoRedoList();

            sut.Add(undo, redo);
            sut.Undo();
            sut.Redo();
            sut.Undo();
            sut.Redo();
        }
Ejemplo n.º 7
0
        public void TestBasicRedo()
        {
            Action act = mockRepo.CreateMock <Action>();

            act();
            mockRepo.ReplayAll();
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, act);
            sut.Undo();
            sut.Redo();
        }
Ejemplo n.º 8
0
        public void UndoRedoListTest()
        {
            // List which support undo/redo.
            var target = new UndoRedoList <int>();

            target.Add(100);

            // You can undo/redo also.
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.Redo());
        }
Ejemplo n.º 9
0
        static void RemoveTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.RemoveAt(times - count);
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }
Ejemplo n.º 10
0
        static void AddTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.Add(count);
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }
Ejemplo n.º 11
0
        public void TestUndoRedoTwoTimesIsUndoableRedoable()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            Assert.That(sut.IsUndoActive);
            Assert.That(sut.UndoCount, Is.EqualTo(1));
            sut.Undo();
            Assert.That(sut.IsUndoActive, Is.False);
            Assert.That(sut.UndoCount, Is.EqualTo(0));
            Assert.That(sut.IsRedoActive);
            Assert.That(sut.RedoCount, Is.EqualTo(1));
            sut.Redo();
            Assert.That(sut.IsUndoActive);
            Assert.That(sut.UndoCount, Is.EqualTo(1));
            Assert.That(sut.IsRedoActive, Is.False);
            Assert.That(sut.RedoCount, Is.EqualTo(0));
        }
Ejemplo n.º 12
0
        static void ExchangeTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.Add(count);
            }

            for (var count = 1; count <= times; count++)
            {
                list[random.Next(times)] = count;
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }