I've a method in my controller with this signature
public async Task<ViewResult> Index()
This is what I'm doing in my unit test to wait for the result of Index()
[TestMethod]
public void TestIndex()
{
var controller = new MyController();
var result = controller.Index().Result;
// Asserts here
}
But the documentation say that the way to test async methods is using async Task in the signature of the test method and using await like this
public async Task TestIndex()
{
var controller = new MyController();
var result = await controller.Index();
// Asserts here
}
I really want to know what is the difference between the way the documentation say and the way I'm doing it?
What's wrong doing the test the way I'm doing it?
PS: Even the exceptions thrown in the Index method are shown in the Test Explorer window.