1
我試圖寫一個MVC應用程序的一些集成測試如下查詢JsonResult在C#集成測試
控制器
public JsonResult CreateWithJson(List<string> values)
{
if (values == null) return Json(new { Valid = false, Message = "No data was received by the server" });
}
測試類
public static void TestEmptyDataFailsGracefully()
{
var objUt = new MyController();
var actual = objUt.CreateWithJson(new List<string>());
actual.Should().BeOfType(typeof(JsonResult));
// this is System.Object
actual.Data...
// what I want to do
actual.Data.Valid.Should.Be(false);
}
那麼,如何查詢請在JsonResult中返回匿名類型?
這可能幫助:HTTP://stackoverflow.com/questions/17232470/how-to-access-jsonresult-data-when-testing-in-asp-net-mvc –