title: How to test asp.net core 1.1 mvc actions returing razor views using microsoft.aspnetcore.testhost
body: <p>Using Microsoft.aspnetcore.testhost I am unable to make http get to controller action returning razor view. I need to test the response has specific security headers and have other test I would like to perform on the action responses.
  Razor throws compilation exceptions for every namespace it hits, not just the system example below:</p>
  
  <pre><code>oclq12bb.ugz(5,11): error CS0246: The type or namespace name 'System' could
  not be found (are you missing a using directive or an assembly reference?)
  oclq12bb.ugz(6,11): error CS0246: The type or namespace name 'System' could
  not be found (are you missing a using directive or an assembly reference?)
  </code></pre>
  
  <p>Repro:</p>
  
  <ul>
  <li>Using visual studio 2017 create a new asp.net core 1.1 web project
  and add a .net core unit test project.</li>
  <li>Remove the appsettings from startup.</li>
  <li>Set view /home/index.cshtml to copy to output directory to "copy always".</li>
  <li>create and run unit test. Throws exception.</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>[TestClass]
  public class UnitTest1
  {
      private readonly HttpClient _client;
  
      public UnitTest1()
      {
          var server = new TestServer(
              new WebHostBuilder().UseStartup&lt;Startup&gt;());
          _client = server.CreateClient();
      }
  
      [TestMethod]
      public async Task Test1()
      {
          var response = await _client.GetAsync("/");
      }
  }
  </code></pre>
  
  <p>I have tried publishing the web project to a folder and using the .UseContentRoot() in place of copy always. Same result.</p>