I’m trying to clean my code to make it unit-testable. I know that unit tests must be created while coding but… I have to do it now, with code completed.
My business class is full of methods with a similar implementation like:
var rep=new NHrepository<ModelClass1>(Session);
rep.Where(x=>x.Field1==1).ToList();
first error (from my point of view) is that I don’t have to use “new” but instead use DI and add in the ctor parameters a INHrepository modelClass1Repository.
If in my class I have two or more repository of different model class? Each must be in the ctor? Or probably business class is not build with SeparationOfConcern principle?
You’re right about the dependecy injection.
Also, I strongly recommend that you read Working Effectively with Legacy Code if you plan to write unit tests for your legacy code.