I am trying to write test methods for Route entries and in my route config there were a lot of entries for different action. I am using MvcContrib.TestHelper for Testing . I am new to MVC as well as TDD. Kindly help me to solve this issue. My test case is failing and what can I do to make it pass .
Route Entry
routes.MapRoute(
name: "X1Details",
url: "X1/{X1ID}",
defaults: new { controller = "X1", action = "Index", X1ID = "X1ID" }
);
X1Controller
public ActionResult Index(int? instanceID = 0, string InfoMsg ="")
{
}
Test Method
[Test Method]
public void Should_Route_X1Index()
{
"~/X1/"
.ShouldMapTo<X1Controller>(action => action.Index(null, ""));
}
Error
Test method
XXX.Tests.MVCContibRouteMapTest.Should_Route_X1IndexOf
threw exception: MvcContrib.TestHelper.AssertionException: Value for
parameter ‘InfoMsg’ did not match: expected ” but was ”; no value
found in the route context action parameter named ‘InfoMsg’ – does
your matching route contain a token called ‘InfoMsg’?
Thanks in advance.
Default values don’t work well with MVCContrib helper. You could modify your controller action like so:
and then: