Typemock Isolator 5.1.1 is Out!

Ever wanted to fake collections or perform dynamic-language style behavior faking? Get the new Isolator version 5.1.1! This version received a minor version notation because we still have some major features up our sleeve, but it still sports cool new features, namely:

Duck-type swapping:

The saying “If it walks like a duck and talks like a duck, it must be a duck” is often used to illustrate concepts behind dynamic languages. Identifying an object by its behavior, rather than by its declared type, adds a programming language with powerful and flexible descriptive capabilities – just see what Microsoft is up to in C# futures. We took the idea of behavior-based type inference into the behavior faking world with the new Isolator swapping features:

// both the duck and the dog can talk. Normally a duck goes "Quack!" and a dog goes "Woof!"
var duck = new Duck();
var dog = new Dog();

// Once we swap the two...

// ...we have a duck going "Woof!"
Assert.AreEqual("Woof!", duck.Talk());

Besides the novelty value and endless options dealing with duck and dogs (you can make ducks chase cars or go fetch!), this is useful in unit testing. When you want to replace an object you are dependant on with a stand-in implementation this is a simple and powerful mechanism.

Collection handling:

A lot of support cases we saw recently pointed out difficulties when handling collections with Isolator. This is a frequent yet complex problem we are addressing with this release. Basically it comes with two sub features: collection value swapping and automatic collection faking.

Collection value swapping: we can now replace values of collections in the code under test with test data collections we prepare for this purpose. The API is pretty simple too:

// swap the Calculation.Numbers collection property with our own collection of numbers
Isolate.WhenCalled(() => Calculation.Numbers)
.WillReturnCollectionValuesOf(new[] {1, 3, 5});

// when iterating over the collection or accessing its members we receive the test values
Assert.AreEqual(3, Calculation.Numbers[1]);

int sum = 0;
foreach(var number in Numbers)
sum += number;
Assert.AreEqual(9, sum);

Automatic collection faking: when modifying behavior for a call chain which includes a collection index access, we assume you would like to fake out all elements in that collection up to the one in the index we are modifying. With auto-collection faking this is done automatically: when setting behavior for a collection element, all elements of a lower index are automatically created and assigned with recursive fake objects. Here’s a practical example from the SharePoint world:

// create a fake SPSite - this is the top level in the SP object model
SPSite fakeSite = Isolate.Fake.Instance<SPSite>(Members.ReturnsRecursiveFakes);

//make the 3rd list's 2nd item have a specific name and ID
Isolate.WhenCalled(() => fakeSite.OpenWeb().Lists[2].Items[1].Name).WillReturn("Test Item");
Isolate.WhenCalled(() => fakeSite.OpenWeb().Lists[2].Items[1].ID).WillReturn(999);

// Underlying lists are created automatically
Assert.AreEqual(3, fakeSite.OpenWeb().Lists);

// We can iterate over all lists and items and query them
int id = SharepointHandler.GetIdForListItem(fakeSite, "Test Item");
Assert.AreEqual(999, id);

// example implementation of GetIdForListItem() for reference:
public int GetIdForListItem(SPSite site, string itemName)
using(SPWeb web = site.OpenWeb())
foreach(var list in web.Lists)
foreach(var item in list.Items)
if(item.Name == itemName) return item.ID;

What do you think? go ahead and download the new version and let us know.