Replacing site collection scoped service locator configuration when unit testing

May 1, 2012 at 7:39 PM
Edited May 1, 2012 at 7:40 PM

Hello, I have successfully run unit testing with farm scoped service locator settings. I have not managed to do the same when using site collection scoped service locator settings. The documentation does not seem to cover this. Does anyone have any solution for doing this? I'm using Moles from Microsoft Research to replace run time instances of SharePoint instances.

Run time code to get implementation from site collection scoped configuration:

instance = SharePointServiceLocator.GetCurrent(site).GetInstance<IInterface>();

I'm not able to use get instances using this code when unit testing. I'm getting errors because necessary properties/methods are not moled.

Unit test setup (does work for farm scoped configuration, but not for site collection scoped configuration):

ActivatingServiceLocator locator = new ActivatingServiceLocator();