Allows you to write simple tests against Asp & Mvc pages.
Testing Rendered Mvc pages is fairly simple The main code is
MvcApprovals.VerifyMvcPage<YourTestableController>(c => c.TestName);
The Main points are:
- Using CassiniDevServer to host a webserver at test time
- Creating a TestableController Page to call
- Adding
UnitTestBootStrap.RegisterWithDebugCondition("YourAssembyName");
to your Global.asax - Using
.Explicit()
on your views or extending: ControllerWithExplicitViews
You can also easily test your routes
[TestMethod]
public void TestRoutes()
{
var urls = new[] {"/Home/Index/Hello", "/"};
AspApprovals.VerifyRouting(MvcApplication.RegisterRoutes, urls);
}
Which will product Golden Master Files like
/Home/Index/Hello => [[controller, Home], [action, Index], [id, Hello]]
/ => [[controller, Cool], [action, Index], [id, ]]
Approvals can also unit test any urls that produce reliable output (think static pages).
Here's a good video to explain all the inner workings
Install-Package ApprovalTests.Asp
The vast majority of this was created by @jamesrcounts & @Lnknaveen with help from @isidore
If you need to add seams into your production code for testing, you will need the following added to you runtime
using System;
using System.Web.Mvc;
using ApprovalUtilities.CallStack;
public static class MvcUtilites
{
public static ViewResult CallViewResult<T>(Func<T, ActionResult> call, T parameter)
{
var actionResult = (ViewResult) call(parameter);
actionResult.ViewName = call.Method.Name;
return actionResult;
}
public static ViewResult Explicit(this ViewResult view)
{
view.ViewName = new Caller().Method.Name;
return view;
}
}