我有以下用于单元测试的伪造知识库。我将如何在这个仓库中实现Attach(T实体)方法? (在我的真实存储库中,使用Attach(T实体)方法将对象附加到我的实体框架4数据上下文中)。用于单元测试的C#通用知识库
public class FakeRepository<T> : IRepository<T> where T : class, new()
{
private static List<T> entities = new List<T>();
public IQueryable<T> Entities
{
get { return entities.AsQueryable(); }
}
public T New()
{
return new T();
}
public void Create(T entity)
{
entities.Add(entity);
}
public void Delete(T entity)
{
entities.Remove(entity);
}
public void Attach(T entity)
{
//How to implement Attach???
}
public void Save()
{
//Do nothing
}
public void Dispose()
{
return;
}
}
是的 - 这是有道理的。谢谢。 – thd 2010-11-18 21:47:14