Let say I got the following code in my SqlUserRepository :
var user = from u in NHibernateLinqContext.Linq<User>() ...
What I would like is to have a similar context for my FakeuserRepository
var user = from u in FakeLinqContext.Linq<User>() ...
Like that, I’ll be able to use the same logic in my SqlUserRespository that my FakeUserRepository. But, I don’t know how Linq context work and how I can be able to create one for my FakeUserRepository.
Ideally I would like that, by example, my AnythingUserRepository take a context in constructor parameter.
Example :
SqlUserRepository() : base(NHibernateLinqcontext)
FakeUserRepository() : base(FakeLinqcontext)
Any idea how I can achieve that ?
You could allow the NHibernateLinqContext dependency to be injected into your SqlUserRepository by giving it an appropriate constructor, e.g.
If you want to unit test your SqlUserRepository then you could supply a mocked NHibernateLinqContext to the construction of your target.
If you want to unit test a class which uses your SqlUserRepository then you could simply mock the SqlUserRepository. I’m not sure why you would need a concrete FakeUserRepository.