Mvc Route Tester - ITsvetkoFF/Kv-013 GitHub Wiki

Mvc Route Tester

About

MvcRouteTester is a .Net library to help unit testing ASP MVC route tables. It contains asserts for both regular controllers and the Api controllers. It is built in .Net 4.0 and ASP MVC 5.2 and some older versions. It can be used with a simple or a fluent syntax, e.g either RouteAssert.HasRoute(routes, "/home/index"); or routes.ShouldMap("/home/index").To(x => x.Index()); This library is Open Source and you are welcome to use it as you see fit.

Use

Library allows unit tests on routes. Without such a library, the only way to automate a test that your ASP MVC application responds to a certain route is to make an integration test which fires up the whole MVC application in a web server and issues a Http request to that URL. Unit tests run faster, easier to configure, are less fragile and generally come earlier in the coding life-cycle, so there are good reasons to use unit tests as a first line of defence against route configuration errors.

How it works

MvcRouteTester throws an exception in order to fail a test on a route. This should work in any unit testing framework. For closer integration with particular unit testing framework here is an example how to do it.

How to install

In NuGet Package Manager find MvcRouteTester and install it

Useful links

More detailed documentation

Integrating with NUnit and other unit testing frameworks