jeudi 3 septembre 2015

Unit Testing Json Result

In my controller I have the following Json method:

[HttpPost]
public JsonResult GetStatuses()
{
    var allItems = rep.GetStatuses()
            .OrderBy(i => i.Name)
            .Select(i => i.Name);

    return Json(new { Items = allItems });
}

The method GetStatuses returns a list of statuses ( List ).

In my unit test I get the result:

JsonResult result = testController.GetStatuses() as JsonResult;

But I do not know how to deserialize the result back to List so that I can interrogate the results.

Aucun commentaire:

Enregistrer un commentaire