Isolator 4.3.2 Released!

And another patch is out. You can download it here.

So what’s new in this one? This is mostly a fix compilation, but there are a couple of new things:

  • We’ve added support for ExactMagic‘s TestMatrix code coverage tool.
  • It is now possible to mock two interfaces with the same name, but belong to different namespaces.

There are a bunch of fixes, some of them came up as a result of a big refactoring effort by Lior and Doron. However, there are two breaking changes from versions past:

When using Natural Mocks, static constructors are now called by default. That is, not mocked. Like any default discussion, this may lead to breaking tests that were built under the former assumption. However, we made that change based on the feedback we’re seeing, and also by support calls. If you want your static constructor to be mocked, do so explicitly:

using (RecordExpectations recorder = new RecordExpectations())
{
recorder.DefaultBehavior.MockStaticConstructors = true;
}

The other breaking change is when you mix conditional return values and unconditional ones. For example, look at this code:

[TestMethod()]
public void MockTheFactoryStaticCheckArguments()
{
Mock factoryMock = MockManager.Mock(typeof(ProductFactory));
factoryMock.ExpectAndReturn("HasProduct", true).When("name");
factoryMock.ExpectAndReturn("HasProduct", false);
Assert.IsTrue(ProductFactory.HasProduct("name"));
Assert.IsFalse(ProductFactory.HasProduct("Othername"));
}

We set a conditional mocking on HasProducts, that will return true when the HasProduct method is called with the argument “name”. We then set an expectation to return false, without conditions. This test will pass. Now, let’s switch the expectations:

[TestMethod()]
public void MockTheFactoryStaticCheckArguments()
{
Mock factoryMock = MockManager.Mock(typeof(ProductFactory));
factoryMock.ExpectAndReturn("HasProduct", false);
factoryMock.ExpectAndReturn("HasProduct", true).When("name");
Assert.IsTrue(ProductFactory.HasProduct("name"));
Assert.IsFalse(ProductFactory.HasProduct("Othername"));
}

Now, what will happen? In the former releases, the order of the expectations counted. That means that the first call to HasProduct would always be mocked and therefore returns false, while the second call would be subject to the condition. In our case, this would fail the first Assert.

So now it’s different, and hopefully less confusing. Now both tests pass. Easy! That’s because we decided on the following rule: We first check if there’s a condition on the expectation. If there is, we fulfill it. If there isn’t we fulfill the normal expectation. It’s not that confusing after you get used to it.

Now, the fixes:

  • Apart from changing the default, static constructors are now acting in a more stable manner.
  • Large memory was consumed when mocking a lot of interfaces. Projects that did that a lot ran into memory problems. Now they don’t.
  • FailedWhenCalled was not behaving correctly on a chain.
  • A NullReferenceException was thrown when mocking a security object (specifically IPrincipal).
  • An event was called twice (instead of once) when the handler was a static method.
  • “Out” parameters were sometimes returned empty, instead of the set value.
  • The “7 days left” pop-up reminder now is shown only once, not every run.

So, like always, go and get it. And soon, very soon, expect a major release.

TOP