Mercurial > repos > IBBoard.NUnit
changeset 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 | 2f2d6a6d9ffa |
children | c69b28a67454 |
files | AbstractEqualityTest.cs IBBoard.NUnit.csproj |
diffstat | 2 files changed, 63 insertions(+), 1 deletions(-) [+] |
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(); + } +} +
--- a/IBBoard.NUnit.csproj Sun Apr 03 13:30:30 2011 +0000 +++ b/IBBoard.NUnit.csproj Mon Apr 25 14:50:00 2011 +0000 @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -61,6 +61,7 @@ <Compile Include="Does.cs" /> <Compile Include="Constraints\ArrayContainsConstraint.cs" /> <Compile Include="AssemblyInfo.cs" /> + <Compile Include="AbstractEqualityTest.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />