簡體   English   中英

Moq:繼承自通用接口的Mock接口

[英]Moq: Mock interface that inherits from generic interface

我有一個接口定義如下:

public interface IBaseRepository<T>
{
    IQueryable<T> All();
}

然后,我有一個擴展這個的接口:

public interface IAccountRepository : IBaseRepository<AccountModel>
{
}

但是,在我的測試中,當我嘗試模擬IAccountRepository並調用IAccountRepository.All()設置時,Moq將不允許我使用Returns方法來定義結果。

var mockAccountRepository = new Mock<IAccountRepository>();
mockAccountRepository.Setup(x => x.All()).Returns(...); // "Returns" can't work here for some reason.

如何在繼承自通用接口的接口上模擬基本方法?

mockAccountRepository.Setup(x => x.All()).Returns(new List<AccountModel>().AsQueryable());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM