C# - how to create a successfully completed task with a result

Tasks can be a bit of a pain when writing tests, especially when a dependency returns a task. Often it is just enough to return a completed one. This can be done easily with a one-liner in C#. Using Task.FromResult() you can easily get a successfully completed task with a result:

var completedTask = Task.FromResult<string>("SomeResult");

The above Creates and completes a task in the same line. You can then go ahead and use .Result to get the returned string.

I hope this helps someone out there! Let me know if it did.