I have a method that returns
return new System.Web.Mvc.JsonResult()
{
Data = new
{
Status = "OK",
}
}
I need to write a unit test where I need to verify that jsonResult.Data.status= "OK"
.
How do I read the status property?
Update: I tried the [assembly: InternalsVisibleTo("TestingAssemblyName")], but that didn't help. I kept getting the error {"'System.Web.Mvc.JsonResult' does not contain a definition for 'Status'"}
Besides I think I will prefer not modifying the code that I am testing.
So I took Jon's advice and used reflection.
var type = jsonResult.Data.GetType();
var pinfo = type.GetProperty("Status");
string statusValue = pinfo.GetValue(jsonResult.Data,null).ToString();
Assert.AreEqual("OK", statusValue);