public void GetOrAddChildNode_NewChildNodeFromName_ContainsChildNode() { const string childNodeName = "ChildNode"; var fieldSelectorNode = new FieldSelectorTreeNode(string.Empty); FieldSelectorTreeNode childNode = fieldSelectorNode.GetOrAddChildNode(childNodeName); Assert.True(fieldSelectorNode.Children.Contains(childNode)); Assert.Equal(childNodeName, childNode.MemberName); }
public void Expand_ComplexNestedFieldString_ReturnsParsedTree() { List <FieldSelectorTreeNode> tree = FieldSelectorParser.Expand( "person(name(first,last),address(zip,street)),person/salary,link(url,description/short)"); FieldSelectorTreeNode personNode = tree.Find(item => item.MemberName == "person"); Assert.NotNull(personNode); Assert.Equal(3, personNode.Children.Count); Assert.NotNull(personNode.Children.Find(item => item.MemberName == "salary")); FieldSelectorTreeNode nameNode = personNode.Children.Find(item => item.MemberName == "name"); Assert.NotNull(nameNode); Assert.Equal(2, nameNode.Children.Count); Assert.NotNull(nameNode.Children.Find(item => item.MemberName == "first")); Assert.NotNull(nameNode.Children.Find(item => item.MemberName == "last")); FieldSelectorTreeNode addressNode = personNode.Children.Find(item => item.MemberName == "address"); Assert.NotNull(addressNode); Assert.Equal(2, addressNode.Children.Count); Assert.NotNull(addressNode.Children.Find(item => item.MemberName == "zip")); Assert.NotNull(addressNode.Children.Find(item => item.MemberName == "street")); FieldSelectorTreeNode linkNode = tree.Find(item => item.MemberName == "link"); Assert.NotNull(linkNode); Assert.Equal(2, linkNode.Children.Count); Assert.NotNull(linkNode.Children.Find(item => item.MemberName == "url")); FieldSelectorTreeNode descriptionNode = linkNode.Children.Find(item => item.MemberName == "description"); Assert.NotNull(descriptionNode); Assert.Equal(1, descriptionNode.Children.Count); Assert.NotNull(descriptionNode.Children.Find(item => item.MemberName == "short")); }