我正在使用MvcContrib-TestHelper在我的應用程序上測試路由。我有僅限於HTTP POST動作:如何測試MVC操作只能通過HTTP POST訪問?
public TestController { [HttpPost] public ActionResult Example() { return View(); } }
這裏是一個測試的例子應該失敗:
[TestFixture] public class RoutingTests { [TestFixtureSetUp] public void TestFixtureSetUp() { RouteTable.Routes.Clear(); Application.RegisterRoutes(RouteTable.Routes); } [Test] public void TestWithGet() { var route = "~/Test/Example".WithMethod(HttpVerbs.Get); route.ShouldMapTo(r => r.Example()); } }
然而,測試通過!我已經看到了另一個未答覆的問題(對不起,錯誤的鏈接),這也引發了這種問題,而且看起來功能已經被破壞了。測試此路線是否僅通過POST可訪問的更好方法是什麼?
無論[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]之間的區別如何,它都可以工作嗎? – sargant
檢查出來。我幾乎90%確定這是相同的 – Mediator
鑑於它的測試,它分別看到AcceptVerbsAttribute和HttpPostAttribute。反射可能就像我會得到的那樣 - 我會看看是否有更接近實際分析路由信息的方式,如果沒有,我很快就會接受這個答案。謝謝! – sargant