I'm having issues trying to get NSubstitute
to return an IEnumerable
interface from a Task
.
The factory I'm mocking:
public interface IWebApiFactory<T> : IDisposable
{
<T> GetOne(int id);
Task<IEnumerable<T>> GetAll();
Task<IEnumerable<T>> GetMany();
void SetAuth(string token);
}
The test method:
[TestMethod]
public async Task TestMutlipleUsersAsViewResult()
{
var employees = new List<EmployeeDTO>()
{
new EmployeeDTO(),
new EmployeeDTO()
};
// Arrange
var factory = Substitute.For<IWebApiFactory<EmployeeDTO>>();
factory.GetMany().Returns(Task.FromResult(employees));
}
The error I am getting is:
cannot convert from 'System.Threading.Tasks.Task> to System.Func>>
Is this an issue with me passing a list, as a posed to IEnumerable
even though List
is IEnumerable
?
Edit:
These are the functions within NSubstitute
public static ConfiguredCall Returns<T>(this T value, Func<CallInfo, T> returnThis, params Func<CallInfo, T>[] returnThese);
public static ConfiguredCall Returns<T>(this T value, T returnThis, params T[] returnThese);