Ejemplo n.º 1
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.º 2
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.º 3
0
        public void ActionScopeTest()
        {
            // list which support undo/redo.
            var target = new UndoRedoList <int, List <int> >();

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

            // ActionScope
            using (var scope = new UndoRedoList <int, List <int> > .ActionScope(target)) {
                // Modify target in ActionScope
                target.Add(100);
                target.Add(200);
                target.Add(300);
            }

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

            // Undo
            Assert.IsTrue(target.Undo());
            // The 3 actions in ActionScope can undo in one time.
            Assert.AreEqual(0, target.Count);
            Assert.IsFalse(target.CanUndo);
        }
Ejemplo n.º 4
0
        public void Undo()
        {
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.Undo());

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

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

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

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

            target.Add(300);
            Assert.IsTrue(target.CanUndo);
            target.Add(400);
            target.RemoveAt(0);
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(400, target[0]);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(400, target[1]);

            target.Add(500);
            target[target.Count - 1] = 600;
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(600, target[target.Count - 1]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(500, target[target.Count - 1]);

            target.Clear();
            Assert.AreEqual(0, target.Count);
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
        }
Ejemplo n.º 5
0
        public void TestRedoListCount()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            sut.Add(NoAction, NoAction);
            sut.Add(NoAction, NoAction);
            sut.Undo();
            sut.Undo();
            Assert.That(sut.RedoCount, Is.EqualTo(2));
        }
Ejemplo n.º 6
0
        public void TestRedoable()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            Assert.That(sut.IsRedoActive, Is.False);
        }
Ejemplo n.º 7
0
        public void TestUndoable()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, null);
            Assert.That(sut.IsUndoActive);
        }
Ejemplo n.º 8
0
        public void TestBasicListAction()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(null, null);
            Assert.That(sut.UndoCount, Is.EqualTo(1));
        }
Ejemplo n.º 9
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.º 10
0
        public void DisabledUndoScope()
        {
            var target = new UndoRedoList <int, List <int> > {
                100
            };

            Assert.IsTrue(target.CanUndo);

            using (var scope = new UndoRedoList <int, List <int> > .DisabledUndoScope(target))
                target.Add(200);

            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.CanUndo);
            target.Add(300);
            Assert.IsTrue(target.CanUndo);
        }
Ejemplo n.º 11
0
        public void TestRedoableWhenUndo()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add(NoAction, NoAction);
            sut.Undo();
            Assert.That(sut.IsRedoActive, Is.True);
        }
Ejemplo n.º 12
0
        public void TestNameList()
        {
            UndoRedoList sut = new UndoRedoList();

            sut.Add("ActionName", NoAction, NoAction);
            Assert.That(sut.ActionList.Count(), Is.EqualTo(1));
            Assert.That(sut.ActionList.First(), Is.EqualTo("ActionName"));
        }
Ejemplo n.º 13
0
        public void AddRemove()
        {
            var list = new UndoRedoList<int>();
            // Add
            UndoRedoManager.Start("");
            list.Add(1);
            UndoRedoManager.Commit();

            Assert.AreEqual(1, list[0]);
            Assert.AreEqual(1, list.Count);
            // AddRange
            UndoRedoManager.Start("");
            list.AddRange(new int[] { 2, 3, 4, 5, 6});
            UndoRedoManager.Commit();

            Assert.AreEqual(6, list.Count);
            // RemoveRange
            UndoRedoManager.Start("");
            list.RemoveRange(4, 2);
            UndoRedoManager.Commit();

            // RemoveAt
            UndoRedoManager.Start("");
            list.RemoveAt(0);
            UndoRedoManager.Commit();

            // Remove
            UndoRedoManager.Start("");
            list.Remove(2);
            UndoRedoManager.Commit();

            Assert.AreEqual(3, list[0]);
            Assert.AreEqual(4, list[1]);
            Assert.AreEqual(2, list.Count);

            UndoRedoManager.Undo();
            UndoRedoManager.Undo();
            UndoRedoManager.Undo();
            Assert.AreEqual(6, list.Count);

            UndoRedoManager.Undo(); // undo AddRange
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Undo(); // undo Add
            Assert.AreEqual(0, list.Count);

            UndoRedoManager.Redo(); // redo Add
            UndoRedoManager.Redo(); // redo AddRange
            Assert.AreEqual(6, list.Count);
            Assert.IsTrue(list[0] == 1 && list[1] == 2 && list[2] == 3 && list[3] == 4 && list[4] == 5 && list[5] == 6);

            UndoRedoManager.Redo(); // redo RemoveRange
            UndoRedoManager.Redo(); // redo RemoveAt
            UndoRedoManager.Redo(); // redo Remove
            Assert.AreEqual(2, list.Count);
        }
Ejemplo n.º 14
0
        public void TestBasicUndo()
        {
            Action act = mockRepo.CreateMock <Action>();

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

            sut.Add(act, null);
            sut.Undo();
        }
Ejemplo n.º 15
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.º 16
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.º 17
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.º 18
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.º 19
0
        public void DisabledUndoScopeTest()
        {
            // list which support undo/redo.
            var target = new UndoRedoList <int, List <int> >();

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

            // DisabledUndoScope
            using (var scope = new UndoRedoList <int, List <int> > .DisabledUndoScope(target)) {
                // Modify target in DisabledUndoScope
                target.Add(100);
            }

            // You can't undo actions in DisabledUndoScope.
            Assert.IsFalse(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
        }
Ejemplo n.º 20
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.º 21
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();
            }
        }
Ejemplo n.º 22
0
 public GroupFigure(IList<Figure> figs)
 {
     System.Diagnostics.Debug.Assert(figs != null, "figs is not assigned");
     // make new figure list
     childFigs = new UndoRedoList<Figure>();
     foreach (Figure f in figs)
         childFigs.Add(f);
     // store starting dimensions for scaling later on
     CreateOriginalRects();
     // use individual alpha for each child
     UseRealAlpha = false;
 }
Ejemplo n.º 23
0
        public void ManualCancel()
        {
            var i = new UndoRedo<int>(0);
            var list = new UndoRedoList<int>(new int[] {1, 2, 3});
            var dict = new UndoRedoDictionary<int, string>();

            UndoRedoManager.Start("");
            i.Value = 1;
            list.Add(4);
            dict[1] = "One";
            UndoRedoManager.Cancel();

            Assert.AreEqual(0, i.Value);
            Assert.AreEqual(3, list.Count);
            Assert.IsFalse(dict.ContainsKey(1));

            // run next command to make sure that framework works well after cancel
            UndoRedoManager.Start("");
            i.Value = 1;
            UndoRedoManager.Commit();

            Assert.AreEqual(1, i.Value);
        }
Ejemplo n.º 24
0
        public void Clear()
        {
            var list = new UndoRedoList<int>(new int[] {1, 2, 3});
            Assert.AreEqual(3, list.Count);
            // clear
            UndoRedoManager.Start("");
            list.Clear();
            UndoRedoManager.Commit();
            Assert.AreEqual(0, list.Count);
            // add
            UndoRedoManager.Start("");
            list.Add(1);
            UndoRedoManager.Commit();
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Undo(); // undo add
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Undo(); // undo clear
            Assert.AreEqual(3, list.Count);

            UndoRedoManager.Redo(); // redo clear
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Redo(); // redo add
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Start("");
            list.Add(1);
            list.Add(2);
            Assert.AreEqual(3, list.Count);
            list.Clear();
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Commit();

            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Undo(); // undo
            Assert.AreEqual(1, list.Count);
        }
Ejemplo n.º 25
0
        public void RevertToConcrete()
        {
            _building = true;
            _dontCache = true;

            Layers = new UndoRedoList<EditorTileLayer>();

            Width = ConcreteWidth;
            Height = ConcreteHeight;

            foreach (var layer in ConcreteLayers)
            {
                var newLayer = new EditorTileLayer(layer.Name, layer.Opacity, layer.Visible)
                {
                    Tiles = new EditorTile[Width,Height],
                    Sprites = new Sprite[Width,Height],
                    TerrainCache = new TerrainCache[Width,Height]
                };

                for (var x = 0; x < Width; x++)
                {
                    for (var y = 0; y < Height; y++)
                    {
                        newLayer.Tiles[x, y] = new EditorTile(x, y, 0, 0, 0, 0, newLayer);
                        newLayer.Tiles[x, y].PropertyChanged += Tile_PropertyChanged;
                    }
                }

                foreach (var tile in layer.Tiles)
                {
                    var newTile = newLayer.Tiles[tile.X, tile.Y];
                    newTile.X = tile.X;
                    newTile.Y = tile.Y;
                    newTile.Tileset = tile.Tileset;
                    newTile.SrcX = tile.SrcX;
                    newTile.SrcY = tile.SrcY;
                    newTile.Terrain = tile.Terrain;
                }

                Layers.Add(newLayer);
            }

            _building = false;
            _dontCache = false;

            CacheAllTiles();
        }
Ejemplo n.º 26
0
 static void ApplyChildren(XmlReader re, IChildFigureable c)
 {
     UndoRedoList<Figure> figs = new UndoRedoList<Figure>();
     while (re.Read())
     {
         if (re.NodeType == XmlNodeType.Element && re.LocalName == FIGURE_ELE)
         {
             Figure f = FromXml(re.ReadSubtree());
             if (f != null)
                 figs.Add(f);
         }
     }
     c.ChildFigures = figs;
 }