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