title: Test Exceptions in Xunit ()
body: <p>I am trying to write Xunit test on this method:</p>
  
  <pre><code>public async Task&lt;IEnumerable&lt;T&gt;&gt; RunSQLQueryAsync(string queryString)
  {
      try
      {
          //do something
      }
      catch (DocumentClientException e)
      {
          throw new InvalidOperationException(e);
      }
  
  }
  </code></pre>
  
  <p>Here's the unit test:</p>
  
  <pre><code>[Fact]
  public async virtual Task Test_Exception()
  {
      var queryString = "SELECT * FROM c";
      var exception = Record.ExceptionAsync(async () =&gt; await classname.RunSQLQueryAsync(queryString));
      Assert.NotNull(exception);
      Assert.IsType&lt;DocumentClientException&gt;(exception);
  }
  </code></pre>
  
  <p>But the method failed and it says:</p>
  
  <blockquote>
    <p>Message: Assert.IsType() Failure Expected: System.DocumentClientException Actual:<br>
    System.Threading.Tasks.Task`1[[System.Exception,
    System.Private.CoreLib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=xxx]]</p>
  </blockquote>
  
  <p><strong>When I debugged the test, it doesn't go to the catch block.</strong> So my question is how to make the unit test expects the method <code>RunSQLQueryAsync</code> to have <code>DocumentClientException</code>?</p>