Typemock Isolator 5.3.1 can fake DateTime.Now

I just downloaded and installed Isolator 5.3.1 which has the ability to fake DateTime.Now, probably one of those functions in .NET you’ve always wanted to isolate correctly in tests. And now you can. For quick reference, check the Typemock Insider blog.

This can however be a breaking change in your unit tests. For example, we had the following test to verify of a DateTime was put into a property.

Isolate.Verify.WasCalledWithAnyArguments(() => someObject.ProcessDate = DateTime.Now);

With version 5.3.1 the test failed with the following error message.

TypeMock Verification: Method MyNameSpace.SomeClass.ProcessDate was called with mismatching arguments.

I fixed this by setting the following behavior on DateTime.Now.

// Arrange
var testDate = new DateTime(2000, 1, 1);
Isolate.WhenCalled(() => DateTime.Now).WillReturn(testDate);

// Act
// Some code here

// Assert
Isolate.Verify.WasCalledWithAnyArguments(() => someObject.ProcessDate = testDate);