comparison 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
comparison
equal deleted inserted replaced
6:2f2d6a6d9ffa 7:1ed310d10fc9
1 // This file (AbstractEqualityTest.cs) is a part of the IBBoard.NUnit project and is copyright 2011 IBBoard
2 //
3 // 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.
4 using System;
5 using NUnit;
6 using NUnit.Framework;
7 using System.Reflection;
8
9 namespace IBBoard.NUnit
10 {
11 public abstract class AbstractEqualityTest<TEST_CLASS>
12 {
13 [Test]
14 public void TestEquality()
15 {
16 Assert.AreEqual(GetObject(), GetSameObject());
17 Assert.AreEqual(GetSameObject(), GetObject());
18 }
19
20 [Test]
21 public void TestInequality()
22 {
23 Assert.AreNotEqual(GetObject(), GetDifferentObject());
24 Assert.AreNotEqual(GetSameObject(), GetDifferentObject());
25 Assert.AreNotEqual(GetDifferentObject(), GetObject());
26 Assert.AreNotEqual(GetDifferentObject(), GetSameObject());
27 }
28
29 [Test]
30 public void TestReflexiveEquality()
31 {
32 Assert.AreEqual(GetObject(), GetObject());
33 Assert.AreEqual(GetSameObject(), GetSameObject());
34 Assert.AreEqual(GetDifferentObject(), GetDifferentObject());
35 }
36
37 [Test]
38 public void TestOtherInequality()
39 {
40 MethodInfo[] methodInfo = GetType().GetMethods();
41 TEST_CLASS obj = GetObject();
42
43 foreach (MethodInfo method in methodInfo)
44 {
45 if (method.Name.StartsWith("GetOtherDifferent"))
46 {
47 TEST_CLASS otherObj = (TEST_CLASS)method.Invoke(this, new object[0]);
48 Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name);
49 Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name);
50 }
51 }
52 }
53
54 public abstract TEST_CLASS GetObject();
55
56 public abstract TEST_CLASS GetSameObject();
57
58 public abstract TEST_CLASS GetDifferentObject();
59 }
60 }
61