C# Visual Studio 2008:泛型类中的单元测试方法未正确检测

C# Visual Studio 2008:泛型类中的单元测试方法未正确检测,c#,visual-studio,visual-studio-2008,unit-testing,mstest,C#,Visual Studio,Visual Studio 2008,Unit Testing,Mstest,我有一组存储库类,我想使用VisualStudio2008进行单元测试。它们实现以下接口: public interface IRepository<TEntity> where TEntity : IEntity { /// <summary> /// Get entity by ID /// </summary> /// <param name="id">The ID</param> ///

我有一组存储库类,我想使用VisualStudio2008进行单元测试。它们实现以下接口:

public interface IRepository<TEntity> where TEntity : IEntity
{
    /// <summary>
    /// Get entity by ID
    /// </summary>
    /// <param name="id">The ID</param>
    /// <returns></returns>
    TEntity GetById(int id);

    /// <summary>
    /// Get all entities
    /// </summary>
    /// <returns></returns>
    IEnumerable<TEntity> GetAll();
}
公共接口i假设,其中tenty:ienty
{
/// 
///按ID获取实体
/// 
///身份证
/// 
TEntity GetById(intid);
/// 
///获取所有实体
/// 
/// 
IEnumerable GetAll();
}
现在我可以为我拥有的每个存储库编写一个完整的测试类。然而,为了尽量减少冗余,我想编写一个包含主要“通用”测试方法的基本测试类。这将允许我为每个存储库编写一个简单的子类,如下所示:

[TestClass]
public class EmployeeRepositoryTest : RepositoryTestBase<Employee>
{
     // all test methods are inherited from the base class
     // additional tests could be added here...
}
[TestClass]
公共类EmployeeRepositoryTest:RepositoryTestBase
{
//所有测试方法都继承自基类
//可以在此处添加其他测试。。。
}
但是,VisualStudio无法检测到RepositoryTestBase中定义的测试方法(因为有泛型),这使得这种方法毫无用处。要使其工作,我需要包装基类的每个方法,使它们对Visual Studio可见,这会再次导致冗余


有没有更好的方法来解决这种痛苦?我不想用大量的包装代码把我的测试弄得乱七八糟:(

是否可以在测试声明中不包含泛型,而仅仅依赖于IEntity,比如:

IEntity GetById(int id);
IEnumerable<IEntity> GetAll();
entity GetById(int-id);
IEnumerable GetAll();
如果这两个函数需要对Entity进行任何实例化,您可以让存储库构造函数接受一个factory对象。实例化是factory对象的工作。将有一个抽象基(或接口)对于实例化方法仅返回IEntity的工厂,以及可以模板化或不模板化的子类