title: AspNet Core Integration test - MethodNotAllowed Response
body: <p>I have created a webapi project with GET, POST, PUT routes which run fine in the postman. But when I've made integration test, only GET and POST routes are passing. When making PUT request in integration test, it throws MethodNotAllowed Error (405 - Method not allowed).</p>
  
  <p>System: Ubuntu 18.10
  dotnet version: 2.2.100</p>
  
  <p>Any advice/direction would be much appreciated.</p>
  
  <pre><code>namespace TestingMvc.Tests {
  public class JsonContent : StringContent {
      public JsonContent (object obj):
          base (JsonConvert.SerializeObject (obj), Encoding.UTF8, "application/json") { }
  }
  
  public class MyTest : IClassFixture&lt;WebApplicationFactory&lt;WebApi.Startup&gt;&gt; {
      private readonly WebApplicationFactory&lt;WebApi.Startup&gt; _factory;
  
      public MyTest (WebApplicationFactory&lt;WebApi.Startup&gt; factory) {
          _factory = factory;
      }
  
      // This is Ok -&gt; Returns 200
      [Fact]
      public async Task Get_Attachments () {
          var client = _factory.CreateClient ();
          var response = await client.GetAsync ("/attachments");
          Assert.Equal (HttpStatusCode.OK, response.StatusCode);
      }
  
      // This is Ok -&gt; returns 200
      [Fact]
      public async Task Post_Attachments () {
          var client = _factory.CreateClient ();
          var response = await client.PostAsync ("/attachments", new JsonContent(new { a = "foobaz" }));
          Assert.Equal (HttpStatusCode.OK, response.StatusCode);
      }
  
      // This is not ok -&gt; returns 405 Method not allowed
      [Fact]
      public async Task Put_Attachments () {
          var client = _factory.CreateClient ();
          var response = await client.PutAsync ("/attachments", new JsonContent(new { a = "foobaz" }));
          Assert.Equal (HttpStatusCode.OK, response.StatusCode);
      }
  }
  }
  </code></pre>
  
  <p>Startup.cs</p>
  
  <pre><code>    public void ConfigureServices (IServiceCollection services) {
          services.AddCors ();
          services.AddMvc ().SetCompatibilityVersion (CompatibilityVersion.Version_2_2);
      }
  
      public void Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
          app.ConfigureExceptionHandler ();
          app.UseCors (x =&gt; x
              .AllowAnyOrigin ()
              .AllowAnyMethod ()
              .AllowAnyHeader ()
              .AllowCredentials ());
          app.UseMvc ();
      }
  </code></pre>
  
  <p>WebApiTest.csproj</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk.Web"&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp2.2&lt;/TargetFramework&gt;
      &lt;IsPackable&gt;false&lt;/IsPackable&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" /&gt;
      &lt;PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /&gt;
      &lt;PackageReference Include="xunit" Version="2.2.0" /&gt;
      &lt;PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;ProjectReference Include="../src/WebApi.csproj" /&gt;
  &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>Console output:</p>
  
  <pre><code>info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
        Request starting HTTP/2.0 PUT http://localhost/attachments application/json; charset=utf-8 
  dbug: TestingMvc.Tests.TestAuthenticationHandler[8]
        AuthenticationScheme: Test Scheme was successfully authenticated.
  info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
        Executing endpoint '405 HTTP Method Not Supported'
  info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
        Executed endpoint '405 HTTP Method Not Supported'
  info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
        Request finished in 236.9092ms 405 
  </code></pre>