I have this controller method:
[GET("/whatever/list")]
public ActionResult Index(string sortby, string order)
I'm trying to test it with MvcContrib route testing:
"~/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 parameter 'sortby' did not match: expected '' but was ''; no value found in the route context action parameter named 'sortby' - does your matching route contain a token called 'sortby'?
What am I missing?
Based on the assert message (
expected '' but was '';so one of the values isnullorstring.Emptyin the assertation) your first test is failing, because you usedstring.Emptybut the default value for string isnullChange your assert to use
nulland it should wotk: