How to check MVC route with additional querystring options

I have this controller method:

[GET("/whatever/list")]
public ActionResult Index(string sortby, string order)

I am trying to verify it using the MvcContrib route test:

"~/whatever/list".ShouldMapTo<MyController>(c => c.Index(string.Empty, string.Empty));
"~/whatever/list?sortby=type&order=desc".ShouldMapTo<MyController>(c => c.Index("type", "desc"));

However, it returns this error.

Failure: MvcContrib.TestHelper.AssertionException: value for "sortby" did not match: expected '', but was ''; it doesn't matter if it’s found in the route context action parameter named "sortby" - does your corresponding route contain a token called "sortby"?

What am I missing?

+5
source share
2 answers

assert (expected '' but was '';, : null string.Empty ) , string.Empty, null

null, wotk:

"~/whatever/list".ShouldMapTo<MyController>(c => c.Index(null, null));
+3

var route = "~/whatever/list".WithMethod(HttpVerbs.Get);
route.Values.Add("sortby", "type");
route.Values.Add("order", "desc");
route.ShouldMapTo<MyController>(c => c.Index("type", "desc"));
+2

All Articles