The question is: how is this best done?
I can think of three ways:
- Inherit B (with class C) and override the (protected) method that loads up A. In C, A-mock would be loaded instead of A. During testing run the unit tests on C instead of B.
- Add public or internal methods to B that allow A being set. During testing give B A-mock instead of A using these new methods.
- Use reflection to load A dynamically based on the configuration (in app.config, e.g.). During testing replace A with A-mock in the configuration.
Unfortunately I don't have the answer to that :)