Moq安装程序不提供AsQueryable方法

时间:2014-03-05 16:54:11

标签: c# unit-testing moq

我有以下内容:

        Mock<ISiteRepository> mockSiteRepository = new Mock<ISiteRepository>();

        mockSiteRepository.Setup(m => m.Sites).Returns(new Site[] {
            new Site {
                SiteID = 0,
                DateCreated = DateTime.Now,
                Name = "A",
            }
        }/*There is no AsQueryable ?*/);

这是我实现的东西的界面:

public interface ISiteRepository
{
    IQueryable<Site> Sites { get; }
    ...

有什么想法吗?

如果我没有在Site数组的末尾添加任何内容,则会抛出编译错误:

Error   6   The best overloaded method match for 'Moq.Language.IReturns<James.Domain.Abstract.ISiteRepository,System.Linq.IQueryable<James.Domain.Entities.Site>>.Returns(System.Linq.IQueryable<James.Domain.Entities.Site>)' has some invalid arguments   

1 个答案:

答案 0 :(得分:2)

using需要System.Linq;