Await calls with try/catch

In 451eddc647 we were a little overzealous
in removing async/await calls. Anywhere we do a try/catch around a
method that returns a Task, we need to use await.
This commit is contained in:
Haacked
2014-03-21 11:14:22 -07:00
parent 5f6181cfa6
commit b56613b99b
6 changed files with 30 additions and 10 deletions
@@ -0,0 +1,19 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using NSubstitute.Core;
public static class NSubstituteExtensions
{
public static ConfiguredCall ReturnsAsync<TTask, TTaskType>(
this TTask value, Func<CallInfo, TTaskType> returnThis,
params Func<CallInfo, TTaskType>[] returnThese) where TTask : Task<TTaskType>
{
return value.Returns(callInfo => Task.Factory.StartNew(() => returnThis(callInfo)));
}
public static ConfiguredCall ThrowsAsync<T>(this Task<T> value, Exception exception)
{
return value.ReturnsAsync<Task<T>, T>(callInfo => { throw exception; });
}
}