public void TopNodeIsVisible() { // arrange var top = new ContentModelStub(null); var result = Matching(top, c => !c.HideFromSitemap, c => !c.HideChildrenFromSitemap).ToList(); result.Count.Should().Be(1); }
public void TopNodeHasChildren() { // arrange var top = new ContentModelStub(null); top.ChildNodes = new[] { new ContentModelStub(top), new ContentModelStub(top), new ContentModelStub(top) }; var result = Matching(top, c => !c.HideFromSitemap, c => !c.HideChildrenFromSitemap).ToList(); result.Count.Should().Be(4); }
public IEnumerable <ContentModelStub> Matching(ContentModelStub node, Func <ContentModelStub, bool> predicate = null, Func <ContentModelStub, bool> includeChildren = null) { if (predicate?.Invoke(node) ?? true) { yield return(node); } if (includeChildren?.Invoke(node) ?? true) { foreach (var child in node.Children(predicate)) { foreach (var grandChild in Matching(child, predicate, includeChildren)) { yield return(grandChild); } } } }
public void TopNodeTree() { // arrange var top = new ContentModelStub(null); var child = new ContentModelStub(top) { HideChildrenFromSitemap = true }; child.ChildNodes = new[] { new ContentModelStub(child) }; top.ChildNodes = new[] { child }; var result = Matching(top, c => !c.HideFromSitemap, c => !c.HideChildrenFromSitemap).ToList(); result.Count.Should().Be(2); }
public ContentModelStub(ContentModelStub parent) { Parent = parent; }