Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Alexandre Locas 52 posts 216 karma points
    Mar 21, 2022 @ 18:31
    Alexandre Locas

    The type initializer for 'Umbraco.Extensions.FriendlyPublishedContentExtensions' threw an exception

    Hi, I need to unit test the following code :

    var myPage = _publishedContentQuery.ContentAtRoot().DescendantsOrSelfOfType("myDocAlias").FirstOrDefault();

    When running a unit test I get the following exception :

    The type initializer for 'Umbraco.Extensions.FriendlyPublishedContentExtensions' threw an exception.'

    How can i refactor the code to be more testable or how can I unit test this kind of code ?

    Thank you

  • Paul Taylor 2 posts 22 karma points
    Aug 08, 2022 @ 10:26
    Paul Taylor

    A good question. I hit the same issue attempting to use IPublishedContent.Url() in a unit test.

    This extension method retrieves an instance of IPublishedUrlProvider from the internal StaticServiceProvider service locator which renders the code "basically untestable", according to the documentation.

Please Sign in or register to post replies

Write your reply to: