Unit test for a collection of anonymous JSON objects
This question was inspired by this excellent example . I have ASP.NET Core MVC application and I am writing unit tests for the controller. One of the methods returns JsonResult with a collection of anonymous types. I can get to each element of the collection. I can also assert values in each element like this: Dictionary<int, string> expectedValues = new Dictionary<int, string> { { 1, "Welcome Tester"}, { 2, "Namaste Tester"}, { 3, "Privet Tester"}, { 4, "Labdien Tester"} }; foreach (dynamic value in jsonCollection) { dynamic json = new DynamicObjectResultValue(value); Assert.Equal