Copied to clipboard

Flag this post as spam?

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


  • rani_N 1 post 71 karma points
    Jan 11, 2023 @ 16:41
    rani_N
    0

    Mocking Umbraco8 IPublishedContent siteSettings Descendants method

    Need some help writing mock tests implementation for surface controllers. Unable to mock IPublishedContent methods in Umbraco *

    I initially tried to Mock IPublishedContent as mentioned below.

     Mock<IPublishedContent> mockIdentifierTypeContent = new Mock<IPublishedContent>();
    SiteSettings siteSettings = Umbraco.Content(request.HomePageId) as SiteSettings;
    

    and able to successfully mock content in SiteSettings object.

    but looking to mock the SiteSettings Descendants as mentioned in the line below.

    siteSettings.Descendants<Registration>().FirstOrDefault(s => s.Id == request.PageId);
    
    
     public static IEnumerable<T> Descendants<T>(this IPublishedContent content, string culture = null)
                where T : class, IPublishedContent
            {
                return content.Descendants(culture).OfType<T>();
            }
    

    Any inputs or Suggestions greatly appreciated. Thanks in advance.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" button below.

    Continue discussion

Please Sign in or register to post replies