Hi all
I have a bunch of repository classes which I want to unit-test using Visual Studio 2008. They implement the following interface:
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();
}
Now I could write a fully blown test class for each and every repository I have. However to minimize redundancies, I want to write a base test class which contains the main "generic" test methods. This would allow me to write a simple subclass for every repository, like this:
[TestClass]
public class EmployeeRepositoryTest : RepositoryTestBase<Employee>
{
// all test methods are inherited from the base class
// additional tests could be added here...
}
However, the test methods defined in RepositoryTestBase are not detected by Visual Studio (because of generics), making this approach useless. To make it work, I would need to wrap each method of the base class to make them visible to Visual Studio, which causes redundancies again..
Is there a better approach to solve this pain? I don't want to clutter my tests with tons of wrapping code :(