Пример #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);
        }
Пример #2
0
        public void RemoveVertexCommandTest()
        {
            Shapes.Models.UndoRedoManager manager = new Shapes.Models.UndoRedoManager();
            Shapes.Models.Canvas          canvas  = new Shapes.Models.Canvas();
            Shapes.Models.Vertex          first   = new Shapes.Models.Vertex
            {
                Location = new System.Windows.Point(1, 2)
            };
            Assert.AreEqual(0, canvas.Count);
            Assert.IsFalse(canvas.Contains(first));

            canvas.Add(first);
            Assert.AreEqual(1, canvas.Count);
            Assert.IsTrue(canvas.Contains(first));

            Shapes.Commands.Vertex.RemoveVertex removeVertexCommand =
                new Shapes.Commands.Vertex.RemoveVertex(canvas, first);

            manager.Execute(removeVertexCommand);

            Assert.AreEqual(0, canvas.Count);
            Assert.IsFalse(canvas.Contains(first));


            manager.Undo();
            Assert.AreEqual(1, canvas.Count);
            Assert.IsTrue(canvas.Contains(first));

            manager.Redo();
            Assert.AreEqual(0, canvas.Count);
            Assert.IsFalse(canvas.Contains(first));
        }
 public static void UndoAll(Shapes.Models.UndoRedoManager manager)
 {
     while (manager.CanUndo)
     {
         manager.Undo();
     }
 }
Пример #4
0
        public void ChangeLocationCommandTest()
        {
            Shapes.Models.UndoRedoManager manager = new Shapes.Models.UndoRedoManager();
            Shapes.Models.Vertex          first   = new Shapes.Models.Vertex
            {
                Location = new System.Windows.Point(1, 2)
            };
            Assert.AreEqual(new System.Windows.Point(1, 2), first.Location);

            Shapes.Commands.Vertex.ChangeLocation changeLocationCommand =
                new Shapes.Commands.Vertex.ChangeLocation(first, new System.Windows.Point(5, 6));

            manager.Execute(changeLocationCommand);

            Assert.AreEqual(new System.Windows.Point(5, 6), first.Location);


            manager.Undo();
            Assert.AreEqual(new System.Windows.Point(1, 2), first.Location);

            manager.Redo();
            Assert.AreEqual(new System.Windows.Point(5, 6), first.Location);
        }