I had a tricky idea of ββusing a dynamic variable to check the results of a method that returns an anonymous type - more precisely, it returns a JsonResult, which, like json, looks like
{ "newData" : [ 1120741.2697475906, 826527.64681837813 ], "oldData" : [ 1849870.2326665826, 1763440.5884212805 ], "timeSteps" : [ 0, 4.8828124999999998e-10 ], "total" : 2 }
I can read JSonResult which will give me an anonymous type. Here is my code:
var jsonResult = controller.GetChangeData(1) as JsonResult; dynamic data = jsonResult.Data; Assert.AreEqual(2, data.total);
But how do I get, for example, in "newData"? This code is ....
var newData = data.newData;
Gives me System.Linq.Enumerable.WhereSelectArrayIterator, but I do not know what to do with it in order to be able to use it as a double digit.
I tried to make it as double [], but it does not work either.
As an aside, can I easily check if a property is defined in a dynamic?
source share