Ejemplo n.º 1
0
        public void Graph_Tree_Flatten_SelectOneEdge()
        {
            var root = graph.VertexContainingType(typeof(Dto));
            var edge = graph.OutgoingEdges(root).First(x => x.From != x.To);
            var tree = new Tree(root, new[] {
                Graph.ITuple.Create <Edge, Tree>(edge, new Tree(edge.To)),
            });
            var flat = tree.Flatten();

            Assert.NotNull(flat);
            Assert.Equal(2, flat.Vertices.Count());
            Assert.Single(flat.Edges);
        }
Ejemplo n.º 2
0
        public static PathToProperty PathAndPropertyFromExpandItem(QueueItem addition, GraphSchema graph, Type RootQueryType)
        {
            // add to path list.
            var      edges        = new List <Edge>();
            Property propertyName = null;

            void traverseExpandTree(Vertex from, QueueItem parsedSelection)
            {
                if (parsedSelection?.Root?.Value.Representation != TextRepresentation.ExpandProperty)
                {
                    return;
                }
                if (!parsedSelection.Children.Any())
                {
                    propertyName = from.Value.Properties.Single(x => x.Name == parsedSelection.Root.Value.Text);
                    return;
                }

                // get the edge in the graph where it is connected from the same type as the from vertex, and the property name matches.
                var edge = graph.Edges.FirstOrDefault(e => e.From.Value.TypeId == from.Value.TypeId && e.Value.Name == parsedSelection.Root.Value.Text);

                if (edge is null)
                {
                    return;
                }
                edges.Add(edge);
                foreach (var child in parsedSelection.Children)
                {
                    traverseExpandTree(edge.To, child.Item2);
                }
            }

            var rootQueryVertex = graph.VertexContainingType(RootQueryType);

            traverseExpandTree(rootQueryVertex, addition);
            return(new PathToProperty(edges, propertyName));
        }
Ejemplo n.º 3
0
        public void Tree_Traverse_Success()
        {
            var root        = graph.VertexContainingType(typeof(Dto));
            var childVertex = graph.VertexContainingType(typeof(DtoChild));

            var edgeRootToChildAsChildren = graph.Edges.Single(e => e.From == root && e.To == childVertex && (e as Edge).Value.IsCollection == false);
            var edgeRootToRootAsFavorite  = graph.Edges.Single(e => e.From == root && e.To == childVertex && (e as Edge).Value.IsCollection == false);

            var tree = new Tree(root,
                                new[] {
                Graph.ITuple.Create(edgeRootToChildAsChildren, new Tree(childVertex)),
                Graph.ITuple.Create(edgeRootToRootAsFavorite, new Tree(root)),
            }
                                );
            var traversedEdges = new List <Edge>();

            tree.TraverseDepthFirstSearch(e => traversedEdges.Add(e));
            Assert.Equal(2, traversedEdges.Count);
        }