Beginning EPiServer Unit Testing: Page Filtering

I managed to solve the problem with ContentLanguage.PreferredCulture as described in my previous post. But six unit tests still failed. It turned a filter had been added to display only published pages like this:

new FilterPublished(PagePublishedStatus.Published).Filter(pages);

For me, this was harder than expected to fix. Pages were created in unit tests like this:

new BeslutsunderlagPage()

(We’re using PageTypeBuilder.) But these have version status “NotCreated” and are filtered out by the above code. After a lot of experimenting (because I’m a complete beginner at EPiServer) I came up with the following way to create these pages that works:

        private static TPage CreatePublishedPage<TPage>() where TPage : PageTypeBuilder.TypedPageData, new()
            var page = new TPage();
            var prop = new PropertyNumber((int)VersionStatus.Published);
            page.Property.Add("PageWorkStatus", prop);
            return page;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.