MockUnitOfWork '无法解析符号 MockUnitOfWork'
我正在尝试使用此处的示例从 IRepository 获取图 3 假数据库 http://msdn.microsoft.com/en-us/magazine/dd263069。 aspx
public class InMemoryRepository : IRepository
{
private readonly Cache<Type, object> _types;
private MockUnitOfWork _lastUnitOfWork;
public InMemoryRepository()
{
_types = new Cache<Type, object>(type =>
{
Type listType = typeof(List<>).MakeGenericType(type);
return Activator.CreateInstance(listType);
});
}
private IList<T> listFor<T>()
{
return (IList<T>)_types.Get(typeof(T));
}
public T Find<T>(long id) where T : Entity
{
return listFor<T>().FirstOrDefault(t => t.Id == id);
}
public void Delete<T>(T target)
{
listFor<T>().Remove(target);
}
public T[] Query<T>(Expression<Func<T, bool>> where)
{
var query = from item in listFor<T>() select item;
return query.Where(where.Compile()).ToArray();
}
public void Save<T>(T target)
{
listFor<T>().Add(target);
}
}
我收到“无法解析符号 MockUnitOfWork”。 我安装/引用了 NUnit/Moq/Rhino.Mock,但找不到任何对 MockUnitOfWork 的引用。 任何帮助表示赞赏。
I'm trying to get Figure 3 Fake Database from IRepository using the example here
http://msdn.microsoft.com/en-us/magazine/dd263069.aspx
public class InMemoryRepository : IRepository
{
private readonly Cache<Type, object> _types;
private MockUnitOfWork _lastUnitOfWork;
public InMemoryRepository()
{
_types = new Cache<Type, object>(type =>
{
Type listType = typeof(List<>).MakeGenericType(type);
return Activator.CreateInstance(listType);
});
}
private IList<T> listFor<T>()
{
return (IList<T>)_types.Get(typeof(T));
}
public T Find<T>(long id) where T : Entity
{
return listFor<T>().FirstOrDefault(t => t.Id == id);
}
public void Delete<T>(T target)
{
listFor<T>().Remove(target);
}
public T[] Query<T>(Expression<Func<T, bool>> where)
{
var query = from item in listFor<T>() select item;
return query.Where(where.Compile()).ToArray();
}
public void Save<T>(T target)
{
listFor<T>().Add(target);
}
}
I'm getting 'Cannot resolve symbol MockUnitOfWork.
I have NUnit/Moq/Rhino.Mock installed/referenced but I cannot find any reference to MockUnitOfWork.
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需删除
MockUnitOfWork
即可,因为代码中从未使用过它。我认为这是重构后留下的残余。
You can just remove the
MockUnitOfWork
, because it is never used in the code.I think it is a remnant left over after a refactoring.
文章没有明确说明 MockUnitOfWork 是什么,但由于它是显式声明的类型,因此它一定是一个手卷 Mock。
尽管其语义相同,但它与 Moq 或 RhinoMocks 无关。
如果您可以下载本文的源代码,我很确定您会在测试项目中找到一个名为 MockUnitOfWork 的类。
The article doesn't explicitly say anything about what MockUnitOfWork is, but since it is an explicitly declared type, it must be a hand-rolled Mock.
Despite its semantic equivalence, it has nothing to do with Moq or RhinoMocks.
If you can download the source code for the article, I'm pretty sure you will find a class called MockUnitOfWork in the test project.