title: How to handle exceptions thrown by Tasks in xUnit .net's Assert.Throws<T>?
body: <p>The following asynchronous <code>xUnit.net</code> test with a <code>lambda</code> marked with the <code>async</code> modifier fails by reporting that no exception was thrown:</p>
  
  <pre><code>    [Theory, AutoWebData]
      public async Task SearchWithNullQueryThrows(
          SearchService sut,
          CancellationToken dummyToken)
      {
          // Fixture setup
          // Exercise system and verify outcome
          Assert.Throws&lt;ArgumentNullException&gt;(async () =&gt;
              await sut.SearchAsync(null, dummyToken));
          // Teardown
      }
  </code></pre>
  
  <p>To make sure that an <code>ArgumentNullException</code> is actually thrown I explicitly used a <code>try-catch</code> block. It worked, however the resulting code is not clean (compared to the first test):</p>
  
  <pre><code>[Theory, AutoWebData]
  public async Task SearchWithNullQueryThrows(
      SearchService sut,
      CancellationToken dummyToken)
  {
      // Fixture setup
      var expected = typeof(ArgumentNullException);
      Type actual = null;
      // Exercise system
      try
      {
          await sut.SearchAsync(null, dummyToken);
      }
      catch (ArgumentNullException e)
      {
          actual = e.GetType();
      }
      // Verify outcome
      Assert.Equal(expected, actual);
      // Teardown
  }
  </code></pre>
  
  <p>Why the <code>Assert.Throws&lt;T&gt;</code> with the <code>lambda</code> marked with the <code>async</code> modifier fails?</p>