title: .NET Core Xunit - IActionResult' does not contain a definition for 'StatusCode'
body: <p>I have an API written in .NET Core and using xUnit to test those.</p>
  
  <p>I have my method in API as:</p>
  
  <pre><code>[HttpDelete("api/{id}")]
  public async Task&lt;IActionResult&gt; DeleteUserId(string id)
  {
     try
      {
         //deleting from db       
      }
      catch (Exception ex)
      {           
          return StatusCode(500, ex.Message);
      }       
  }
  </code></pre>
  
  <p>I want to write a unit test when null/empty id passed to this method. </p>
  
  <p>I have my test case as:</p>
  
  <pre><code>[Fact]
  public void DeleteUserId_Test()
  {
      //populate db and controller here
  
      var response= _myController.DeleteUserId("");  //trying to pass empty id here
  
      // Assert
      Assert.IsType&lt;OkObjectResult&gt;(response);
  }
  </code></pre>
  
  <p>How can I check the status code 500 is returned from my controller method call here. Something like</p>
  
  <pre><code>Assert.Equal(500, response.StatusCode);
  </code></pre>
  
  <p>While debugging I can see response has Result return type (Microsoft.AspNetCore.Mvc.ObjectResult) which has <code>StatusCode</code> as 500.</p>
  
  <p>But when I try to do this:</p>
  
  <pre><code>response.StatusCode
  </code></pre>
  
  <p>It throws me error: </p>
  
  <blockquote>
    <p>'IActionResult' does not contain a definition for 'StatusCode' and no extension method 'StatusCode' accepting a first argument of type 'IActionResult' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>How can I resolve this?</p>