Moq does not contain a definition for ReturnAsync?
Another option for this error is because ReturnsAsync
is only available for methods that return a Task<T>
. For methods that return only a Task, either of the following options can be used:
mock.Setup(arg=>arg.DoSomethingAsync()).Returns(Task.FromResult(default(object)))
mock.Setup(arg=>arg.DoSomethingAsync()).Returns(Task.CompletedTask);
The generic argument being used does not match the arguments of the member being mocked.
Remove the generic argument
VeracrossMock
.Setup(_ => _.GetStudentsAsync(1, null, CancellationToken.None))
.ReturnsAsync(resp);
and the method will infer the desired generic arguments based on the member being mocked.
I've hit this error message several times over the past few weeks and keep forgetting how I fixed it, so I'm writing it here in the hope it helps someone. Each time it was because I was being daft and was passing in an object/type when the method I was setting up expected a list of objects/types.