コード例 #1
0
        public void AddVertexCommandTest()
        {
            Shapes.Models.UndoRedoManager manager    = new Shapes.Models.UndoRedoManager();
            Shapes.Models.Canvas          testCanvas = new Shapes.Models.Canvas();
            Shapes.Models.Vertex          first      = new Shapes.Models.Vertex();
            Shapes.Models.Vertex          second     = new Shapes.Models.Vertex();

            Assert.AreEqual(0, testCanvas.Count);
            Shapes.Commands.Vertex.AddVertex testCommand =
                new Shapes.Commands.Vertex.AddVertex(testCanvas, first, manager);

            manager.Execute(testCommand);
            Assert.AreEqual(1, testCanvas.Count);

            manager.Undo();
            Assert.AreEqual(0, testCanvas.Count);

            manager.Redo();
            Assert.AreEqual(1, testCanvas.Count);

            manager.Execute(
                new Shapes.Commands.Vertex.AddVertex(testCanvas, second, manager));
            Assert.AreEqual(2, testCanvas.Count);

            manager.Undo();
            manager.Undo();
            Assert.AreEqual(0, testCanvas.Count);

            manager.Redo();
            Assert.AreEqual(1, testCanvas.Count);

            Configuration.UndoAll(manager);
        }
        public void ClearTest()
        {
            UndoRedoManager manager = new UndoRedoManager();

            Canvas testCanvas = new Canvas();
            Vertex first      = new Vertex();

            Shapes.Commands.Vertex.AddVertex testCommand =
                new Shapes.Commands.Vertex.AddVertex(testCanvas, first, manager);


            Assert.AreEqual(0, manager.UndoItems.Count());
            Assert.AreEqual(0, manager.RedoItems.Count());

            manager.Execute(testCommand);
            manager.Execute(testCommand);
            manager.Execute(testCommand);

            manager.Undo();

            Assert.AreEqual(2, manager.UndoItems.Count());
            Assert.AreEqual(1, manager.RedoItems.Count());

            manager.Clear();

            Assert.AreEqual(0, manager.UndoItems.Count());
            Assert.AreEqual(0, manager.RedoItems.Count());
        }
        public void ExecuteTest()
        {
            UndoRedoManager manager    = new UndoRedoManager();
            Canvas          testCanvas = new Canvas();
            Vertex          first      = new Vertex();

            Shapes.Commands.Vertex.AddVertex testCommand =
                new Shapes.Commands.Vertex.AddVertex(testCanvas, first, manager);
            manager.Execute(testCommand);
            Assert.AreEqual(1, testCanvas.Count);
            Configuration.UndoAll(manager);
        }
        public void CanRedoTest()
        {
            UndoRedoManager urm = new UndoRedoManager();

            Assert.IsFalse(urm.CanRedo);

            Canvas testCanvas = new Canvas();
            Vertex first      = new Vertex();

            Shapes.Commands.Vertex.AddVertex testCommand =
                new Shapes.Commands.Vertex.AddVertex(testCanvas, first, urm);

            urm.Execute(testCommand);
            Assert.IsFalse(urm.CanRedo);

            urm.Undo();

            Assert.IsTrue(urm.CanRedo);

            urm.Redo();

            Assert.IsFalse(urm.CanRedo);
        }