title: How to return a Task<string> using Moq?
body: <p>I am using <code>XUnit</code> and <code>Moq</code> to test code from my logic layer. My logic layer also communicates with the data layer, so I want to mock the interface to keep my test simple.</p>
  <p>I am wondering how I should return a <code>Task&lt;string&gt;</code> when I call the async Task method. My <code>GetOrder</code> method calls <code>GetOrderById</code> but the data layer method returns null.<br/></p>
  <p><strong>Edit:</strong> I changed my unit test based on all the feedback. It works fine now.<br/>
  <strong>My test</strong>:</p>
  <pre><code>public async void GetOrder()
  {
      //Arrange 
      string expected = &quot;test&quot;;
      
      var mock = new Mock&lt;IRepository&gt;();
      mock.Setup(arg =&gt; arg.GetOrderNameById(It.IsAny&lt;int&gt;())
          .Returns(Task.FromResult(expected));
      var survey = new SurveyResult(mock.Object);
  
      //Act 
      string result = await survey.GetOrderNameById(It.IsAny&lt;int&gt;()));
  
      //Assert
      Assert.Equal(expected, result);
  }
  </code></pre>