对于我的单元测试,我需要伪造一个存储库。我很容易就能伪造除了将Linq Expression委托作为参数的Find方法以外的所有方法。伪造存储库 - 伪造查找方法
我的假存储库代码列在下面(不必要的代码已删除)。我尝试使用的代码显示在Find方法中。我从VS获得的编译器错误是:
“System.Collections.Generic.List”不包含'Where'和最佳扩展方法重载定义'System.Linq.Queryable.Where(System.Linq .IQueryable,System.Linq.Expressions.Expression>)”有一些无效参数”
如何我弯曲标准参数进入参数类型所需的任何想法?
public class FakeCourseRepository : IRepository<Course>
{
private List<Course> courseList;
public FakeCourseRepository(List<Course> courses)
{
courseList = courses;
}
public IList<Course> Find(System.Linq.Expressions.Expression<Func<Course, bool>> criteria)
{
return courseList.Where<Course>(criteria);
}
}
感谢KeithS,这是一个非常有用的答案。我还会围绕一个具体的列表来研究你的建议。 – Ozzy 2010-11-05 09:14:25