title: routing and integration testing webapi via selfhosting
body: <p>I am using this code:</p>
  
  <pre><code>[Fact]
  public void ValueController_WithGetMethos_ShouldReturnValidData_NoBaseClass()
  {
      var configuration = new HttpSelfHostConfiguration("http://localhost:64466");
      configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
      configuration.Services.Replace(typeof(IAssembliesResolver), new WebApiClassBase.TestAssemblyResolver(typeof(ValuesController)));
  
              configuration.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
  
      var server = new HttpSelfHostServer(configuration);
      try
      {
      server.OpenAsync().Wait();
  
      var request = new HttpRequestMessage
      {
          RequestUri = new Uri("http://localhost:64466/api/values"),
          Method = HttpMethod.Get
      };
  
      var client = new HttpClient(server);
      using (HttpResponseMessage response = client.SendAsync(request).Result)
      {
          response.Should().Not.Be.Null();
          response.IsSuccessStatusCode.Should().Be.True();
  
          string[] result = response.Content.ReadAsAsync&lt;string[]&gt;().Result;
  
          result.Length.Should().Be.EqualTo(4);
          result[0].Should().Be.EqualTo("http://tostring.it");
          result[1].Should().Be.EqualTo("http://imperugo.tostring.it");
          result[2].Should().Be.EqualTo("http://twitter.com/imperugo");
          result[3].Should().Be.EqualTo("http://www.linkedin.com/in/imperugo");
      }
      }
      finally
      {
      configuration.Dispose();
      server.Dispose();
      }
  }
  </code></pre>
  
  <p>Inspired by <a href="https://github.com/imperugo/Spike/blob/master/imperugo.webapi.selfhost/imperugo.webapi.integrationTest/ValuesControllerWithoutBaseClass.cs" rel="nofollow">this</a>, which also contains the relevant <a href="https://github.com/imperugo/Spike/blob/master/imperugo.webapi.selfhost/imperugo.webapi.selfhost/Controller/ValuesController.cs" rel="nofollow">ValuesController</a>. I have noticed that I had to adapt the routing:</p>
  
  <pre><code>configuration.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new { id = RouteParameter.Optional }
  );
  </code></pre>
  
  <p>according to the one in my WebApiConfig. However, when I try to access an Action with attribute routing like this:</p>
  
  <pre><code>Route("Calculator/AddTwoNumbers/a/{a}/b/{a}")]
  public IHttpActionResult AddTwoNumbers(PayLoad payLoad)
  </code></pre>
  
  <p>I get an 404 - Not found error. Do I also have to define this declarative routing? If so, integration testing seems quite tedious. Any feedback would be very much appreciated. Thanks. </p>
  
  <p>PS:</p>
  
  <p>I tried:</p>
  
  <pre><code>configuration.MapHttpAttributeRoutes();
  </code></pre>
  
  <p>which does not seem to help</p>