public void ApplyConventions_Edge_Should_Apply_Conventions()
        {
            var conventionTracker = new ConventionTracker();
            var convention = MockRepository.GenerateMock<IEdgeConvention>();
            var fromNode = new GraphNode("a");
            var toNode = new GraphNode("b");
            var edgeInfo = new EdgeInfo(new NodeInfo(fromNode.Name, null), new NodeInfo(toNode.Name, null), null);

            convention.Expect(x => x.ShouldApply(edgeInfo))
                .IgnoreArguments()
                .Constraints(Is.Matching<IEdgeInfo>(x => x.FromNode.Name == "a" && x.ToNode.Name == "b"))
                .Return(true)
                .Repeat.Once();

            convention.Expect(x => x.Apply(null, null)).IgnoreArguments()
                .Constraints(
                    Is.Matching<IEdgeInfo>(x =>
                        x.Tag == edgeInfo.Tag &&
                        x.FromNode.Name == edgeInfo.FromNode.Name &&
                        x.ToNode.Name == edgeInfo.ToNode.Name
                    ), Is.Matching<IEdgeExpression>(x => x != null))
                .Repeat.Once();

            conventionTracker.AddConvention(convention);
            conventionTracker.ApplyConventions(new DirectedEdge(new NodeTarget(fromNode), new NodeTarget(toNode)));
            convention.VerifyAllExpectations();
        }
        /// <summary>
        /// Adds a node with the specified name to the graph.
        /// </summary>
        /// <param name="name">The name of the node to create.</param>
        /// <returns>
        /// A node expression for configuring the node.
        /// </returns>
        public INodeExpression WithName(string name) {
            var node = new GraphNode(name);
            graph.AddNode(node);

            var expression = new NodeExpression(node);
            return expression;
        }
        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);
        }
Beispiel #4
0
 public void Add_Should_Add_Node_To_Collection()
 {
     var tracker = new NodeTracker();
     var node = new GraphNode("name");
     tracker.AddNode(node);
     Assert.AreEqual(tracker.Nodes.Count(), 1);
     Assert.AreSame(tracker.Nodes.First(), node);
 }
Beispiel #5
0
        public void ToDot_Uses_Edge_Indicator()
        {
            var a = new GraphNode("a");
            var b = new GraphNode("b");

            var edge = new TestEdge(a, b);
            Assert.AreEqual(edge.ToDot(), "\"a\" ** \"b\"");
        }
        public void WithTag_Should_Set_Tag_On_Node()
        {
            var node = new GraphNode("gg");
            var expression = new NodeExpression(node);
            expression.WithTag(5);

            Assert.AreEqual(node.Tag, 5);
        }
        public void ToDot_Should_Use_Name_And_Attributes_Of_Template()
        {
            var node = new GraphNode("name");
            node.Attributes.AddAttribute(new LabelAttribute("label"));
            node.Attributes.AddAttribute(new URLAttribute("http://www.google.com"));

            var defaults = new EntityDefaultsBase("entity", node);
            Assert.AreEqual(defaults.ToDot(), "entity [label=\"label\", URL=\"http://www.google.com\"]");
        }
Beispiel #8
0
        public void GetNodeByTag_With_Invalid_Tag_Should_Return_Null() {
            var tracker = new NodeTracker();

            var node1 = new GraphNode("name1") { Tag = 1 };
            tracker.AddNode(node1);
            
            Assert.AreEqual(tracker.Nodes.Count(), 1);

            Assert.IsNull(tracker.GetNodeByTag(2));
        }
Beispiel #9
0
        public void ToDot_Should_Output_Name_With_Attributes() {
            var node = new GraphNode("ff");

            var attribute = MockRepository.GenerateMock<IDotAttribute>();
            attribute.Expect(x => x.ToDot()).Return("att=custom");
            node.Attributes.AddAttribute(attribute);

            Assert.AreEqual(node.ToDot(), "\"ff\" [att=custom]");

            attribute.VerifyAllExpectations();
        }
        public void ContainsScaledImage_Should_Add_Image_And_Scaled_Attribute()
        {
            var node = new GraphNode("gg");
            var expression = new NodeExpression(node);
            expression.ContainsScaledImage("FluentDot.Tests.dll");

            Assert.AreEqual(node.Attributes.CurrentAttributes.Count, 2);

            AssertAttributeAdded(node.Attributes.CurrentAttributes[0], typeof(ImageAttribute), Path.GetFullPath("FluentDot.Tests.dll"));
            AssertAttributeAdded(node.Attributes.CurrentAttributes[1], typeof(ImageScaleAttribute), new BooleanValue(true));
        }
Beispiel #11
0
        public void ToDot_Ouputs_Attributes()
        {
            var a = new GraphNode("a");
            var b = new GraphNode("b");

            var attribute = MockRepository.GenerateMock<IDotAttribute>();
            attribute.Expect(x => x.ToDot()).Return("att=custom");
            
            var edge = new TestEdge(a, b);
            edge.Attributes.AddAttribute(attribute);
            Assert.AreEqual(edge.ToDot(), "\"a\" ** \"b\" [att=custom]");
        }
Beispiel #12
0
        public void GetNodeByTag_Should_Retrieve_Node_By_Tag() {
            var tracker = new NodeTracker();
            
            var node1 = new GraphNode("name1") {Tag = 1};
            var node2 = new GraphNode("name2") {Tag = 2};

            tracker.AddNode(node1);
            tracker.AddNode(node2);

            Assert.AreEqual(tracker.Nodes.Count(), 2);

            Assert.AreSame(tracker.GetNodeByTag(1), node1);
            Assert.AreSame(tracker.GetNodeByTag(2), node2);
        }
Beispiel #13
0
        public void GetNodeByName_Should_Retrieve_Node_By_Name()
        {
            var tracker = new NodeTracker();
            var node1 = new GraphNode("name1");
            var node2 = new GraphNode("name2");
            
            tracker.AddNode(node1);
            tracker.AddNode(node2);

            Assert.AreEqual(tracker.Nodes.Count(), 2);

            Assert.AreSame(tracker.GetNodeByName("name1"), node1);
            Assert.AreSame(tracker.GetNodeByName("name2"), node2);
        }
        public void Add_Returns_Parent_Expression() {
            var graph = new UndirectedGraph();

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

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

            var graphExpression = new GraphExpression<IUndirectedGraph>(graph);
            var expression = new EdgeCollectionModifiersExpression<IGraphExpression>(graph, graphExpression);
            
            var instance = expression.Add(edges => edges.FromNodeWithName("a").ToNodeWithName("b"));
            Assert.AreSame(instance, graphExpression);
        }
        public void ApplyConventions_Edge_Should_Not_Apply_Conventions_When_Should_Apply_Is_False()
        {
            var conventionTracker = new ConventionTracker();
            var convention = MockRepository.GenerateMock<IEdgeConvention>();
            var fromNode = new GraphNode("a");
            var toNode = new GraphNode("b");
            var edgeInfo = new EdgeInfo(new NodeInfo(fromNode.Name, null), new NodeInfo(toNode.Name, null), null);

            convention.Expect(x => x.ShouldApply(edgeInfo))
                .IgnoreArguments()
                .Return(false)
                .Repeat.Once();

            convention.Expect(x => x.Apply(null, null))
                .IgnoreArguments()
                .Repeat.Never();

            conventionTracker.AddConvention(convention);
            conventionTracker.ApplyConventions(new DirectedEdge(new NodeTarget(fromNode), new NodeTarget(toNode)));
            convention.VerifyAllExpectations();
        }
        public void ApplyConventions_Node_Should_Not_Apply_Conventions_When_Should_Apply_Is_False()
        {
            var conventionTracker = new ConventionTracker();
            var convention = MockRepository.GenerateMock<INodeConvention>();
            var graphNode = new GraphNode("a");
            var nodeInfo = new NodeInfo(graphNode.Name, graphNode.Tag);

            convention.Expect(x => x.ShouldApply(nodeInfo))
                .IgnoreArguments()
                .Return(false)
                .Repeat.Once();

            convention.Expect(x => x.Apply(null, null))
                .IgnoreArguments()
                .Repeat.Never();
                
            conventionTracker.AddConvention(convention);
            conventionTracker.ApplyConventions(graphNode);

            convention.VerifyAllExpectations();
        }
        public void ApplyConventions_Node_Should_Apply_Conventions()
        {
            var conventionTracker = new ConventionTracker();
            var convention = MockRepository.GenerateMock<INodeConvention>();
            var graphNode = new GraphNode("a");
            var nodeInfo = new NodeInfo(graphNode.Name, graphNode.Tag);

            convention.Expect(x => x.ShouldApply(nodeInfo))
                .IgnoreArguments()
                .Constraints(Is.Matching<INodeInfo>(x => x.Name == "a"))
                .Return(true)
                .Repeat.Once();

            convention.Expect(x => x.Apply(null, null)).IgnoreArguments()
                .Constraints(Is.Matching<INodeInfo>(x => x.Name == graphNode.Name && x.Tag == graphNode.Tag), Is.Matching<INodeExpression>(x => x != null))
                .Repeat.Once();
            
            conventionTracker.AddConvention(convention);
            conventionTracker.ApplyConventions(graphNode);

            convention.VerifyAllExpectations();
        }
Beispiel #18
0
        private static void AssertAttributeAdded(Action<INodeExpression> action, Type attributeType, object attributeValue, Action<IGraphNode> customAsserts)
        {
            var node = new GraphNode("gg");
            var expression = new NodeExpression(node);
            action(expression);
            
            Assert.AreEqual(node.Attributes.CurrentAttributes.Count, 1);

            AssertAttributeAdded(node.Attributes.CurrentAttributes[0], attributeType, attributeValue);

            if (customAsserts != null)
            {
                customAsserts(node);
            }
        }