title: How to Moq a Task.WhenAll()
body: <p>I currently have a function that creates an array of <strong>responses</strong>. As you can see in my code down below I am running a <strong>Task.WhenAll</strong> this will grab each object in my arrayOfRequests and run it through my <strong>FunctionThatCreatesResponse</strong> returning the response for <strong>EACH</strong> object in the <strong>arrayOfRequests</strong></p>
  
  <pre><code>var arrayOfRequests = new [] { RequestObject1, RequestObject2, RequestObject3 }
  var arrayOfResponses = await Task.WhenAll(arrayOfRequests.Select(req =&gt; FunctionThatCreatesResponse(req)));
  
  private async Task&lt;ResponseObject&gt; FunctionThatCreatesResponse(RequestObject req)
  {
      // The response will be created here and returned
  }
  </code></pre>
  
  <p>How can I mock the <em>task.WhenAll()</em> to return a pre defined <strong>arrayOfResponses</strong>?</p>
  
  <p>Something along the lines of:</p>
  
  <pre><code>var task = new Mock&lt;Task&gt;();
  task.Setup(t =&gt; t.WhenAll()).ReturnsAsync(arrayOfResponses);
  </code></pre>