Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8393397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:46:23+00:00 2026-06-09T19:46:23+00:00

In EPiServer, how would someone go by testing an extension like so: public static

  • 0

In EPiServer, how would someone go by testing an extension like so:


public static class LinkItemExtensions
    {
        public static T GetTypedPage(this LinkItem link) where T : TypedPageData
        {
            return (T) DataFactory.Instance.GetPage(PageReference.ParseUrl(link.Href));
        }
    }

What I'm trying to do is somehow test the above class with the following code:


[TestFixture]
public class LinkItemExtensionsTests
    {
        [Test]
        public void GetTypedPage_GivenALinkItem_ReturnsTypedPageData()
        {
            var link = new LinkItem();
            var typedPage = link.GetTypedPage();
            Assert.IsAssignableFrom(typeof(StartPageData), typedPage);
        }
    }

The problem occurs when DataFactory.Instance is summoned.

System.TypeInitializationException : The type initializer for
'EPiServer.DataFactory' threw an exception. ---->
System.NullReferenceException : Object reference not set to an
instance of an object.

So I've tried passing an abstraction of the DataFactory to the extension method like so:


namespace WebTests
{
    [TestFixture]
    public class PageDataExtensionsTests
    {
        [Test]
        public void GetTypedPage_GivenALinkItem_ReturnsTypedPageData()
        {
            var link = new LinkItem();

        var startPage = A.Fake<StartPageData>();

        var pageDataFactory = A.Fake<IDataFactoryFacade>();

        A.CallTo(() => pageDataFactory.GetPage(null))
            .WithAnyArguments()
            .Returns(startPage);

        var typedPage = link.GetTypedPage<StartPageData>(pageDataFactory);

        Assert.IsAssignableFrom(typeof(StartPageData), typedPage);

    }

}

}

And I get

System.InvalidCastException : Unable to cast object of type 'Castle.Proxies.PageDataProxy' to type 'LocalEPiSandbox.Templates.PageTypes.StartPageData'.

How do you approach this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:46:24+00:00Added an answer on June 9, 2026 at 7:46 pm

    You should depend on abastractions insted of it’s implementations (you should have some facade cladd above DataFactory). Please take a look over More testability to the people with EPiAbstractions!.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you perform your UI tests on a CMS like EPiServer? Where the
I'm using EPiServer for this website. Unlike asp:DataList , EPiServer:PAgeList does not have AlternatingItemTemplate
I have the following code. It works in an html document. I would like
We have an EPI Server site. We would like to publish the contents from
EPiServer CMS 6 site that suddenly got this error in edit mode. Found alot
I can't find any information about this on either www.episerver.com or world.episerver.com, anyone knows?
What is the best way to abstract the episerver infrastructure for easier testing?
I would like to exclude CA1822:MarkMembersAsStatic from the CoreTest assembly as the NUnit test
I'm working with EpiServer CMS 6 on the ASP .net 4.0 platform. I can
Today I saw a demonstration of the episerver cms and it had a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.