using NUnit.Framework; namespace System { /// /// A helper test fixture base class that can be used to test types the /// implement the interface. This set of tests /// also implements the test fixture helper class /// because types that implement are likely to /// overload methods in since they are similar in /// function (for example, and /// ). /// /// The type that is passed to /// as its generic parameter. public abstract class EquatableTests : ObjectTests { [Test, Description("Tests the IEquatable.Equals(T) method to ensure " + "it returns true when passed an instance that should be equal to it.")] public void AreEqual() { IEquatable equatable = CreateEquatable(); T equalInstance = CreateEqualObject(); Assert.That(equatable.Equals(equalInstance), "The IEquatable " + "instance should be equal to the IEquatable instance but the " + "IEquatable.Equals(T) method returned false."); } [Test, Description("Tests the IEquatable.Equals(T) method to ensure " + "it returns false when passed an instance that should NOT be equal to it.")] public void AreNotEqual() { IEquatable equatable = CreateEquatable(); T equalInstance = CreateNotEqualObject(); Assert.That(equatable.Equals(equalInstance) == false, "The " + "IEquatable instance should NOT be equal to the IEquatable " + "instance but the IEquatable.Equals(T) method returned true."); } /// /// Creates an to use for testing. This method /// should always return a new object and never reuse values. /// /// The to be tested protected override object CreateObject() { return CreateEquatable(); } /// /// Creates an to use for testing. This method /// should create an object that is the same as the /// created by but are not the same /// instance (i.e. /// should not return true). This method should always return a new /// object and never reuse values. /// /// The to be tested protected override object CreateSameObject() { return CreateEqualObject(); } /// /// Creates an to use for testing. This method /// should create an object that is different from the /// created by . This method should always /// return a new object and never reuse values. /// /// The to be tested protected override object CreateDifferentObject() { return CreateNotEqualObject(); } /// /// Creates the instance that is to be /// tested. This method should always create a new /// when this method is invoked and never /// reuse instances. /// /// The to test. protected abstract IEquatable CreateEquatable(); /// /// Creates an instance of the type that is /// equal to the instance created by the method /// (i.e., the /// should return true). A new /// instance should be created every time this method is invoked; /// instances should never be reused. /// /// The instance that is to be tested for equality against the /// instance created by . protected abstract T CreateEqualObject(); /// /// Creates an instance of the type that is /// NOT equal to the instance created by the method /// (i.e., the /// should return false). A new /// instance should be created every time this method is invoked; /// instances should never be reused. /// /// The instance that is to be tested for equality against the /// instance created by . protected abstract T CreateNotEqualObject(); } }