Copied to clipboard

Flag this post as spam?

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


  • jake williamson 177 posts 789 karma points
    Jan 16, 2015 @ 17:14
    jake williamson
    0

    unit testing: moqing out IPublishedContent with child nodes

    hello out there,

    making slow progress with unit testing but had some sucsess today (http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/60476-unit-testing-creating-an-UmbracoContext-throws-an-exception!) but've got a new one:

    one of the tests we're trying to write requires a mocked out IPublishedContent with child nodes.

    this is what we have:

    var repo = new MockRepository(MockBehavior.Default);
    var node = repo.Create<IPublishedContent>();
    node.Setup(x => x.Id).Returns(1);
    node.Setup(x => x.DocumentTypeAlias).Returns("Folder");
    

    but for our test to run we need to populate:

    node.Setup(x => x.Children).Returns(WhatGoesHere?);
    

    more specificallty, for this particluar test the 1st child needs to have a 'DocumentTypeAlias' of 'Image'.

    the trick is that 'Children' is a 'IEnumerable

    any clues?

    cheers,

    jake

  • 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" link below.

Please Sign in or register to post replies