4
|
1 // This file (WarFoundryFactoryFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard.
|
0
|
2 //
|
4
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
|
0
|
4
|
|
5 using System;
|
|
6 using NUnit.Framework;
|
|
7 using IBBoard;
|
|
8 using IBBoard.WarFoundry.API.Objects;
|
|
9 using IBBoard.WarFoundry.API.Factories.Xml;
|
|
10
|
|
11 namespace IBBoard.WarFoundry.API.Factories
|
|
12 {
|
|
13 [TestFixture()]
|
|
14 public class AbstractNativeWarFoundryFactoryTest
|
|
15 {
|
|
16 [Test()]
|
|
17 public void TestFactoryReturnsCorrectClassForDefault()
|
|
18 {
|
|
19 WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetDefaultFactoryClass();
|
|
20 Assert.AreEqual(GetDefaultFactoryClass(), WarFoundryFactoryFactory.GetFactoryFactory().GetFactory().GetType(), "AbstractNativeWarFoundryFactory returned incorrect default factory type");
|
|
21 }
|
|
22
|
|
23 [Test()]
|
|
24 [Ignore("Only one class of factory exists in current implementation")]
|
|
25 public void TestFactoryReturnsCorrectClassForAlteredDefault()
|
|
26 {
|
|
27 WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetDefaultFactoryClass();
|
|
28 WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetOtherFactoryClass();
|
|
29 Assert.AreEqual(GetOtherFactoryClass(), WarFoundryFactoryFactory.GetFactoryFactory().GetFactory().GetType(), "AbstractNativeWarFoundryFactory returned incorrect default factory type for updated factory");
|
|
30 }
|
|
31
|
|
32 [Test()]
|
|
33 public void TestFactoryReturnsCorrectClassForXmlFactory()
|
|
34 {
|
|
35 Assert.AreEqual(WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()).GetType(), GetFactoryClass(), "AbstractNativeWarFoundryFactory failed to return correct type when passed a valid type");
|
|
36 }
|
|
37
|
|
38 [Test()]
|
|
39 public void TestFactoryReturnsEqualFactoryForMatchingClasses()
|
|
40 {
|
|
41 IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
|
|
42 IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
|
|
43 Assert.AreEqual(first, second, "AbstractNativeWarFoundryFactory failed to return equal factory for matching string");
|
|
44 }
|
|
45
|
|
46 [Test()]
|
|
47 public void TestFactoryReturnsSameFactoryForMatchingClasses()
|
|
48 {
|
|
49 IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
|
|
50 IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
|
|
51 Assert.IsTrue(first == second, "AbstractNativeWarFoundryFactory failed to return cached factory");
|
|
52 }
|
|
53
|
|
54 [Test()]
|
|
55 //[ExpectedException(typeof(ArgumentException), ExpectedMessage="was not a subtype", MatchType=MessageMatch.Contains )]
|
|
56 [ExpectedException(typeof(ArgumentException))]
|
|
57 public void TestFactoryThrowsArgumentExceptionForInvalidClass()
|
|
58 {
|
|
59 WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetInvalidFactoryClass());
|
|
60 Assert.Fail("Exceptect exception was not thrown");
|
|
61 }
|
|
62
|
|
63 [Test()]
|
|
64 //[ExpectedException(typeof(ArgumentException), ExpectedMessage="was not a subtype", MatchType=MessageMatch.Contains )]
|
|
65 [ExpectedException(typeof(ArgumentException))]
|
|
66 public void TestFactoryThrowsArgumentExceptionForAbstractClass()
|
|
67 {
|
|
68 WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(typeof(AbstractNativeWarFoundryFactory));
|
|
69 Assert.Fail("Exceptect exception was not thrown");
|
|
70 }
|
|
71
|
|
72 [Test()]
|
|
73 [Ignore("Only one class of factory exists in current implementation")]
|
|
74 public void TestFactoryReturnsEqualFactoriesForSameClassAfterDifferentClasses()
|
|
75 {
|
|
76 IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
|
|
77 WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetOtherFactoryClass());
|
|
78 IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass());
|
|
79 Assert.AreEqual(first, second, "AbstractNativeWarFoundryFactory did not return the same factory after creating a new factory of a different class");
|
|
80 }
|
|
81
|
|
82 private Type GetDefaultFactoryClass()
|
|
83 {
|
|
84 return typeof(WarFoundryXmlFactory);
|
|
85 }
|
|
86
|
|
87 private Type GetInvalidFactoryClass()
|
|
88 {
|
|
89 return typeof(String);
|
|
90 }
|
|
91
|
|
92 private Type GetFactoryClass()
|
|
93 {
|
|
94 return typeof(WarFoundryXmlFactory);
|
|
95 }
|
|
96
|
|
97 private Type GetOtherFactoryClass()
|
|
98 {
|
|
99 //TODO: Fill in when we have a second class
|
|
100 return null;
|
|
101 }
|
|
102 }
|
|
103 }
|