In memory IContentRepository – Getting children

This post is part of a series of post where I try to implement an in memory IContentRepository. The tests for this posts are found here.

In this post we’ll continue to look at another member of the IContentLoader interface, namely the GetChildren method.

IEnumerable<T> GetChildren<T>(ContentReference contentLink) where T : IContentData;

There’s an interesting method with the signature

IEnumerable<T> GetChildren<T>(ContentReference contentLink, ILanguageSelector selector, int startIndex, int maxRows) where T : IContentData;

But since we, like the last post, don’t worry about language (yet) that will have to come later.

Happy path

Getting all the children of a base type or by using one of the specific page types that are children. Given the following structure


var allChildrenBaseType = contentRepository.GetChildren<PageData>(new PageReference(4));
var allStartPageChildren = contentRepository.GetChildren<StartPage>(new PageReference(4));
var allStandardPageChildren = contentRepository.GetChildren<StandardPage>(new PageReference(4));

This works exactly as expected.

Typed to page type that is not a child of the page

var noneExistingTypeOfChildren = contentRepository.GetChildren<OtherPage>(new PageReference(4));

When no child page are of the requested type an empty enumerable is returned.

Children for a page that does not exist

Just like when trying to get the page this will throw EPiServer.Core.PageNotFoundException.

var noneExistingPage = contentRepository.GetChildren<OtherPage>(new PageReference(4000));