2.2. Returning Completed Tasks
Problem
You need to implement a synchronous method with an asynchronous signature. This situation can arise if you are inheriting from an asynchronous interface or base class but wish to implement it synchronously. This technique is particularly useful when unit testing asynchronous code, when you need a simple stub or mock for an asynchronous interface.
Solution
You can use Task.FromResult to create and return a new Task<T> that is already completed with the specified value: