Unit testing Umbraco surface controllers isn't straightforward, due to issues with mocking or faking dependencies. There has been some discussion about it and there are some workarounds regarding using certain test base classes. But in general it's not an easy thing to do, at least at the moment. Another approach (or workaround) for this is to move the thing you are trying to test outside of the controller and into another class - that itself depends only on standard ASP.Net MVC. Test that instead, leaving your controller so simple that in itself there remains little value in testing it directly. As an example, I had this to test: [HttpPost] [ValidateAntiForgeryToken] public ActionResult SignUp(NewsletterSignUpModel model) { if (ModelState.IsValid) { // Model valid so sign-up email address var result = _newsletterSignUpService.SignUp(model.Email, model.FirstName, model.LastName); ...
Senior Developer and head of DXP at Umbraco. Previously with Zone, building solutions primarily on .NET and using Umbraco, EPiServer and Sitecore CMS. This blog is used as a repository for various tips, tricks, issues and impressions drawn from the use of technology my work and interests. All words are my own.