Copied to clipboard

Flag this post as spam?

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


  • Keith Jackson 183 posts 552 karma points
    Mar 28, 2014 @ 19:38
    Keith Jackson
    0

    Unit Testing Controllers in Umbraco 7

    The last part of my unit testing fixes migrating from U6 to U7 is my controllers.

    I can no longer seem to unit test my controllers as the umbracoContext parameter is null.

    This didn't seem to be a problem in Umbraco 6, but in 7 these tests no longer work. Can anyone offer any guidance as to a way around this. If there isn't where would be a good place to request a change to make the UmbracoContext a mockable interface so that we can properly unit test our controllers.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 28, 2014 @ 22:40
    Jeroen Breuer
    0

    Hello,

    I don't think the way controllers work in v6 and v7 is very different. If something is it might be a good idea to report it here: http://issues.umbraco.org/dashboard#newissue=yes

    Jeroen

  • Keith Jackson 183 posts 552 karma points
    Mar 31, 2014 @ 12:38
    Keith Jackson
    0

    Hi Jeroen,

    I'll check out the codebase history and see if I can pick out any changes, I think the site was running 6.0.0 before though and that's not in the GIT Repo but I'll see what I can dig out first anyway.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 31, 2014 @ 12:42
    Jeroen Breuer
    0

    Controllers have been improved in 6.1 and even after that and those changes are in v7 so in that case there might be differences.

    Jeroen

  • Keith Jackson 183 posts 552 karma points
    Mar 31, 2014 @ 14:00
    Keith Jackson
    1

    I think I've sussed this. Back in 6.1, the RenderMvcController inherited directly from System.Web.Mvc.Controller and didn't require any constructor parameters. In 7, RenderMvcController now inherits from UmbracoController, which now requires an umbracoContext parameter to be present.

    I assume that this parameter is injected by some Autofac magic at some point in the normal lifecycle, but as the context seems completely unmockable it seems that it's no longer possible to unit test controllers.

    I'll raise this as an issue.

  • Keith Jackson 183 posts 552 karma points
    Mar 31, 2014 @ 14:06
    Keith Jackson
    100

    I've raised this now here - http://issues.umbraco.org/issue/U4-4566

Please Sign in or register to post replies

Write your reply to:

Draft