Reputation:
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?
Upvotes: 4
Views: 965
Reputation: 13409
mockAccountRepository.Setup(x => x.All()).Returns(new List<AccountModel>().AsQueryable());
Upvotes: 4