I’ve been looking at the Nerd Dinner app, more specifically how it handles its unit tests.
The following constructors for the RSVPController are confusing my slightly
public RSVPController()
: this(new DinnerRepository()) {
}
public RSVPController(IDinnerRepository repository) {
dinnerRepository = repository;
}
From what I can tell the second one is used by the unit tests so it can use Fake repositories. What I cant work out is what the first constructor does. It doesn’t seem to ever set the dinnerRepository variable, it seems to imply its inheriting from something but I really don’t get it.
Can anyone explain?
Thanks
The first constructor is passing the “default”
IDinnerRepositoryimplemenation (namelyDinnerRepository) to the second constructor.It does so because that empty constructor is used by the MVC Controller Factory. In other words, when the application actually executes, it uses the first constructor with the default repository implementation. When a unit test wants to test the Controller, then an mocked
IDinnerRepositorycan be passed to the controller.