title: Web API Unit test for exception?
body: <p>I wrote a unit test for exception. But looks like it is not working correctly. It is always saying '404 Not Found' Status. that means url request not found. If I paste same url on browser it <code>HttpResponse.StatusCode</code> says <code>BAD REQUEST</code>. </p>
  
  <p>I don't understand why it is not working for Unit test.</p>
  
  <pre><code>[TestMethod()]
      public void GetTechDisciplinesTestException()
      {
          var config = new HttpSelfHostConfiguration("http://localhost:51546/");
          config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
          using (var server = new HttpSelfHostServer(config))
          using (var client = new HttpClient())
          {
              server.OpenAsync().Wait();
              using (var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:51546/api/techdisciplines/''"))
              using (var response = client.SendAsync(request).Result)
              {
                  //Here Response Status Code says 'Not Found', 
                  //Suppose to be 'Bad Request`
                  Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
              }
              server.CloseAsync().Wait();
          };
      }
  </code></pre>
  
  <p>I tried with <code>HttpSelfHostServer</code> which works fine and it uses IISExpress.</p>
  
  <pre><code> [TestMethod()]
      public void GetTechDisciplinesTestException()
      {
  
          using (var client = new HttpClient())
          {               
              using (var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:51546/api/techdisciplines/''"))
              using (var response = client.SendAsync(request).Result)
              {
                  Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
              }               
          };
      }
  </code></pre>
  
  <p>So I dont know <code>HttpSelfHostServer</code> is not wkring in the code? How to force <code>HttpSelfHostServer</code> to use <code>IISExpress</code>?  How to deal this?</p>