I have an interface defined as follows:
public interface IBaseRepository<T>
{
IQueryable<T> All();
}
Then, I have an interface extending this:
public interface IAccountRepository : IBaseRepository<AccountModel>
{
}
In my tests, however, when I try to mock the IAccountRepository and call setup for IAccountRepository.All(), Moq won't allow me to use the Returns method to define a result.
var mockAccountRepository = new Mock<IAccountRepository>();
mockAccountRepository.Setup(x => x.All()).Returns(...); // "Returns" can't work here for some reason.
How can I mock a base method on an interface that inherits from a generic interface?
mockAccountRepository.Setup(x => x.All()).Returns(new List<AccountModel>().AsQueryable());
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