Files
octokit.net/Octokit.Tests/Helpers/NSubstituteExtensions.cs
2020-03-31 16:57:16 -03:00

20 lines
628 B
C#

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.FromResult(returnThis(callInfo)));
}
public static ConfiguredCall ThrowsAsync<T>(this Task<T> value, Exception exception)
{
return value.ReturnsAsync<Task<T>, T>(callInfo => { throw exception; });
}
}