cannot convert from ‘IEnumerable’ to ‘IEnumerable

public async void  Select_getallTask()

    IEnumerable<TaskToDo> list = new List<TaskToDo>();

    var mockrepo = new Mock<ITaskToDoRepository>();
      mockrepo.Setup(x => x.GetTasks()).Returns(list);


    var data = mockrepo.Object.GetTasks();

    Assert.AreEqual(data, list);

this gives me error on

mockrepo.Setup(x => x.GetTasks()).Returns(list);

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from
'System.Collections.Generic.IEnumerable<ToDoApp.Models.TaskToDo>' to
'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ToDoApp.Models.TaskToDo>>'  UnitTest_ToDoApp    J:SourceRealAppUnitTest_ToDoAppListTest.cs  97  Active

Repo is
public interface ITaskToDoRepository
    Task<IEnumerable<TaskToDo>> GetTasks();
    TaskToDo GetTasksById(Guid Id);      


I hope you could understand the problem. Thx


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You should use ReturnsAsync in your setup like as shown below

var mockrepo = new Mock<ITaskToDoRepository>();
                  mockrepo.Setup(x => x.GetTasks()).ReturnsAsync(list);

as your method GetTasks is type of Task<> return type.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x