Testing problem modules in VB.NET

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 does not work. Objects are DirectoryEntryexactly the same, but different references to different objects. I come from a Java background where you always have it .equals().

What can I do so that it evaluates correctly and returns true, since for all purposes and objects the objects are equal. Is there something I can do, as in Java, and override equals ()?

+5
source share
2 answers

Try comparing the paths of objects with something like this:

Assert.AreEqual(expected.Path, actual.Path)

This will compare the base paths (string type) rather than object references. If the paths are the same, you do not need to redefine anything.

EDIT:

DirectoryEntry - , Equals from Object :

Object.Equals Method:

Equals . , , , . , , , .

+5

? ToString() ? , , ToString() .

DirectoryEntries, IEqualityComparer .

+2

All Articles