mercredi 27 avril 2016

Moq: Mock interface that inherits from generic interface

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?

Aucun commentaire:

Enregistrer un commentaire