Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Can not call Swap.AllInstances() more than once on a type.

+3 votes
Hi - we are having some issues with the following test method;

public void TestSynchroniseFullSyncTrigger()
SynchronisationService synchronisationService = Isolate.Fake.Instance<SynchronisationService>(Members.CallOriginal, ConstructorWillBe.Ignored);
Isolate.WhenCalled(() => ConfigurationManager.AppSettings["FullSynchronisationIntervalInSeconds"]).WillReturn("100");
IConnectionMonitorService connectionMonitorService = Isolate.Fake.Instance<IConnectionMonitorService>();
Isolate.WhenCalled(() => connectionMonitorService.IsConnected()).WillReturn(false);
bool eventCalled = false;
synchronisationService.CaseHeaderListUpdated +=
delegate(object sender, EventArgs e)
eventCalled = true;
Assert.IsTrue(eventCalled == false);

When calling the line;


We get the following exception;

Test method ***.Synchronisation.Test.SynchronisationServiceTests.TestSynchroniseFullSyncTrigger threw exception: TypeMock.TypeMockException:
*** Can not call Swap.AllInstances() more than once on a type.

Note we have used the [Isolated] attribute on both the Test Class and Test Method.
asked Mar 11, 2011 by stephencampling (1,250 points)

2 Answers

+2 votes

Does it happen when the test runs alone or when it runs in a class or assembly? Isolated attribute clears expectations and behaviors after the test finishes, so if a previous test left a behavior it'll cause a conflict.

If it still happens, will you be able to send us a small project that reproduces this case?

Typemock Support
answered Mar 11, 2011 by Elisha (22,740 points)
+3 votes
Hi thanks for the response, yes it happens both in isolation and as part of a full test run.

I'll look into getting a small test app but may not be that easy.

answered Mar 11, 2011 by stephencampling (1,250 points)