Consider a beginner dealing with Dependency Injection. We're analyzing two relevant classes in NerdDinner.
DinnerRepository from the application:
FakeDinnerRepository from the tests:
They implement different logic, which of course is necessary, as the key idea here is to implement the IDinnerRepository
, and provide different implementations and private members.
I understand the test is for the controller, but I am concerned that there are two different implementations of the data access logic. Consider any project that uses any kind of ORM, ADO.NET, SubSonic, or whatever flavour of data access you like. Yes, you can setup your fake repository to match the real repo.
My worry is that over time, implementation details in the real repo change. Perhaps a typo slips in, or some other important implementation detail changes in the query. This leads to a potential mismatch of the logic in the Model between the fake and the real repo. The worry is that the implementation of the real repo and test repo get out of sync.
Questions:
- How would you test the Model in this case?
- Is it appropriate to test the model?
- Is it a matter of discipline to ensure your test keep up with the implementation of the business logic?