Faking async methods
The faking of async
methods is fully supported in FakeItEasy.
A call to a non-configured async method on a fake will return a
Dummy Task
or Task<T>
, just
as if it were any other method that returns a Task
or
Task<T>
1. For example:
var foo = A.Fake<Foo>();
var bar = await foo.Bar(); // will return immediately and return string.Empty
Of course, you can still configure calls to async
methods as you would normally:
- In FakeItEasy 1.12 or earlier, the
Task
returned from a non-configured fake method would never be completed and theawait
would never be satisfied. If you are using 1.12 or earlier, upgrade now.