Setup method in Moq, ambiguous call

Try the generic version of Returns:

var matchSetupRepository = new Mock<IMatchSetupRepository>();
matchSetupRepository
    .Setup(ms => ms.GetAll())
    .Returns<IEnumerable<MatchSetup>>(null);

or:

var matchSetupRepository = new Mock<IMatchSetupRepository>();
matchSetupRepository
    .Setup(ms => ms.GetAll())
    .Returns((IEnumerable<MatchSetup>)null);

Instead. Because you’re passing the function null (and there are two overloads of Returns), the compiler does not know which overload you mean unless you cast the argument to the correct type.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)