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.

Jon Skeet
people
quotationmark

Just parse the JSON, e.g. using Json.NET:

JsonResult result = testController.GetStatuses();
string json = (string) result.Data;
List<Status> statuses = JsonConvert.DeserializeObject<List<Status>>(json);
// Check statuses

people

See more on this question at Stackoverflow