chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi - we are having some issues with the following test method;

[TestMethod]
[Isolated]
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.Swap.AllInstances<IConnectionMonitorService>().With(connectionMonitorService);
Isolate.WhenCalled(() => connectionMonitorService.IsConnected()).WillReturn(false);
bool eventCalled = false;
synchronisationService.CaseHeaderListUpdated +=
delegate(object sender, EventArgs e)
{
eventCalled = true;
};
synchronisationService.Synchronise(false);
Assert.IsTrue(eventCalled == false);
}


When calling the line;

Isolate.Swap.AllInstances<IConnectionMonitorService>().With(connectionMonitorService);

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 by stephencampling (3k points)

2 Answers

0 votes
Hi,

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?

Regards,
Elisha,
Typemock Support
answered by Elisha (12k points)
0 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.

Thanks
Steve.
answered by stephencampling (3k points)
...