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