我是TDD模式的新手,所以我想在Asp.Net MVC中创建基本的演示应用程序,它有一个通用的存储库。谁能告诉我如何使用mockrepository创建一个通用模拟进行单元测试?
我的通用存储库代码如下
public class PoolManagementRepository<T> :IPoolManagementRepository<T> where T:class
{
internal PoolManagmentEntities context;
internal DbSet<T> dbSet;
public PoolManagementRepository(PoolManagmentEntities context)
{
this.context = context;
this.dbSet = context.Set<T>();
}
#region Reository Operation
public virtual IEnumerable<T> GetAll()
{
return context.Set<T>();
}
public virtual T GetByID(object id)
{
return dbSet.Find(id);
}
public virtual void Insert(T entity)
{
dbSet.Add(entity);
}
public virtual void Delete(object id)
{
T entityToDelete = dbSet.Find(id);
Delete(entityToDelete);
}
public virtual void Delete(T entityToDelete)
{
}
public virtual void Update(T entityToUpdate)
{
dbSet.Attach(entityToUpdate);
context.Entry(entityToUpdate).State = EntityState.Modified;
}
#endregion
}