I am trying to just return a very simple Anonymous object as Json like so:
[HttpGet]
public JsonResult GetJson()
{
return Json(new {
id = 1,
child = new
{
id = 12,
name = "woop woop"
}
});
}
Then I have a test case that verify that id = 1
[TestMethod]
public void TestMethod4()
{
var controller = new ValuesController();
dynamic result = controller.GetJson();
Assert.AreEqual(1, result.Value.id);
}
This result in:
Message: Test method UnitTestProject1.UnitTest1.TestMethod4 threw exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'id'