I have the following code:
<TestMethod()> _
Public Sub GetDirectoryEntryTest()
Dim path As String = runner.getLDAPPath()
Dim expected As DirectoryEntry = runner.GetDirectoryEntry()
Dim actual As DirectoryEntry
actual = LDAPBase.GetDirectoryEntry(path)
Assert.AreEqual(expected, actual)
End Sub
This unit test fails. The DirectoryEntry objects are exactly the same, but different references to different objects. I come from a Java background where you always have the .equals().
What can I do so that this will evaluate correctly and return true since for all intents and purposes, the objects are equal. Is there something I can do like I would do in Java and override the equals()?
Try comparing the paths of the objects with something like this:
That will compare the underlying paths (string type) rather than the object references. If the paths being the same is enough you shouldn’t have to override anything.
EDIT:
DirectoryEntry is a reference type that inherits Equals from Object and so:
From Object.Equals Method: