This isn't of much help to your VB Unit test, but the C# equivalent works just fine:
var schedules = new List<Schedule>
{
Mock.Of<Schedule>(
s => s.ActiveFrom == new DateTime(2010, 01, 01)
&& s.ActiveUntil == new Nullable<DateTime>(new DateTime(2110, 01, 01)))
};
Assert.IsTrue((schedules.Count == 1) &&
schedules.Single(_ => (_.ActiveFrom == new DateTime(2010, 01, 01))
&& (_.ActiveUntil == new DateTime(2110, 01, 01))) != null);
It also isn't related to the implicit comparison of DateTime
to DateTime?
either as careful unpacking of the DateTime?
also fails:
AndAlso If(Not s.ActiveUntil.HasValue, False,
s.ActiveUntil.Value = New DateTime("2110-01-01")
I believe the issue may relate to Mock.Of's usage of parsed Expressions
during construction of the mock from the predicate provided - possibly there is nuance in VB which wasn't considered.
If so, and assuming you don't want to change your unit tests to C#, you may need to either need to build the Expressions by hand to get the Mock.Of(predicate)
goodness to work, or revert to old style creation of your Mock / Fake objects:
Dim scheduleMock As New Mock(Of Schedule)
scheduleMock.SetupGet(Function(s) s.ActiveFrom).Returns("2010-01-01")
scheduleMock.SetupGet(Function(s) s.ActiveUntil).Returns(New DateTime?("2110-01-01"))
Dim schedules = New List(Of Schedule) From
{
scheduleMock.Object
}
Assert.IsTrue(schedules.Count = 1)
Assert.IsTrue(schedules.First.ActiveFrom = "2010-01-01"
AndAlso schedules.First.ActiveUntil = "2110-01-01")