What a long title :D.

I use nUnit (funny how they use php for their website) for my testing together with Resharper they make a good team.

So lets first look at one of my DomainObjects/Entities.

Namespace AddressManagement
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    <CLSCompliant(True)> _
    <NHibernate.Mapping.Attributes.JoinedSubclass(0, Table:="tbl_Country", extendstype:=GetType(Common.Translated), lazy:=False)> _
    Public Class Country
        Inherits Common.Translated
        Implements Interfaces.ICountry

#Region " Private members "
        ''' <summary>
        ''' A local variable called _name of type String
        ''' </summary>
        ''' <remarks>Has Property Name</remarks>
        Private _name As String
#End Region

#Region " Constructors "
        ''' <summary>
        ''' Default empty constructor
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            Me.New("", New Common.Translation(), "")
        End Sub

        ''' <summary>
        ''' Constructor to fill the name. 
        ''' </summary>
        ''' <param name="Name">Datatype = String</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal Name As String)
            Me.New(Name, New Common.Translation(), "")
        End Sub

        ''' <summary>
        ''' Constructor with all the fields
        ''' </summary>
        ''' <param name="Name">DataType = String</param>
        ''' <param name="description"></param>
        ''' <param name="Remarks"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal Name As String, ByVal description As Common.Translation, ByVal Remarks As String)
            Me.Name = Name
            Me.Description = description
            Me.Remarks = Remarks
            ClearDirtyStatus()
        End Sub
#End Region

#Region " Public properties "
        ''' <summary>
        ''' This is the Name property.
        ''' </summary>
        ''' <value>String</value>
        ''' <returns>String</returns>
        ''' <remarks></remarks>
        <NHibernate.Mapping.Attributes.Key(1, column:="Id")> _
        <NHibernate.Mapping.Attributes.Property(2, length:=50)> _
        Public Overridable Property Name() As String Implements Interfaces.ICountry.Name, Common.Interfaces.ITranslatedSubClass.Key
            Get
                Return _name
            End Get
            Set(ByVal Value As String)
                _name = Value
                SetDirty()
            End Set
        End Property
#End Region

#Region " Overrides ToString "
        ''' <summary>
        ''' Overridden ToString method for this class
        ''' </summary>
        ''' <returns>String</returns>
        ''' <remarks>The String value of this class represented by the ToStrings of all it's private members</remarks>
        Public Overrides Function ToString() As String
            Dim ReturnString As New System.Text.StringBuilder()
            If _name IsNot Nothing Then
                ReturnString.Append("[Name: " & _name.ToString() & "]")
            End If
            Return ReturnString.ToString()
        End Function
#End Region

#Region " Overrides Equals "
        ''' <summary>
        ''' Overridden Equals method for this class
        ''' </summary>
        ''' <returns>Boolean</returns>
        ''' <remarks>The Boolean value indictaing if this is equal to the other class</remarks>
        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            If obj IsNot Nothing Then
                If obj.GetType Is Me.GetType Then
                    Return Me._name.Equals(CType(obj, Country)._name)
                Else
                    Return False
                End If
            Else
                Return False
            End If
        End Function
#End Region

#Region " Overrides CompareTo "
        ''' <summary>
        ''' Overridden CompareTo method for this class
        ''' </summary>
        ''' <returns>Integer</returns>
        ''' <remarks></remarks>
        Public Overrides Function CompareTo(ByVal obj As Object) As Integer
            If obj IsNot Nothing Then
                If obj.GetType Is Me.GetType Then
                    Return Me._name.CompareTo(CType(obj, Country)._name)
                Else
                    Return -1
                End If
            Else
                Return -1
            End If
        End Function
#End Region

    End Class
End Namespace

There is quit a lot of code in this simple Entity. First of all it inherits from Common.Translated (which I won’t show. But that in turn inherited from DomainEntity. Look at my post from a couple of days ago to see what that does.

Then I override (always) tostring, compareto and equals. Then I have 3 constructors and one property. So now we need to test all this.

Imports NUnit.Framework

Namespace AddressManagement.Test
    ''' <summary>
    ''' Test Class to test the Country Class
    ''' </summary>
    ''' <remarks>Tests all the methods of this class</remarks>
    <TestFixture(Description:="Test Country")> _
    <Category("Model")> _
    <Category("Model.AddressManagement")> _
    Public Class TestCountry
        Implements Util.Interfaces.ITest

#Region " Private members "
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Country1 As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Country1a As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Country2 As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Country3 As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Country4 As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private Country5 As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private CountryNothing As Model.AddressManagement.Country
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private CountryList As List(Of Model.AddressManagement.Country)
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Private otherObject As New TextBox()
#End Region

#Region " Setup tests "
        ''' <summary>
        ''' Setup the private members
        ''' </summary>
        ''' <remarks></remarks>
        <SetUp()> _
        Public Sub Setup() Implements Util.Interfaces.ITest.Setup
            Country1 = New Model.AddressManagement.Country()
            Country1a = New Model.AddressManagement.Country()
            Country2 = New Model.AddressManagement.Country("Country 2", New Model.Common.Translation(), "")
            Country3 = New Model.AddressManagement.Country("Country 3", New Model.Common.Translation(), "")
            Country4 = New Model.AddressManagement.Country("Country 4", New Model.Common.Translation(), "")
            Country5 = New Model.AddressManagement.Country("Country 5", New Model.Common.Translation(), "")
            CountryList = New List(Of Model.AddressManagement.Country)
        End Sub
#End Region

#Region " Tests "
        ''' <summary>
        ''' Test Compareto
        ''' </summary>
        ''' <remarks></remarks>
        <Test(Description:="Test Compareto")> _
        Public Sub TestCompareTo() Implements Util.Interfaces.ITest.TestCompareTo
            CountryList.Add(Country1)
            CountryList.Add(Country1a)
            CountryList.Add(Country2)
            CountryList.Add(Country3)
            CountryList.Add(Country4)
            CountryList.Add(Country5)
            CountryList.Add(CountryNothing)
            CountryList.Reverse()
            Assert.AreNotEqual(Country5, CountryList(0))
            Assert.AreNotEqual(Country1, CountryList(0))
            Assert.AreNotEqual(Country1a, CountryList(0))
            Assert.AreNotEqual(Country2, CountryList(0))
            Assert.AreNotEqual(Country3, CountryList(0))
            Assert.AreNotEqual(Country4, CountryList(0))
            Assert.AreEqual(CountryNothing, CountryList(0))
            Assert.AreEqual(Country5, CountryList(1))
            Assert.AreNotEqual(Country1, CountryList(1))
            Assert.AreNotEqual(Country1a, CountryList(1))
            Assert.AreNotEqual(Country2, CountryList(1))
            Assert.AreNotEqual(Country3, CountryList(1))
            Assert.AreNotEqual(Country4, CountryList(1))
            Assert.AreNotEqual(CountryNothing, CountryList(1))
            Assert.AreEqual(Country4, CountryList(2))
            Assert.AreNotEqual(Country1, CountryList(2))
            Assert.AreNotEqual(Country1a, CountryList(2))
            Assert.AreNotEqual(Country2, CountryList(2))
            Assert.AreNotEqual(Country3, CountryList(2))
            Assert.AreNotEqual(Country5, CountryList(2))
            Assert.AreNotEqual(CountryNothing, CountryList(2))
            Assert.AreEqual(Country3, CountryList(3))
            Assert.AreNotEqual(Country1, CountryList(3))
            Assert.AreNotEqual(Country1a, CountryList(3))
            Assert.AreNotEqual(Country2, CountryList(3))
            Assert.AreNotEqual(Country5, CountryList(3))
            Assert.AreNotEqual(Country4, CountryList(3))
            Assert.AreNotEqual(CountryNothing, CountryList(3))
            Assert.AreEqual(Country2, CountryList(4))
            Assert.AreNotEqual(Country1, CountryList(4))
            Assert.AreNotEqual(Country1a, CountryList(4))
            Assert.AreNotEqual(Country5, CountryList(4))
            Assert.AreNotEqual(Country3, CountryList(4))
            Assert.AreNotEqual(Country4, CountryList(4))
            Assert.AreNotEqual(CountryNothing, CountryList(4))
            Assert.AreEqual(Country1, CountryList(5))
            Assert.AreEqual(Country1a, CountryList(5))
            Assert.AreNotEqual(Country5, CountryList(5))
            Assert.AreNotEqual(Country2, CountryList(5))
            Assert.AreNotEqual(Country3, CountryList(5))
            Assert.AreNotEqual(Country4, CountryList(5))
            Assert.AreNotEqual(CountryNothing, CountryList(5))
            Assert.AreEqual(Country1a, CountryList(6))
            Assert.AreEqual(Country1, CountryList(6))
            Assert.AreNotEqual(Country5, CountryList(6))
            Assert.AreNotEqual(Country2, CountryList(6))
            Assert.AreNotEqual(Country3, CountryList(6))
            Assert.AreNotEqual(Country4, CountryList(6))
            Assert.AreNotEqual(CountryNothing, CountryList(6))
            CountryList.Sort()
            Assert.AreNotEqual(Country1, CountryList(0))
            Assert.AreNotEqual(Country1a, CountryList(0))
            Assert.AreNotEqual(Country2, CountryList(0))
            Assert.AreNotEqual(Country3, CountryList(0))
            Assert.AreNotEqual(Country4, CountryList(0))
            Assert.AreNotEqual(Country5, CountryList(0))
            Assert.AreEqual(CountryNothing, CountryList(0))
            Assert.AreEqual(Country1, CountryList(1))
            Assert.AreEqual(Country1a, CountryList(1))
            Assert.AreNotEqual(Country2, CountryList(1))
            Assert.AreNotEqual(Country3, CountryList(1))
            Assert.AreNotEqual(Country4, CountryList(1))
            Assert.AreNotEqual(Country5, CountryList(1))
            Assert.AreNotEqual(CountryNothing, CountryList(1))
            Assert.AreEqual(Country1, CountryList(2))
            Assert.AreEqual(Country1a, CountryList(2))
            Assert.AreNotEqual(Country2, CountryList(2))
            Assert.AreNotEqual(Country3, CountryList(2))
            Assert.AreNotEqual(Country4, CountryList(2))
            Assert.AreNotEqual(Country5, CountryList(2))
            Assert.AreNotEqual(CountryNothing, CountryList(2))
            Assert.AreNotEqual(Country1, CountryList(3))
            Assert.AreNotEqual(Country1a, CountryList(3))
            Assert.AreEqual(Country2, CountryList(3))
            Assert.AreNotEqual(Country3, CountryList(3))
            Assert.AreNotEqual(Country4, CountryList(3))
            Assert.AreNotEqual(Country5, CountryList(3))
            Assert.AreNotEqual(CountryNothing, CountryList(3))
            Assert.AreNotEqual(Country1, CountryList(4))
            Assert.AreNotEqual(Country1a, CountryList(4))
            Assert.AreNotEqual(Country2, CountryList(4))
            Assert.AreEqual(Country3, CountryList(4))
            Assert.AreNotEqual(Country4, CountryList(4))
            Assert.AreNotEqual(Country5, CountryList(4))
            Assert.AreNotEqual(CountryNothing, CountryList(4))
            Assert.AreNotEqual(Country1, CountryList(5))
            Assert.AreNotEqual(Country1a, CountryList(5))
            Assert.AreNotEqual(Country2, CountryList(5))
            Assert.AreNotEqual(Country3, CountryList(5))
            Assert.AreEqual(Country4, CountryList(5))
            Assert.AreNotEqual(Country5, CountryList(5))
            Assert.AreNotEqual(CountryNothing, CountryList(5))
            Assert.AreNotEqual(Country1, CountryList(6))
            Assert.AreNotEqual(Country1a, CountryList(6))
            Assert.AreNotEqual(Country2, CountryList(6))
            Assert.AreNotEqual(Country3, CountryList(6))
            Assert.AreNotEqual(Country4, CountryList(6))
            Assert.AreEqual(Country5, CountryList(6))
            Assert.AreNotEqual(CountryNothing, CountryList(6))
            Assert.AreEqual(-1, Country1.CompareTo(otherObject))
        End Sub

        ''' <summary>
        ''' Test Constructors
        ''' </summary>
        ''' <remarks></remarks>
        <Test(Description:="Test Constructors")> _
        Public Sub TestConstructors() Implements Util.Interfaces.ITest.TestConstructors
            Assert.AreEqual("", Country1.Remarks)
            Assert.AreEqual("", Country1.Name)
            Assert.IsNull(Country1.Id)
            Assert.IsNotNull(Country1.Description)
            Assert.AreEqual("", Country2.Remarks)
            Assert.AreEqual("Country 2", Country2.Name)
            Assert.IsNull(Country2.Id)
            Assert.IsNotNull(Country2.Description)
        End Sub

        ''' <summary>
        ''' Test Equals
        ''' </summary>
        ''' <remarks></remarks>
        <Test(Description:="Test Equals")> _
        Public Sub TestEquals() Implements Util.Interfaces.ITest.TestEquals
            Assert.AreEqual(True, Country1.Equals(Country1))
            Assert.AreEqual(True, Country1.Equals(Country1a))
            Assert.AreEqual(True, Country1a.Equals(Country1))
            Assert.AreEqual(True, Country1a.Equals(Country1a))
            Assert.AreEqual(True, Country2.Equals(Country2))
            Assert.AreEqual(True, Country3.Equals(Country3))
            Assert.AreEqual(True, Country4.Equals(Country4))
            Assert.AreEqual(True, Country5.Equals(Country5))
            Assert.AreEqual(False, Country1.Equals(Country2))
            Assert.AreEqual(False, Country1.Equals(Country3))
            Assert.AreEqual(False, Country1.Equals(Country4))
            Assert.AreEqual(False, Country1.Equals(Country5))
            Assert.AreEqual(False, Country1.Equals(CountryNothing))
            Assert.AreEqual(False, Country1.Equals(otherObject))
            Assert.AreEqual(False, Country1a.Equals(Country2))
            Assert.AreEqual(False, Country1a.Equals(Country3))
            Assert.AreEqual(False, Country1a.Equals(Country4))
            Assert.AreEqual(False, Country1a.Equals(Country5))
            Assert.AreEqual(False, Country1a.Equals(CountryNothing))
            Assert.AreEqual(False, Country1a.Equals(otherObject))
            Assert.AreEqual(False, Country2.Equals(Country1))
            Assert.AreEqual(False, Country2.Equals(Country1a))
            Assert.AreEqual(False, Country2.Equals(Country3))
            Assert.AreEqual(False, Country2.Equals(Country4))
            Assert.AreEqual(False, Country2.Equals(Country5))
            Assert.AreEqual(False, Country2.Equals(CountryNothing))
            Assert.AreEqual(False, Country2.Equals(otherObject))
            Assert.AreEqual(False, Country3.Equals(Country1))
            Assert.AreEqual(False, Country3.Equals(Country1a))
            Assert.AreEqual(False, Country3.Equals(Country2))
            Assert.AreEqual(False, Country3.Equals(Country4))
            Assert.AreEqual(False, Country3.Equals(Country5))
            Assert.AreEqual(False, Country3.Equals(CountryNothing))
            Assert.AreEqual(False, Country3.Equals(otherObject))
            Assert.AreEqual(False, Country4.Equals(Country1))
            Assert.AreEqual(False, Country4.Equals(Country1a))
            Assert.AreEqual(False, Country4.Equals(Country2))
            Assert.AreEqual(False, Country4.Equals(Country3))
            Assert.AreEqual(False, Country4.Equals(Country5))
            Assert.AreEqual(False, Country4.Equals(CountryNothing))
            Assert.AreEqual(False, Country4.Equals(otherObject))
            Assert.AreEqual(False, Country5.Equals(Country1))
            Assert.AreEqual(False, Country5.Equals(Country1a))
            Assert.AreEqual(False, Country5.Equals(Country2))
            Assert.AreEqual(False, Country5.Equals(Country3))
            Assert.AreEqual(False, Country5.Equals(Country4))
            Assert.AreEqual(False, Country5.Equals(CountryNothing))
            Assert.AreEqual(False, Country5.Equals(otherObject))
        End Sub

        ''' <summary>
        ''' Test Properties
        ''' </summary>
        ''' <remarks></remarks>
        <Test(Description:="Test properties")> _
        Public Sub TestProperties() Implements Util.Interfaces.ITest.TestProperties
            Country1.Description = New Model.Common.Translation("en", "nl", "fr")
            Country1.Name = "Country 1"
            Country1.Remarks = "Remarks"
            Assert.AreEqual("en", Country1.Description.En)
            Assert.AreEqual("fr", Country1.Description.Fr)
            Assert.AreEqual("nl", Country1.Description.Nl)
            Assert.AreEqual("Country 1", Country1.Name)
            Assert.AreEqual("Remarks", Country1.Remarks)
            Assert.IsNull(Country1.Id)
        End Sub

        ''' <summary>
        ''' Test ToString
        ''' </summary>
        ''' <remarks></remarks>
        <Test(Description:="Test ToString")> _
        Public Sub TestToString() Implements Util.Interfaces.ITest.TestToString
            Assert.AreEqual(True, Country1.ToString.StartsWith("[Name: "))
            Assert.AreEqual(True, Country2.ToString.StartsWith("[Name: "))
            Assert.AreEqual(True, Country3.ToString.StartsWith("[Name: "))
            Assert.AreEqual(True, Country4.ToString.StartsWith("[Name: "))
            Assert.AreEqual(True, Country5.ToString.StartsWith("[Name: "))
        End Sub

        <Test()> _
        Public Sub TestIFIsDirtyIsFalseAfterNew()
            Dim _Country As New Model.AddressManagement.Country()
            Assert.AreEqual(False, _Country.IsDirty)
            _Country = New Model.AddressManagement.Country("test")
            Assert.AreEqual(False, _Country.IsDirty)
            _Country = New Model.AddressManagement.Country("test", Nothing, "")
            Assert.AreEqual(False, _Country.IsDirty)
        End Sub

        <Test()> _
        Public Sub TestIfIsDirtyIsTruAfterUpdatePropertyCountry()
            Dim _Country As New Model.AddressManagement.Country()
            Assert.AreEqual(False, _Country.IsDirty)
            _Country.Name = "Test"
            Assert.AreEqual(True, _Country.IsDirty)
        End Sub
#End Region

    End Class
End Namespace

Yep a whole lot more code. Read it and ask questions if needed.