Exemplo n.º 1
0
        public void CreateEdgeOperation_Do_Test()
        {
            var graph = new Model.GraphArea();

            var source = new DataVertex(100) { };
            var sourceVC = new VertexControl(source);
            graph.Graph.AddVertex(source);
            graph.AddVertex(source, sourceVC);

            var target = new DataVertex(101) { };
            var targetVC = new VertexControl(target);
            graph.Graph.AddVertex(target);
            graph.AddVertex(target, targetVC);

            bool called = false;
            EdgeControl ec = null;
            var ceo = new CreateEdgeOperation(graph, source, target, (e) =>
            {
                called = true;
                ec = e;
            },
            (e) =>
            {

            });

            ceo.Do();

            Assert.IsTrue(called);
            Assert.IsNotNull(ec);
            Assert.AreEqual<VertexControl>(ec.Source, sourceVC, "source are not equal");
            Assert.AreEqual<VertexControl>(ec.Target, targetVC, "target are not equal");
        }
Exemplo n.º 2
0
        public void VertexPositionChanged_Test()
        {
            var graph = new Model.GraphArea();

            var vertex = new DataVertex();

            var vctrol = new VertexControl(vertex);

            graph.Graph.AddVertex(vertex);

            graph.AddVertex(vertex, vctrol);

            bool called     = false;
            bool undoCalled = false;

            var vpco = new VertexPositionChangeOperation(graph, vctrol, 10, 10, vertex, (v, vc) =>
            {
                called = true;
            }, (vc) =>
            {
                undoCalled = true;
            });

            vpco.Do();

            Assert.IsTrue(called);

            vpco.UnDo();

            Assert.IsTrue(undoCalled);
        }
Exemplo n.º 3
0
        public void CreateEdgeOperation_Do_Test()
        {
            var graph = new Model.GraphArea();

            var source = new DataVertex(100)
            {
            };
            var sourceVC = new VertexControl(source);

            graph.Graph.AddVertex(source);
            graph.AddVertex(source, sourceVC);

            var target = new DataVertex(101)
            {
            };
            var targetVC = new VertexControl(target);

            graph.Graph.AddVertex(target);
            graph.AddVertex(target, targetVC);

            bool        called = false;
            EdgeControl ec     = null;
            var         ceo    = new CreateEdgeOperation(graph, source, target, (e) =>
            {
                called = true;
                ec     = e;
            },
                                                         (e) =>
            {
            });

            ceo.Do();

            Assert.IsTrue(called);
            Assert.IsNotNull(ec);
            Assert.AreEqual <VertexControl>(ec.Source, sourceVC, "source are not equal");
            Assert.AreEqual <VertexControl>(ec.Target, targetVC, "target are not equal");
        }
Exemplo n.º 4
0
        public void Delete_Vertex_With_Related_Edges_Test()
        {
            //begin setup
            var graph = new Model.GraphArea();

            var v1 = new DataVertex(100) { };
            var v2 = new DataVertex(103) { };
            var v3 = new DataVertex(105) { };
            var vc1 = new VertexControl(v1);
            var vc2 = new VertexControl(v2);
            var vc3 = new VertexControl(v3);

            var e1 = new DataEdge(v1, v2);
            var ec1 = new EdgeControl(vc1, vc2, e1);
            var e2 = new DataEdge(v1, v3);
            var ec2 = new EdgeControl(vc1, vc3, e2);

            graph.Graph.AddVertex(v1);
            graph.AddVertex(v1, vc1);
            graph.Graph.AddVertex(v2);
            graph.AddVertex(v2, vc2);
            graph.Graph.AddVertex(v3);
            graph.AddVertex(v3, vc3);

            graph.Graph.AddEdge(e1);
            graph.AddEdge(e1, ec1);
            graph.Graph.AddEdge(e2);
            graph.AddEdge(e2, ec2);
            //end setup
            bool doCalled = false;
            bool undoCalled = false;
            var dvo = new DeleteVertexOperation(graph, v1, (dv, vc) =>
            {
                doCalled = true;
            },
            (dv) =>
            {
                undoCalled = true;
            });

            dvo.Do();

            Assert.IsTrue(doCalled);
            Assert.IsFalse(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e2));

            dvo.UnDo();

            Assert.IsTrue(undoCalled);
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsTrue(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsTrue(graph.EdgesList.Any(e => e.Key == e2));

            dvo.Do();

            Assert.IsTrue(doCalled);
            Assert.IsFalse(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e2));
        }
Exemplo n.º 5
0
        public void VertexPositionChanged_Test()
        {
            var graph = new Model.GraphArea();

            var vertex = new DataVertex();

            var vctrol = new VertexControl(vertex);

            graph.Graph.AddVertex(vertex);

            graph.AddVertex(vertex, vctrol);

            bool called = false;
            bool undoCalled = false;

            var vpco = new VertexPositionChangeOperation(graph, vctrol, 10, 10, vertex, (v, vc) =>
            {
                called = true;
            }, (vc) =>
            {
                undoCalled = true;
            });

            vpco.Do();

            Assert.IsTrue(called);

            vpco.UnDo();

            Assert.IsTrue(undoCalled);
        }
Exemplo n.º 6
0
        public void Delete_Vertex_With_Related_Edges_Test()
        {
            //begin setup
            var graph = new Model.GraphArea();

            var v1 = new DataVertex(100)
            {
            };
            var v2 = new DataVertex(103)
            {
            };
            var v3 = new DataVertex(105)
            {
            };
            var vc1 = new VertexControl(v1);
            var vc2 = new VertexControl(v2);
            var vc3 = new VertexControl(v3);

            var e1  = new DataEdge(v1, v2);
            var ec1 = new EdgeControl(vc1, vc2, e1);
            var e2  = new DataEdge(v1, v3);
            var ec2 = new EdgeControl(vc1, vc3, e2);

            graph.Graph.AddVertex(v1);
            graph.AddVertex(v1, vc1);
            graph.Graph.AddVertex(v2);
            graph.AddVertex(v2, vc2);
            graph.Graph.AddVertex(v3);
            graph.AddVertex(v3, vc3);

            graph.Graph.AddEdge(e1);
            graph.AddEdge(e1, ec1);
            graph.Graph.AddEdge(e2);
            graph.AddEdge(e2, ec2);
            //end setup
            bool doCalled   = false;
            bool undoCalled = false;
            var  dvo        = new DeleteVertexOperation(graph, v1, (dv, vc) =>
            {
                doCalled = true;
            },
                                                        (dv) =>
            {
                undoCalled = true;
            });

            dvo.Do();

            Assert.IsTrue(doCalled);
            Assert.IsFalse(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e2));

            dvo.UnDo();

            Assert.IsTrue(undoCalled);
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsTrue(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsTrue(graph.EdgesList.Any(e => e.Key == e2));

            dvo.Do();

            Assert.IsTrue(doCalled);
            Assert.IsFalse(graph.VertexList.Any(v => v.Key.Id == v1.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v2.Id));
            Assert.IsTrue(graph.VertexList.Any(v => v.Key.Id == v3.Id));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e1));
            Assert.IsFalse(graph.EdgesList.Any(e => e.Key == e2));
        }