title: How to test async Task<IActionResult> returning IEnumerable<model> using moq in xunit?
body: <p>I want to test GetMoviesAsync of my Controller. I don't know where I am doing wrong in my Moq setup. I am getting 0 item from GetMoviesAsync.</p>
  <p>What am I doing wrong?</p>
  <p>// Api-Controller:</p>
  <pre><code>   public interface ICommand
     {
          Task&lt;IEnumerable&lt;Movie&gt;&gt; GetMoviesAsync();
     }
  
     public class SampleController : ControllerBase
      {
          private readonly ICommand movieCommand;
  
          public SampleController(ICommand command)
          {
              movieCommand = command;
          }
  
          [HttpGet]
          public async Task&lt;IActionResult&gt; GetMoviesAsync()
          {
              var movies = await movieCommand.GetMoviesAsync();
              return Ok(movies);
          }
      }
  </code></pre>
  <p>// Unit-Test:</p>
  <pre><code>public class SampleControllerTest
      {
          private IEnumerable&lt;Movie&gt; MovieList()
          {
              IList&lt;Movie&gt; movies = new List&lt;Movie&gt;()
              {
                  new Movie()
                  {
                      ID =1,
                      Title = &quot;Test&quot;,
                      ReleaseDate = DateTime.Now,
                      RunningTimeInMinutes = 100
                  }
              };
              return movies;
          }
  
          private SampleController GetSampleController()
          {
              var command = new Mock&lt;ICommand&gt;();
  
              return new SampleController(command.Object);
          }
  
          [Fact]
          public async Task GetMovies_Test()
          {
              // Arrange
              var controller = GetSampleController();
              var commadMock = new Mock&lt;ICommand&gt;();
              // How to setup moq here?
              commadMock.Setup(s =&gt; s.GetMoviesAsync()).Returns(Task.FromResult&lt;IEnumerable&lt;Movie&gt;&gt;(MovieList())).Verifiable();
              // Act
              var response = await controller.GetMoviesAsync() as OkObjectResult;
              // Problem is here, 
              var li=response.Value as IEnumerable&lt;Movie&gt;;
           }
      }
  </code></pre>