【发布时间】:2011-08-30 14:48:57
【问题描述】:
我有一个运行 linq to sql 查询的接口:
public interface IMyDataContext : IDisposable
{
ITable<MyTable> GetMyTable();
}
在这个界面上,我正在运行一个 linq 查询:
var results = from table1 in _MyDataContext.GetMyTable()
group table1 by table1.Column1 into myGroup
orderby myGroup.Count() descending
select new
{
Column1 = myGroup.Key,
Count = myGroup.Count()
};
查询运行良好。我被卡住的地方是在编写单元测试时。 如何让函数 GetMyTable() 返回一个带有一些假数据的模拟对象,围绕这里的待办事项:
public class MockMyContextWrapper : IMyDataContext
{
public void Dispose()
{
}
public ITable<MyTable> GetMyTable()
{
var table = MockRepository.GenerateMock<ITable<MyTable>>();
//todo: code to return something so that the linq query fired on this table works
return table;
}
}
【问题讨论】:
标签: c# linq nunit rhino-mocks itable