mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 18:35:35 +00:00
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:
@@ -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; });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user