Unit testing ASP.NET MVC redirection

前端 未结 4 1931
南笙
南笙 2021-02-05 09:50

How do I Unit Test a MVC redirection?

public ActionResult Create(Product product)
{
    _productTask.Save(product);
    return RedirectToAction(\"Success\");   
         


        
4条回答
  •  半阙折子戏
    2021-02-05 10:36

    You can assert on the ActionResult that is returned, you'll need to cast it to the appropriate type but it does allow you to use state-based testing. A search on the Web should find some useful links, here's just one though.

提交回复
热议问题