I'm happy to announce the latest version of Typemock Isolator. It's been three months since the last Major version release. In this version the Isolator development team has done some work on improving the overall user experience when using AAA:
Visual Basic API
If you're a developer using VB.NET there is no reason you could not use AAA - Isolator has a new API dedicated especially for Visual Basic.NET developers, that allows utilizing the simplicity and elegance of the Arrange-Act-Assert principals in VB.
Click the link to learn more on Programming Visual Basic applications with Isolator.
Dim fake As Logger = FakeInstance(Of Logger)()
' set behavior on the CanWrite() method
Using TheseCalls.WillReturn(True)
fake.CanWrite("c:\test.txt")
End Using
fake.Write("Hello World")
' assert that a call happened
Using AssertCalls.HappenedWithExactArguments
fake.WriteToDisk("c:\test.txt")
End Using
True Properties
setting property behavior is simpler than ever - just use the property setter to define property getter behavior:
var fake = Isolate.Fake.Instance<Logger>();
// use True Properties to set the behavior of the LogPath property
// this is done regardless of the actual implementation of the property setter.
fake.LogPath = "c:\test.txt";
// the property getter now returns the set value
Assert.AreEqual("c:\test.txt", fake.LogPath);
True Indexers
From this version behavior set on indexers is always conditional on the index value. Based on customer feedback, we feel this better reflects the way you would expect indexers to behave.
- Warning - The exact index must be sepcified when using WhenCalled/TheseCall block. Using dummy values (i.e. empty string or '0') for index in WhenCalled/TheseCalls block shall cause the test to break.
var fake = Isolate.Fake.Instance<LogFile>();
// use True Indexers to set the behavior of the index getter
// the behavior will apply only to the index value in the WhenCalled() statement
Isolate.WhenCalled(() => fake[0]).WillReturn("Hello");
Isolate.WhenCalled(() => fake[1]).WillReturn("World");
// when accessing the indexer it will return the set behavior depending on the index
Assert.AreEqual("World", fake[1]);
Assert.AreEqual("Hello", fake[0]);
// when accessing the indexer at an index we did not set behavior for the default behavior is returned
Assert.AreEqual("", fake[2]);
Behavior Sequencing
Behavior Sequencing: when setting behavior for a call more than once, the behaviors are sequenced - each time the call is made the next behavior is returned. The last call in the sequence is the default behavior that will be repeated after all sequenced behaviors are used:
var fake = Isolate.Fake.Instance<Logger>();
// use Behavior Sequencing to set up behavior on repeated calls to ReadFromLog()
Isolate.WhenCalled(() => fake.ReadFromLog()).WillReturn("Hello");
Isolate.WhenCalled(() => fake.ReadFromLog()).WillReturn("World");
// the last sequenced value will be used as the default value once all values are returned
Isolate.WhenCalled(() => fake.ReadFromLog()).WillReturn("DefaultValue");
// when the calls are made the return values are returned in the order they were sequenced at:
Assert.AreEqual("Hello", fake.ReadFromLog());
Assert.AreEqual("World", fake.ReadFromLog());
Assert.AreEqual("DefaultValue", fake.ReadFromLog());
Assert.AreEqual("DefaultValue", fake.ReadFromLog());
Another change in this version is the default behavior for creating fake objects. It has been changed to Members.ReturnRecursiveFakes when creating a fake instance without any parameters.
That's it - you can download the new version (as always) from our download section.






0 comments:
Post a Comment