I am writing some tests using the full verson of Isolator 5.2.x on a Sharepoint webpart tha requires me to mock out SPFarm.Local, the static property that allows you to grab the list of all services in the farm.
I setup the mock as follows at the start of each isolated test
private static void SetupFakeFarm()
{
SPFarm fakeFarm = Isolate.Fake.Instance<SPFarm>(Members.ReturnRecursiveFakes);
List<SPService> fakeServiceCollection = new List<SPService>{Isolate.Fake.Instance<SPWebService> (Members.ReturnRecursiveFakes)};
// some more items created......
Isolate.Swap.NextInstance<SPFarm>().With(fakeFarm);
Isolate.WhenCalled(() => fakeFarm.Services).WillReturnCollectionValuesOf(fakeServiceCollection);
// setup some more when called
}
I can then us these fakes to run tests against
[TestMethod, Isolated]
public void MyTest() {
SetupFakeFarm();
SPFarm localFarm = SPFarm.Local;
// Get all the services from the farm object
foreach (SPService service in localFarm.Services)
{ ....}
// some asserts
}
If I run each of my tests individually then they work perfectly, but if I run them as batch (via VS Test tools or TestDriven.NET) the first one works but the subsequent ones fail as the localFarm returned does not appear to be the fake.
Is there something special I need to do to dispose of fakes of statics between tests other than setting the lsolate attribute?