我有這樣的控制方法:如何測試可選查詢字符串的MVC路由參數
[GET("/whatever/list")]
public ActionResult Index(string sortby, string order)
我試圖用MvcContrib路線測試,以測試它:
"~/whatever/list".ShouldMapTo<MyController>(c => c.Index(string.Empty, string.Empty));
"~/whatever/list?sortby=type&order=desc".ShouldMapTo<MyController>(c => c.Index("type", "desc"));
但是,它返回錯誤。
失敗:MvcContrib.TestHelper.AssertionException:價值 參數 'sortby' 不匹配:預期 '' 但 '';沒有值 在名爲'sortby'的路由上下文動作參數中找到 - 您的 匹配路由是否包含名爲'sortby'的令牌?
我錯過了什麼?
我認爲第一個測試失敗::'「〜/ whatever/list」.ShouldMapTo(c => c.Index(string.Empty,string.Empty));'嘗試用'null'而不是' string.Empty'因爲'null'是'string'的默認值。 –
nemesv
如果你是這樣做的答案,我會標記它的答案。這似乎是這樣做的,我不知道爲什麼這沒有打我。 –