Testing the action of the controller returning JsonResult should not be different from testing other actions. Consider the following scenario:
public class MyModel
{
public string Name { get; set; }
}
public class HomeController : Controller
{
public ActionResult Index()
{
return Json(new MyModel { Name = "Hello World" });
}
}
unit test (, MSTest, NUnit atm, ):
var sut = new HomeController();
var actual = sut.Index();
Assert.IsInstanceOfType(actual, typeof(JsonResult));
var jsonResult = (JsonResult)actual;
Assert.IsInstanceOfType(jsonResult.Data, typeof(MyModel));
var model = (MyModel)jsonResult.Data;
Assert.AreEqual("Hello World", model.Name);