Reputation: 7077
I have an interface:
public interface IPeopleService
{
Task<List<Person>> GetPeople();
}
Here is my code to mock up the return for the request:
List<Person> people = ...;
var mockPeopleService = new Mock<IPeopleService>();
mockPeopleService.Setup(ps => ps.GetPeople()).Returns<Task<List<Person>>>(Task.FromResult(people));
Error persists no matter what I have done.....
After trying to use ReturnsAsync() it shows me this error:
mockPeopleService.Setup(ps => ps.GetPeople()).ReturnsAsync(people);
Update 2:
Upvotes: 4
Views: 259
Reputation: 9519
The problem with your approach is that you are using this method:
IReturnsResult<TMock> Returns<T>(Func<T, TResult> valueFunction);
In your example it doesn't make sense to use that overload. Just drop T
. Also might be usefull to use ReturnsAsync
.
mockPeopleService.Setup(ps => ps.GetPeople()).ReturnsAsync(people);
Upvotes: 4