I have an interface IRepository
to abstract my repository:
Fake repository
public class Repository : IRepository
{
IQueryable<User> _users;
public IQueryable<User> Users
{
get
{
return _users ?? (_users = Enumerable.Empty<User>().AsQueryable());
}
}
IQueryable<Couple> _couples;
public IQueryable<Couple> Couples
{
get
{
return _couples ?? (_couples = Enumerable.Empty<Couple>().AsQueryable());
}
}
IQueryable<Role> _roles;
public IQueryable<Role> Roles
{
get
{
return _roles ?? (_roles = Enumerable.Empty<Role>().AsQueryable());
}
}
public T Add<T>(T entity) where T : class
{
throw new System.NotImplementedException(); //Problem here!!
}
}
I need to know, how to add an object in the right collection in my repository fake?
In my database repository, I not have this problem:
Database repository
public class Repository : DbContext, IRepository
{
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Couple> Couples { get; set; }
public T Add<T>(T entity)
where T : class
{
return Set<T>().Add(entity);
}
... //More...
}
I know that the collections are not the same type, concealed this implementation to shorten the code.
All I want to know is how to maintain the same behavior from my database repository in my fake repository?