Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Last active August 29, 2015 14:15
Show Gist options
  • Save johnmmoss/18fcfd1a880b4ffe1ed4 to your computer and use it in GitHub Desktop.
Save johnmmoss/18fcfd1a880b4ffe1ed4 to your computer and use it in GitHub Desktop.
Rhino Mock Async Considerations
public void AsyncExamples()
{
// Async controller actions have to be called asyn:
await controller.Create(model);
// Async methods return a task, so use Task.FromResult:
_apiClient.Stub(x => x.GetCustomersAsync(Arg<long>.Is.Anything))
.Return(Task.FromResult(new List<Customer>()));
// If the method returns just Task and not Task<T> use true/null/1:
_file.Stub(x => x.SavePostedFile(Arg<HttpPostedFileBase>.Is.Anything))
.Return(Task.FromResult(true));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment