Ich versuche, einige Integrationstests für eine MVC-Anwendung zu schreiben, wieQuerying JsonResult in C# Integrationstests
-Controller folgt
public JsonResult CreateWithJson(List<string> values)
{
if (values == null) return Json(new { Valid = false, Message = "No data was received by the server" });
}
Testklasse
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);
}
So wie ich abfragen der anonyme Typ zurückgegeben in der JsonResult bitte?
könnte dies helfen: http: //stackoverflow.com/questions/17232470/how-to-access-jsonresult-data-when-testing-in-asp-net-mvc –