Using MSTest, when I try to run a test that has a type of dynamic that is a container of a JSON object (from an API Query) I am ment to be able to dereference the JSON elements in the commented out be below, but it fails, where as treating it as an item collection it seems ok. If inspect '(jsonResponse.message)' it has a value of "Hi" - but it wont work in a Unit Test. Why is that?
// http://www.newtonsoft.com/json/help/html/LINQtoJSON.htm // Deserialize json object into dynamic object using Json.net
[TestMethod]
public void DynamicDeserialization()
{
dynamic jsonResponse = JsonConvert.DeserializeObject("{\"message\":\"Hi\"}");
JObject d = JObject.Parse("{\"message\":\"Hi\"}");
Assert.IsTrue((string)d["message"] == "Hi"); // Is ok
// Assert.IsTrue(jsonResponse.message.ToString() == "Hi"); // is not ok
}