This is precisely why "new is considered bad" and why dependency
injection was invented. :)
Btw, if you pass in a CityManager but then don't use it, creating your
own instead, it isn't really dependency injection, is it?
There are other patterns too of course.... Inject a factory of some
sort which is responsible for creating the CityManager on demand, then
mock the factory. Or move the CityManager creation to a virtual
method, and have the test use a TestPersonManager that inherits from
PersonManager and overrides the virtual method. Or get the CityManager
from a static method, the static method will call into a factory,
which it finds in a static property, and which the tests and bootstrap
code can initialize to either a mock provider, or the real thing,
respectively.
Many of these methods come in handy when you try to take control of,
refactor and create tests for a large legacy code base, where you are
limited in how you can change the code. For new code, dependency
injection is often the way to go.
/Oskar
2012/1/15 Sruli Ganor <sr...@netvision.net.il>:
> --
> You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
> To post to this group, send email to rhino...@googlegroups.com.
> To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
>
/Oskar
2012/1/18 Sruli Ganor <sr...@netvision.net.il>: