I'm trying to use Moq to mock the interface:
public interface IMatchSetupRepository { IEnumerable<MatchSetup> GetAll(); }
and I'm doing:
var matchSetupRepository = new Mock<IMatchSetupRepository>(); matchSetupRepository .Setup(ms => ms.GetAll()) .Returns(null);
But it doesn't even compile because of the error:
error CS0121: The call is ambiguous between the following methods or properties: 'Moq.Language.IReturns<Data.Contract.IMatchSetupRepository,System.Collections.Generic.IEnumerable<Data.Model.MatchSetup>>.Returns(System.Collections.Generic.IEnumerable<Data.Model.MatchSetup>)' and 'Moq.Language.IReturns<Data.Contract.IMatchSetupRepository,System.Collections.Generic.IEnumerable<Data.Model.MatchSetup>>.Returns(System.Func<System.Collections.Generic.IEnumerable<Data.Model.MatchSetup>>)'
I'm using:
Moq.dll, v4.0.20926
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With