Reputation: 85
I come across on this test method in NUnit services tests in project I am working at a moment
[Test]
public void FindAsync_By_Using_Some_Condition()
{
//code omitted for clarity ...
var results = Repository.FindAsync(workClients);
results.Wait(TimeSpan.FromSeconds(1));
Assert.AreEqual(2, results.Result.Count);
}
public async Task<ICollection<T>> FindAsync( FindOptions<T> options )
{
var output = new List<T>();
//code omitted for clarity ...
return await Task.FromResult(output);
}
where they have been using Task.Wait before they did assertion. Any particular reason why it was done this way? What would have happened if they omitted Task.Wait (TimeSpan.FromSeconds(1))?
And why FindAsync_By_Using_Some_Condition() is not used in conjunction with async / await keywords?
Upvotes: 0
Views: 2755
Reputation: 22647
The test was probably written before NUnit supported async. With NUnit 2.6.4 or 3.x, it could now be rewritten,
[Test]
public async Task FindAsync_By_Using_Some_Condition()
{
var results = await Repository.FindAsync(workClients);
Assert.AreEqual(2, results.Count);
}
Upvotes: 3