I'm creating a wrapped type similar to Nullable(Of T)
and I'm writing some unit test to test equality. Like Nullable(Of T)
I have implicit conversion between MyWrapperType(Of T)
and T
(both directions). Therefore, I would have expected all of the following tests in NUnit to pass:
Dim x = New MyWrapperType(Of DateTime)(Date.MaxValue)
Assert.True(Date.MaxValue = x)
Assert.True(x = Date.MaxValue)
Assert.True(Date.MaxValue.Equals(x))
Assert.True(x.Equals(Date.MaxValue))
Assert.AreEqual(x, Date.MaxValue)
Assert.AreEqual(Date.MaxValue, x)
They all do, except the last one. It tells me that:
Failed: Expected: 9999-12-31 23:59:59.999 But was: <12/31/9999 11:59:59 PM>
Here are some functions from my type that may be relevant. Note: my type has a Value
property similiar to Nullable(Of T)
:
Public Shared Widening Operator CType(value As T) As MyWrapperType(Of T)
Return New MyWrapperType(Of T)(value)
End Operator
Public Shared Widening Operator CType(value As MyWrapperType(Of T)) As T
Return value.Value
End Operator
Public Overrides Function Equals(other As Object) As Boolean
If Me.Value Is Nothing Then Return other Is Nothing
If other Is Nothing Then Return False
Return Me.Value.Equals(other)
End Function
Public Overrides Function GetHashCode() As Integer
If Me.Value Is Nothing Then Return 0
Return Me.Value.GetHashCode()
End Function
When setting breakpoints on these methods methods for the test that fails, none of them get hit except ToString
which gets called when they're formatting the error to display.
Why does this call to Assert.AreEqual
only fail in one direction? Is this something wrong within nunit.framework.dll
(using version 2.6.1.12217)? Or am I missing a bug in my code?