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.
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.
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.
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.
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
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.
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
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.
I've raised this now here - http://issues.umbraco.org/issue/U4-4566
is working on a reply...