Hi,
I'm testing StructuralEqualityComparer (wich is a great idea) in
vb.net 3.5 and mbunit 3.2.0.0.
AreElementsEqual works fine with collection containing null values,
exemple :
--------------------------------------------------------------------
<Test()> _
Public Sub dummy()
Dim actual As New List(Of Date)(New Date() {Nothing,
#2/2/2002#})
Dim expected As New List(Of Date)(New Date() {Nothing,
#2/2/2002#})
Assert.AreElementsEqual(expected, actual)
End Sub
--------------------------------------------------------------------
But when using AreElementsEqual with StructuralEqualityComparer and
when a collection item is null, System.NullReferenceException is
raised, exemple :
--------------------------------------------------------------------
Public Class Dateclass
Public dateutc As Date
Public Sub New(ByVal pDateUtc As Date)
Me.dateutc = pDateUtc
End Sub
End Class
''' <summary>Lambda expression are better in C#</summary>
Public Shared ReadOnly Property DateclassEqualityComparer() As
StructuralEqualityComparer(Of Dateclass)
Get
Dim ec As New StructuralEqualityComparer(Of Dateclass)
ec.Add(Function(item As Dateclass) item.dateutc)
Return ec
End Get
End Property
<Test()> _
Public Sub dummyOk()
Dim actual As New List(Of Dateclass)(New Dateclass() {New
Dateclass(#2/2/2002#)})
Dim expected As New List(Of Dateclass)(New Dateclass() {New
Dateclass(#2/2/2002#)})
Assert.AreElementsEqual(expected, actual,
Exemple.DateclassEqualityComparer)
End Sub
<Test()> _
Public Sub dummyFail()
Dim actual As New List(Of Dateclass)(New Dateclass() {Nothing,
New
Dateclass(#2/2/2002#)})
Dim expected As New List(Of Dateclass)(New Dateclass()
{Nothing, New
Dateclass(#2/2/2002#)})
Assert.AreElementsEqual(expected, actual,
Exemple.DateclassEqualityComparer)
End Sub
--------------------------------------------------------------------
"dummyFail" throw System.NullReferenceException : is it a bug ? Is
there a workaround ?
Thanks !
--
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/mbunituser?hl=en.