Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created December 24, 2012 00:56
Show Gist options
  • Select an option

  • Save JakeGinnivan/4366936 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/4366936 to your computer and use it in GitHub Desktop.
public static void ReturnsValueAsTask<T>(this Task<T> value, T returnThis, params T[] returnThese)
{
Returns(MatchArgs.AsSpecifiedInCall, ToCompletedTask(returnThis), returnThese.Select(ToCompletedTask).ToArray());
}
public static void ReturnsValueAsTask<T>(this Task<T> value, Func<CallInfo, T> returnThis)
{
Returns(MatchArgs.AsSpecifiedInCall, c => ToCompletedTask(returnThis(c)));
}
private static Task<T> ToCompletedTask<T>(T value)
{
var taskCompletionSource = new TaskCompletionSource<T>();
taskCompletionSource.SetResult(value);
return taskCompletionSource.Task;
}
@MNF
Copy link
Copy Markdown

MNF commented Aug 1, 2013

Hi Jake.
Do you have examples how these extensions can be called?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment