How to unit test an Action method which returns JsonResult?

前端 未结 8 1920
我在风中等你
我在风中等你 2020-12-13 12:38

If I have a controller like this:

[HttpPost]
public JsonResult FindStuff(string query) 
{
   var results = _repo.GetStuff(query);
   var jsonResult = results         


        
8条回答
  •  自闭症患者
    2020-12-13 12:56

    If in the test you know what exactly the Json data result should be then you can just do something like this:

    result.Data.ToString().Should().Be(new { param = value}.ToString());
    

    P.S. This would be if you had used FluentAssertions.Mvc5 - but it shouldn't be hard to convert it to whatever testing tools you use.

提交回复
热议问题