annotate WarFoundryFactoryFactoryTest.cs @ 1:b93d6eedc0bb

* Update MonoDevelop Project file for MonoDevelop 2.0a1 * Remove PIDB file (Parser Information Database) from source control
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 16:41:09 +0000
parents faf976fe57df
children 4222cfa99c78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // AbstractNativeWarFoundryFactoryTest.cs
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // Copyright (C) 2007 IBBoard
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 // This library is free software; you can redistribute it and/or
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 // modify it under the terms of the GNU Lesser General Public
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 // License version 2.1 of the License as published by the Free
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 // Software Foundation.
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 //
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 // This library is distributed in the hope that it will be useful,
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 // Lesser General Public License for more details.
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 //
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 // You should have received a copy of the GNU Lesser General Public
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 // License along with this library; if not, write to the Free Software
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 //
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 //
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 using System;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 using NUnit.Framework;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 using IBBoard;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 using IBBoard.WarFoundry.API.Objects;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 using IBBoard.WarFoundry.API.Factories.Xml;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 namespace IBBoard.WarFoundry.API.Factories
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 [TestFixture()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 public class AbstractNativeWarFoundryFactoryTest
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 public void TestFactoryReturnsCorrectClassForDefault()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetDefaultFactoryClass();
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 Assert.AreEqual(GetDefaultFactoryClass(), WarFoundryFactoryFactory.GetFactoryFactory().GetFactory().GetType(), "AbstractNativeWarFoundryFactory returned incorrect default factory type");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 [Ignore("Only one class of factory exists in current implementation")]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 public void TestFactoryReturnsCorrectClassForAlteredDefault()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetDefaultFactoryClass();
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetOtherFactoryClass();
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 Assert.AreEqual(GetOtherFactoryClass(), WarFoundryFactoryFactory.GetFactoryFactory().GetFactory().GetType(), "AbstractNativeWarFoundryFactory returned incorrect default factory type for updated factory");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 public void TestFactoryReturnsCorrectClassForXmlFactory()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 Assert.AreEqual(WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()).GetType(), GetFactoryClass(), "AbstractNativeWarFoundryFactory failed to return correct type when passed a valid type");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 public void TestFactoryReturnsEqualFactoryForMatchingClasses()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 Assert.AreEqual(first, second, "AbstractNativeWarFoundryFactory failed to return equal factory for matching string");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 public void TestFactoryReturnsSameFactoryForMatchingClasses()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 Assert.IsTrue(first == second, "AbstractNativeWarFoundryFactory failed to return cached factory");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 //[ExpectedException(typeof(ArgumentException), ExpectedMessage="was not a subtype", MatchType=MessageMatch.Contains )]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 [ExpectedException(typeof(ArgumentException))]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 public void TestFactoryThrowsArgumentExceptionForInvalidClass()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetInvalidFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 Assert.Fail("Exceptect exception was not thrown");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 //[ExpectedException(typeof(ArgumentException), ExpectedMessage="was not a subtype", MatchType=MessageMatch.Contains )]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 [ExpectedException(typeof(ArgumentException))]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 public void TestFactoryThrowsArgumentExceptionForAbstractClass()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(typeof(AbstractNativeWarFoundryFactory));
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 Assert.Fail("Exceptect exception was not thrown");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 [Ignore("Only one class of factory exists in current implementation")]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 public void TestFactoryReturnsEqualFactoriesForSameClassAfterDifferentClasses()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetOtherFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 Assert.AreEqual(first, second, "AbstractNativeWarFoundryFactory did not return the same factory after creating a new factory of a different class");
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 private Type GetDefaultFactoryClass()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 return typeof(WarFoundryXmlFactory);
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 private Type GetInvalidFactoryClass()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 return typeof(String);
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 private Type GetFactoryClass()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 return typeof(WarFoundryXmlFactory);
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 private Type GetOtherFactoryClass()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 //TODO: Fill in when we have a second class
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 return null;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 }