Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
chaps, it is possible to unit test a back office controller inheriting from UmbracoAuthorizedApiController?
at the moment, when i'm trying to mock my controller out i get:
System.ArgumentNullException : Value cannot be null.
Parameter name: umbracoContext at Umbraco.Web.WebApi.UmbracoApiControllerBase..ctor(UmbracoContext umbracoContext) at Umbraco.Web.WebApi.UmbracoAuthorizedApiController..ctor()
i can move 99% of my code out into a separate service which would negate the need to test my controller but that feels like a work around...
You're stating the answer, but if you'd like to go the long way around, you can test most stuff in Umbraco that relies on an UmbracoContext. I've outlined the basic steps on my blog: http://blog.aabech.no/archive/the-basics-of-unit-testing-umbraco/.
Most basic answer is: reference Umbraco.Tests from the core source. There's base classes there that handle the bulk of setting it up for you.
hey lars, i'm finding i go the long way round more and more these days ;)
thanks for your reply, and for posting the link to your blog post (which i've read many times!).
i'm pretty much there with it now!
Really happy the post helped. :)
The trick is to know when to abstract and when to just deliver.
Best of luck!
Thanks for the post but I'm having problems trying to do an automated test on a plugin we've created. Basically I need to test a class which extends UmbracoAuthorizedApiController but the problem I'm facing is that UmbracoContext.Security.CurrentUser is always null, even if I adapt your UmbracoContext setup and set a User on the httpContextBase.
I'm using Gherkin scripts with SpecFlow and I prefer to use xUnit as my test runner, so I can't use Umbraco.Tests.
I don't have all the code in memory, so I hope you're fine with some general guidance. :)
You'll have to investigate the Umbraco source so you know how it works. There are probably internals you can't get to in order to stub what you need. The benefit of using Umbraco.Tests is that it sets up most internals for you. If you're not using it, you'll have to manage to set those internals yourself.
Which leaves two options:
The latter has access to all internals due to an InternalsVisibleTo in core. It's supposed to be used from tests only, ofc. :)
For older versions you can call it "Umbraco.VisualStudio".
The sample repo from the blog post has been updated recently. You might find something similar to what you need here:
I also have some with SpecFlow, but I don't remember if I touched authentication:
Hope this helps. :)
It looks like your specflow examples have lots of good setup stuff in them. I'll wade through them and see if I can use some of the code from your examples.
Thank you so much :-)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted