madism
02-21-2007, 08:59 AM
Hello,
I am using NMock2 in unit tests. On occasion I run into the problem that I am testing classes that need to use the service locator pattern, ContextRegistry.GetContext().GetObject(..). (for instance WF activities and other MS framework constructed code).
I can of course create a stub instead of a mock for every specific test, but I would rather use generated mocks since it is a lot less work. What I would like to be able to do is reconfigure objects or object factories at runtime, so I can switch out the objects that would normally be returned by GetObject with a Mock generated dynamic proxy. I have tried to do this with ConfigureObject(..), but it seems that once an object has been configured in XML, you cannot 'reconfigure' it with this method. Any chance this can be changed or that a feature can be added? Or is there a lower level API that I can use?
Thanks
I am using NMock2 in unit tests. On occasion I run into the problem that I am testing classes that need to use the service locator pattern, ContextRegistry.GetContext().GetObject(..). (for instance WF activities and other MS framework constructed code).
I can of course create a stub instead of a mock for every specific test, but I would rather use generated mocks since it is a lot less work. What I would like to be able to do is reconfigure objects or object factories at runtime, so I can switch out the objects that would normally be returned by GetObject with a Mock generated dynamic proxy. I have tried to do this with ConfigureObject(..), but it seems that once an object has been configured in XML, you cannot 'reconfigure' it with this method. Any chance this can be changed or that a feature can be added? Or is there a lower level API that I can use?
Thanks