Mercurial > repos > IBBoard.NUnit
diff AbstractEqualityTest.cs @ 7:1ed310d10fc9
* Add abstract equality test class (contains basics)
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 25 Apr 2011 14:50:00 +0000 |
parents | |
children | 29850b7c8f33 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AbstractEqualityTest.cs Mon Apr 25 14:50:00 2011 +0000 @@ -0,0 +1,61 @@ +// This file (AbstractEqualityTest.cs) is a part of the IBBoard.NUnit project and is copyright 2011 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using NUnit; +using NUnit.Framework; +using System.Reflection; + +namespace IBBoard.NUnit +{ + public abstract class AbstractEqualityTest<TEST_CLASS> + { + [Test] + public void TestEquality() + { + Assert.AreEqual(GetObject(), GetSameObject()); + Assert.AreEqual(GetSameObject(), GetObject()); + } + + [Test] + public void TestInequality() + { + Assert.AreNotEqual(GetObject(), GetDifferentObject()); + Assert.AreNotEqual(GetSameObject(), GetDifferentObject()); + Assert.AreNotEqual(GetDifferentObject(), GetObject()); + Assert.AreNotEqual(GetDifferentObject(), GetSameObject()); + } + + [Test] + public void TestReflexiveEquality() + { + Assert.AreEqual(GetObject(), GetObject()); + Assert.AreEqual(GetSameObject(), GetSameObject()); + Assert.AreEqual(GetDifferentObject(), GetDifferentObject()); + } + + [Test] + public void TestOtherInequality() + { + MethodInfo[] methodInfo = GetType().GetMethods(); + TEST_CLASS obj = GetObject(); + + foreach (MethodInfo method in methodInfo) + { + if (method.Name.StartsWith("GetOtherDifferent")) + { + TEST_CLASS otherObj = (TEST_CLASS)method.Invoke(this, new object[0]); + Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name); + Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name); + } + } + } + + public abstract TEST_CLASS GetObject(); + + public abstract TEST_CLASS GetSameObject(); + + public abstract TEST_CLASS GetDifferentObject(); + } +} +