Suppose we have the following Interface:
public interface ICRUDService<T>
{
T Create(T entity);
}
Abstract Implementation:
public abstract class CrudService<T> : ICRUDService<T>
{
IRepository repositorio;
public EntityService(IRepository rep)
{
repositorio= rep;
}
public virtual T Create(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity ");
}
repositorio.Add(instance);
return entity;
}
}
For each object in my domain (Ex: Person, Car, Animal) will implement a service:
public class PessoaService :CrudService<Model.Pessoa>{
IRepository repositorio;
public PessoaService (IRepository repo):base(repo)
{
repositorio= repo;
}
public void MetodoPersonalizadoServicoPessoa(){
var oi = "oi";
}
}
public class CarroService :CrudService<Model.Carro>{
IRepository repositorio;
public CarroService (IRepository repo):base(repo)
{
repositorio= repo;
}
public void MetodoPersonalizadoServicoCarro(){
var oi = "oi2";
}
}
-What is the best way to test each CrudService implementation?
- For each implementation should I repeat the test of the Create method of the abstract class?
-Is there any way to create a generic abstract test that automatically tests the Create method on all classes that implement it?