C# 如何为通用存储库创建MockRepository

C# 如何为通用存储库创建MockRepository,c#,tdd,moq,C#,Tdd,Moq,我是TDD模式的新手,所以我想在Asp.NETMVC中创建基本的演示应用程序,它有一个通用的存储库。有人能告诉我如何使用mockrepository为单元测试创建一个通用的mock吗 我的通用存储库代码如下 public class PoolManagementRepository<T> :IPoolManagementRepository<T> where T:class { internal PoolManagmentEntities context;

我是TDD模式的新手,所以我想在Asp.NETMVC中创建基本的演示应用程序,它有一个通用的存储库。有人能告诉我如何使用mockrepository为单元测试创建一个通用的mock吗

我的通用存储库代码如下

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
}
public类PoolManagementRepository:IPoolManagementRepository其中T:class
{
内部池管理上下文;
内部数据库集;
公共池管理存储库(池管理实体上下文)
{
this.context=上下文;
this.dbSet=context.Set();
}
#区域再定位手术
公共虚拟IEnumerable GetAll()
{
返回context.Set();
}
公共虚拟T GetByID(对象id)
{
返回dbSet.Find(id);
}
公共虚拟无效插入(T实体)
{
添加(实体);
}
公共虚拟无效删除(对象id)
{
T entityToDelete=dbSet.Find(id);
删除(entityToDelete);
}
公共虚拟无效删除(T entityToDelete)
{
}
公共虚拟无效更新(T entityToUpdate)
{
数据库集附加(实体更新);
context.Entry(entityToUpdate.State=EntityState.Modified;
}
#端区
}

您尝试了什么?你走了多远?你在哪里?我创建了通用存储库,但我想创建MockRepository,它将是TDD的通用存储库。你能告诉我如何实现它吗?我在ListIn TDD(测试驱动开发)的通用FindById方法中面临问题。你首先编写测试,然后编写代码以通过测试。您的测试在哪里?我正在尝试使用通用模拟存储库为通用存储库创建测试,实际上我是TDD新手,因此我首先编写了代码