title: How can I mock a method that returns a Task<IList<>>?
body: <p>I am trying to unit test a method that returns a Task>:</p>
  
  <pre><code>void Main()
  {
      var mockRepo = new Mock&lt;IRepository&gt;();
      mockRepo.Setup(x =&gt; x.GetAll()).Returns(new List&lt;MyModel&gt;() { new MyModel { Name = "Test" } });  // works
  
      mockRepo.Setup(x =&gt; x.GetAllAsync()).Returns(Task.FromResult(new List&lt;MyModel&gt;() { new MyModel { Name = "Test" } }));  // error
  
      var result = mockRepo.Object.GetAll();
      result.Dump();
  }
  
  public interface IRepository
  {
      Task&lt;IList&lt;MyModel&gt;&gt; GetAllAsync();
      IList&lt;MyModel&gt; GetAll();
  }
  
  public class MyModel
  {
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>But the Task returning method generates a compiler error:</p>
  
  <blockquote>
    <p>CS1503 Argument 1: cannot convert from
    'System.Threading.Tasks.Task&lt;System.Collections.Generic.List&lt;UserQuery.MyModel&gt;'
    to
    'System.Threading.Tasks.Task&lt;System.Collections.Generic.IList&lt;UserQuery.MyModel&gt;'</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>