I have the following repository interface
public interface IRepository<TEntity> {
TEntity FindById(int id);
TEntity FindById(long id);
etc
}
I then have the following Repository class that inherits from the interface above
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class {
private DB _context;
public Repository() {
_context = new DB();
}
public Repository(DB context) {
_context = context;
}
Methods.....
}
I have created a FakeRepository<> that also inherits from IRepository<>
public class FakeRepository<TEntity> : IRepository<TEntity> where TEntity : class {
private FakeDataContext _context;
public FakeRepository() {
_context = new FakeDataContext();
}
public FakeRepository(FakeDataContext context) {
_context = context;
}
Methods....
}
The only difference between the Repository and the Fake is that rather than using the LinqToSQL DBContext I have created a fake one for testing purposes.
What I then what to be able to do in my unit tests is:
ObjectFactory.Initialize(x => { x.For(typeof(Repository<>)).Use(typeof(FakeRepository<>)); });
So my tests will always be run against the in-memory fakedbcontext.
However I get structuremap error 104 pluggin type error and i'm not sure why?