public void Add_Gets_Applied_To_Graph() {
            var graph = new DirectedGraph();

            var a = new GraphNode("a");
            var b = new GraphNode("b");
            var c = new GraphNode("c");
            var d = new GraphNode("d");

            graph.AddNode(a);
            graph.AddNode(b);
            graph.AddNode(c);
            graph.AddNode(d);

            var graphExpression = new GraphExpression<IDirectedGraph>(graph);
            var expression = new EdgeCollectionModifiersExpression<IGraphExpression>(graph, graphExpression);

            expression.Add(
                edges =>
                    {
                        edges.FromNodeWithName("a").ToNodeWithName("b");
                        edges.FromNodeWithName("c").ToNodeWithName("d");
                    }
                );

            Assert.AreEqual(graph.Edges.Count(), 2);

            var edge1 = graph.Edges.First();
            Assert.AreEqual(edge1.From.Node, a);
            Assert.AreEqual(edge1.To.Node, b);

            var edge2 = graph.Edges.Skip(1).First();
            Assert.AreEqual(edge2.From.Node, c);
            Assert.AreEqual(edge2.To.Node, d);
        }
Ejemplo n.º 2
0
        public void ToDot_Should_Return_DiGraph_Entity()
        {
            var graph = new DirectedGraph {Name = "a"};
            var dot = graph.ToDot();

            Assert.IsTrue(Regex.Match(dot, "^digraph \\\"a\\\" \\{[^}]*\\}$", RegexOptions.Multiline).Success);
        }
        public void WithName_Sets_Name_And_Adds_Node_To_Graph()
        {
            var graph = new DirectedGraph();
            var expression = new RecordCollectionAddExpression(graph);
            Assert.IsNotNull(expression.WithName("name"));

            var node = graph.NodeLookup.GetNodeByName("name");
            Assert.IsNotNull(node);
            Assert.AreEqual(node.Name, "name");
        }
        public void Edges_Action_Should_Add_Template_As_Defaults_To_Graph()
        {
            var graph = new DirectedGraph();
            var graphExpression = new GraphExpression<IDirectedGraph>(graph);

            Assert.IsNull(graph.EdgeDefaults);

            var expression = new DefaultsExpression(graphExpression, graph);
            expression.ForEdges.Are(x => x.WithLabel("label"));

            Assert.IsNotNull(graph.EdgeDefaults);
            Assert.AreEqual(graph.EdgeDefaults.AttributeCount, 1);
        }
Ejemplo n.º 5
0
        private static void AssertAttributeAdded(Action<ISubGraphExpression> action, Type attributeType, object attributeValue, Action<ISubGraph> customAsserts)
        {
            var graph = new DirectedGraph();
            var expression = new SubGraphExpression(graph);
            action(expression);

            var cluster = expression.SubGraph;

            Assert.AreEqual(cluster.Attributes.CurrentAttributes.Count, 1);

            var attribute = cluster.Attributes.CurrentAttributes[0];
            Assert.IsInstanceOfType(attributeType, attribute);
            Assert.AreEqual(attribute.Value, attributeValue);

            if (customAsserts != null)
            {
                customAsserts(expression.SubGraph);
            }
        }