While writing unit test I got problem with JsonResult.Data.
It looks in debuger like that: jsonResult.Data { success = false, message = "some string" } it's annonymous type
-> success : false : bool -> message : "some string" : string
So I cast data to dynamic to do that: dynamic jsonData = jsonResult.Data;
and in debugger it shows that jsonData have property success and message.
Assert.False(jsonData.success) // throws exception RuntimeBinderException about that jsonData do not have success property.
But when I have collection in jsonData I can do this: jsonData.Data[0].success // thats work.
Anyone can help?
Code: SomeMethod retuns
return Json(new { success = false, message = "Some string" });
var jsonResult = this._controller.SomeMethod(null);
dynamic jsonData = jsonResult.Data;
Assert.NotNull(jsonResult);
Assert.False(jsonData.success);