Exemplo n.º 1
0
        public void Query_AddChild()
        {
            var queryNode = new QueryNode <TestUser>("NAME");

            var addedNode = queryNode.AddChild("CHILD");

            Assert.Equal("NAME", addedNode.Name);
            Assert.Equal("CHILD", addedNode.Value);
            Assert.Equal("CHILD", queryNode.Childs.Single().Value);
        }
Exemplo n.º 2
0
        private static QueryNode <TEntity> BuildTreeForNode <TEntity>(QueryNode <TEntity> node, string currentPath, List <string> paths)
        {
            if (currentPath == null || node == null)
            {
                return(null);
            }

            var lastPaths = paths.Skip(1).ToList();
            var lastPath  = lastPaths.FirstOrDefault();

            var existingNode = node.Childs.FirstOrDefault(x => x.Value == currentPath);

            if (existingNode == null)
            {
                var newNode = node.AddChild(currentPath);

                return(BuildTreeForNode(newNode, lastPath, lastPaths) ?? newNode);
            }

            return(BuildTreeForNode(existingNode, lastPath, lastPaths) ?? existingNode);
        }