Release Notes

Version 5.2.0

These are the release notes for Release 5.2.0.


New Features
  • VB Friendly API:
A new API dedicated especially for Visual Basic.NET developers allows utilizing the simplicity and elegance of the Arrange-Act-Assert principals in VB:
    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: 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.
  • 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: 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());

  • The default behavior when creating fake objects or faking static method for a type has been changed to return recursive fakes. This is a change from the previous default of Must Specify Return Value - we feel this better represents the concept of a fake object not failing unnecessarily, making tests easier to write and less clutteC:\Development\Isolator\Documentation\ReleaseNotes520.htmlred. You can still create fakes that will throw an exception for unexpected behaviors by passing in the MustSpecifyReturnValues behavior.
    • Note that this may break tests created with the older default, in case the test depends on the exception thrown when calls that did not have behavior set to them. Fixing this should be done by passing in the Members.MustSpecifyReturnValues behavior when creating fake objects.

General fixes

In 5.2.1:

  • Visual Basic API: Fixed issue - Exception thrown WhenCalled is used with Nothing.

In 5.2.0:

  • Recursive fakes now return string.Empty (instead of null) for methods returning strings
  • Simplified the Isolator example projects structure
    • You can now find separate example solutions for c# and VB.NET, as well as a solution dedicated to our older APIs - Natural and Reflective.
  • Fixed a crash when creating fakes for classes containing anonymous delegates or lambda expressions
  • Fake.StaticConstructor() will not throw an exception when called twice
  • Faking the same struct twice is unsupported. A proper exception is thrown now for this scenario. 
    • A common solution for problems where you try to fake several copies of the same struct is to create a real copy of the struct and return it with WillReturn.
  • Improved displayed method signature in verification exception message
  • Resharper test runner is now reset when disabling and enabling Typemock Isolator in Visual Studio
  • Fixed a bug where a type's  static constructor is called even though Fake.StaticConstructor() was called for the type.


Known Issues
  • Isolator now installs into Program Files->Typemock->Isolator->5.2. When removing former versions, some artifcats on the file system and menus may remain, which can be deleted manually. 
  • When faking behavior for a chained call beginning with a static method for than once, the last behavior may override previous expectations:
  • Isolate.WhenCalled(() => ProductFactory.GetProduct().Name).WillReturn("ProductA");
    Isolate.WhenCalled(() => ProductFactory.GetProduct().Price).WillReturn(100);

    // may fail: the second behavior setting declaration overrid the first.
    Assert.AreEqual("ProductA", ProductFactory.GetProduct.Name);
  • Isolator AAA does not support nested chains in WhenCalled() and Verify methods:
  • Isolate.WhenCalled(() => fake.Call(fake.Do())).WillReturn(0); // not supported

    // instead extract the inner chain to a variable:
    var innerChain = fake.Do();
    Isolate.WhenCalled(() => fake.Call(innerChain)).WillReturn(0); // supported


Breaking changes
  • Starting version 5.1.1: Obsoleted Isolate.SwapNextInstance() which is replaced by Isolate.Swap.NextInstance(). This is done for consistency with other entries under Isolate.Swap.
  • The default behavior for creating fake objects has been changed to Members.ReturnRecursiveFakes when cretaing a  fake instace without any parameters.
  • True Indexers: Must specify the exact index in WhenCalled/TheseCall block. Using dummy values (i.e. empty string or '0') for index in WhenCalled/TheseCalls block shall cause the test to break.


 

Copyright © Typemock Ltd. 2004-2020. All Rights Reserved.