The difference between Duck Typing and swapping collections

I noticed that two features that came out in version 5.1.1 of Typemock Isolator can cause confusion.
The features are Duck Typing and Swapping collections.

Lets look at their method signature:
For duck typing it is:
Isolate.Swap.CallsOn(object toSwap).WithCallsTo(object swapped);
For swapping collections it is:
Isolate.WhenCalled(Func<T> func).WillReturnCollectionValuesOf(IEnumerable collection)

Notice that when you use Duck Typing the CallsOn method takes an object as an argument while WhenCalled takes lambda expression as an argument.
The difference is that when you use Isolate.Swap.CallsOn(object toSwap) …
the method or chain of methods inside CallsOn will be evaluated (not faked).
While the lambda expression inside WhenCalled method is faked.

For example in the code below:
Isolate.Swap.CallsOn(a.b.ReturnSomeObject()).WithCallsTo(myFakeObject);
a.b.ReturnSomeObject() will be called and the object that is returned from the chain will be swapped with myFakeObject.

On the other hand if you call:
Isolate.WhenCalled(()=> a.b.ReturnSomeObject()).WillReturnCollectionValuesOf( new string [] {“John”, “Paul”} );
That’s like saying to the Isolator “when the chain a.b.ReturnSomeObject() is called just fake it and return the string array {“John”, “Paul”}”

Happy swapping!

TOP