title: How do you unit test ASP.NET Core MVC Controllers that return anonymous objects?
body: <p>I'm having trouble unit testing ASP.NET Core MVC controllers that return anonymous objects. The unit testing is set up in a separate project and calls the controller methods from the main project directly.</p>
  
  <p>The controller methods return <code>IActionResult</code> but typically these are <code>OkObjectResult</code> and <code>BadRequestObjectResult</code> objects that get translated into a JSON response with the appropriate HTTP status code. The anonymous objects are passed as the constructor parameters for the <code>ObjectResult</code> objects and it is these I'm trying to make assertions against (accessible via <code>ObjectResult.Value</code>).</p>
  
  <p>I found this question (<a href="https://stackoverflow.com/questions/34742454/how-can-i-access-internals-in-asp-net-5">how can i access internals in asp.net 5</a>) that has an answer that says to use dynamics and add</p>
  
  <pre><code>[assembly: InternalsVisibleTo("Namespace")]
  </code></pre>
  
  <p>to AssemblyInfo.cs to allow the test project access to the internal object properties of the anonymous objects. However, latest versions of ASP.NET Core MVC do not have AssemblyInfo.cs and adding one as suggested in the answers to the linked question does not work either.</p>
  
  <p>Is there now a different location to add the <code>InternalsVisibleTo</code> or am I missing something?</p>