Route Testing and MVC 2.0 Areas
I’ve been using the MvcContrib.TestHelper class for a while now to get rather nice fluent testing of the routes in my MVC applications.
A typical test class would look like this
public class CategoryRoutesFixture : RoutesFixture
{
private const int categoryId = 34;
private static string BaseUrl
{
get { return "~/admin/Category"; }
}
[Test]
public void Index()
{
BaseUrl.ShouldMapTo<CategoryController>(x => x.Index());
}
[Test]
public void Create()
{
(BaseUrl + "/create").ShouldMapTo<CategoryController>(x => x.Create());
}
[Test]
public void Show()
{
(BaseUrl + "/" + categoryId).ShouldMapTo<CategoryController>(x => x.Show(categoryId));
}
[Test]
public void Edit()
{
(BaseUrl + string.Format("/{0}/edit", categoryId)).ShouldMapTo<CategoryController>(x => x.Edit(categoryId));
}
}
The base class just takes care of initialising the routes collection from the MvcApplication.