Typemock Isolator 5.3 Is Out!
Time has come for another Isolator release – this time we’ve put a lot of effort into providing features and bug fixes requested by many of you – hope you like it! The new version is available on our download page.
Exact Argument Matching
You now have the power to provide a fake behavior that will only apply when the arguments passed to the method being faked match those passed to WhenCalled(). This is how it looks like in our c# API (WillThrow is used to illustrate the feature. You can of course use any behavior):
var fake = Isolate.Fake.Instance<Logger>();
Isolate.WhenCalled(() => fake.OpenPath("c:log.txt")).WithExactArguments().
// this call will be ignored
// this call will throw an exception
And for you VBers:
Dim fake As Logger = FakeInstance(Of Logger)()
Using TheseCalls.WithExactArguments.WillThrow(new FileNotFoundException())
' This call is ignored
' This call throws an exception
Up until now calls could be faked to stock behaviors such as returning a value, throwing an exception, ignoring the call etc. However, for some of you this wasn’t enough – you wanted to control custom method behavior and define what happens when a method is called yourself. Well, now you can, using this new API:
var fake = Isolate.Fake.Instance<ProductFactory>();
// define GetProductSequenceId() to return a custom ID
var count = 0;
var countMyProduct = 0;
Isolate.WhenCalled(() => fake.GetProductSequenceId("")).
// return a count of "MyProduct"s created so far
if(context.Parameter as string == "MyProduct")
// returns 0
// returns 1
// returns 0
The same functionality in VB.NET is accessed using TheseCalls.WillBeReplacedWith(). Because lambda expressions are not fully supported in VB.NET, we pass in a delegate address:
Using TheseCalls.WillBeReplacedWith(AddressOf CustomSequenceId)
' this is our custom behavior implementation
Shared count As Integer = 0
Shared countMyProduct as Integer = 0
Public Function CustomSequenceId(ByVal context as MethodCallContext) As Integer
If CType(context.Parameter(0), String) = "MyProduct" Then
countMyProduct = countMyProduct + 1
count = count + 1
Specific Constructor Invocation
Previously, when creating fake objects you had little control over the object’s constructor behavior; either the default constructor (or the simplest constructor found) was called (when creating fakes with Members.CallOriginal), or no constructor was called. Now you can easily decide whether or not to call a constructor, and which parameters to pass to a constructor if called.
In c# it looks like this:
// do not call a c'tor for a CallOriginal fake object
var fake1 = Isolate.Fake.Instance<Logger>(Members.CallOriginal, ConstructorWillBe.Ignored);
// call a specific c'tor for a RecursiveFakes fake object
var fake2 = Isolate.Fake.Instance<Logger>(Memebrs.ReturnRecursiveFakes, ConstructorWillBe.Called, "c:log.txt");
And in VB.NET:
' Create a CallOriginal fake object but do not call its c'tor
Dim fake1 As Logger = FakeInstance(Of Logger)(Members.CallOriginal, ConstructorWillBe.Ignored)
' Create a RecursiveFakes fake object and call a specific c'tor
Dim fake2 As Logger = FakeInstance(Of Logger)(Members.ReturnRecursiveFakes, ConstructorWillBe.Called, "c:log.txt")
- Several issues concerning faking generic objects have been addressed
- NCover 3 (starting version 3.0.18) linking integration is now supported
As you can see, there are some nice new tools in this version, and I can tell you we’re pretty pleased with it. Go ahead and get it, and let us know what you think!