Copied to clipboard

Flag this post as spam?

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


  • Fabio Milheiro 74 posts 136 karma points
    Mar 06, 2014 @ 15:29
    Fabio Milheiro
    0

    Unit testing umbraco with wrapper abstractions? Is there a better other way?

    I have been thinking: How do I start using TDD with umbraco. Well, I couldn't find a way to test a controller while using an umbraco API inside my action.

    E.g. I had something like the following code inside of an action in a RenderMvcController:

    IContent content = contentService.GetById(id);

    content.SetValue("name", name);

    contentService.SaveAndPublish(content);

    I was thinking of using a layer that would work like a facade that would allow me to abstract umbraco stuff by mocking that layer. It seems I wasn't the only one thinking in these terms.

    See here: https://www.youtube.com/watch?v=1xS002NyGnc

    But I just wasn't sure if everyone would go with this or have other opinions because most umbraco developers who used V4 were certainly used to query the umbraco APIs inside macroScripts and this approach requires that the developer creates a new class for each set of related functionality - which keeps making sense to me because for all I care, in the front-end, umbraco is just a database.

    Am I right to think that from now on, we should always query umbraco from a facade??

  • Charles Afford 1163 posts 1709 karma points
    Mar 11, 2014 @ 21:16
    Charles Afford
    1

    Hi,  If you get a copy of the Umbraco Source and complie you will get a Test.dll.  This has methods that will allow you to a mocked Umbrco and Application context.  Dont know if this is what you are after but might help :)

  • Fabio Milheiro 74 posts 136 karma points
    Mar 11, 2014 @ 21:40
    Fabio Milheiro
    0

    Hi Charles,

    Thanks for your response. I am aware of that. I was more kind of asking (or trying to) about the umbraco service interface that the guy in the video suggested.

    His approach seems reasonably good to me (except that his Save method implementation actually saves on every property change). And if we use an umbraco service to get that, that means that in the code written in the controllers, we can't actually call anything like contentService.GetBy(id).Descendants.. etc etc.

    Is this is how you have been doing? Using a new layer to abstract umbraco access layer?

    Thanks!

  • Charles Afford 1163 posts 1709 karma points
    Mar 17, 2014 @ 13:57
    Charles Afford
    0

    Hi Fabio,

    No problem.

    What are you trying to acheive?

    Charlie.

Please Sign in or register to post replies

Write your reply to:

Draft