How to unit test an Action method which returns JsonResult?

前端 未结 8 1937
我在风中等你
我在风中等你 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:54

    This is how I assert it

    foreach (var item in jsonResult.Data as dynamic) {
        ((int)item.Id).ShouldBe( expected Id value );
        ((string)item.name).ShouldBe( "expected name value" );
    }
    

提交回复
热议问题