Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/WarFoundryLoaderTest.cs @ 176:9a1763af5fd2
Re #338: WarFoundry.API - Save System Data
* Add tests for saving point names
* Add expected values for new tests
* Add points names to existing expected values (because we don't know if they were default or not)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 26 Oct 2011 15:40:52 +0100 |
parents | 17c5030485dc |
children | 7c21ca1482cb |
rev | line source |
---|---|
11 | 1 // This file (WarFoundryLoaderTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard. |
0 | 2 // |
11 | 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. |
0 | 4 |
5 using System; | |
6 using System.IO; | |
7 using NUnit.Framework; | |
12
a4e7e938d065
Re #195: Setting max equipment without min may not function correctly
IBBoard <dev@ibboard.co.uk>
parents:
11
diff
changeset
|
8 using IBBoard.WarFoundry.API.Factories.Mock; |
0 | 9 using IBBoard.WarFoundry.API.Objects; |
86
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
10 using NUnit.Framework.SyntaxHelpers; |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
11 using System.Collections.Generic; |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
12 using IBBoard.WarFoundry.API.Factories.Xml; |
157
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
13 using IBBoard.WarFoundry.API.Factories.Requirement; |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
14 using IBBoard.WarFoundry.API.Objects.Requirement; |
0 | 15 |
16 namespace IBBoard.WarFoundry.API.Factories | |
17 { | |
18 [TestFixture()] | |
19 public class WarFoundryLoaderTest | |
20 { | |
9 | 21 private AbstractNativeWarFoundryFactory sysFactory; |
0 | 22 |
23 [Test()] | |
24 public void TestLoadWithoutFactoriesCompletesWithoutError() | |
25 { | |
26 WarFoundryLoader.GetDefault().LoadFiles(); | |
27 } | |
28 | |
29 [Test()] | |
30 public void TestLoadingSystemCompletesWithoutError() | |
31 { | |
35
4302e6b2c5c1
Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents:
12
diff
changeset
|
32 AbstractWarFoundryLoader loader = WarFoundryLoader.GetDefault(); |
9 | 33 DirectoryInfo dir = new DirectoryInfo("testdata"); |
34 loader.RegisterFactory(GetSystemFactory()); | |
0 | 35 loader.AddLoadDirectory(dir); |
36 loader.LoadFiles(); | |
37 Assert.Greater(loader.GetGameSystems().Length, 0); | |
38 loader.RemoveLoadDirectory(dir); | |
9 | 39 loader.UnregisterFactory(GetSystemFactory()); |
0 | 40 } |
86
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
41 |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
42 [Test()] |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
43 public void TestBug318LoadingSingleFileShouldNotNullRef() |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
44 { |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
45 DefaultWarFoundryLoader loader = new DefaultWarFoundryLoader(); |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
46 loader.RegisterFactory(WarFoundryXmlFactory.GetFactory()); |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
47 ICollection<IWarFoundryObject> objs = loader.LoadFile(new FileInfo("testdata/Test.system")); |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
48 Assert.That(objs, Has.Count(1)); |
d1ec7618f812
Fixes #318: DefaultWarFoundryLoader throws null ref when loading individual files
IBBoard <dev@ibboard.co.uk>
parents:
35
diff
changeset
|
49 } |
157
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
50 |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
51 [Test()] |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
52 public void TestRegisterRequirementFactoryAddsFactory() |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
53 { |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
54 string factoryID = "SomeID"; |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
55 MockRequirementFactory mockFactory = new MockRequirementFactory(factoryID); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
56 WarFoundryLoader.RegisterRequirementFactory(mockFactory); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
57 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory)); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
58 Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
59 } |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
60 |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
61 [Test()] |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
62 public void TestRegisterRequirementFactoryAddsFactories() |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
63 { |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
64 string factoryID1 = "SomeID"; |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
65 MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID1); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
66 WarFoundryLoader.RegisterRequirementFactory(mockFactory1); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
67 string factoryID2 = "SomeOtherID"; |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
68 MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID2); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
69 WarFoundryLoader.RegisterRequirementFactory(mockFactory2); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
70 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID1), Is.EqualTo(mockFactory1)); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
71 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID2), Is.EqualTo(mockFactory2)); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
72 Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
73 } |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
74 |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
75 [Test()] |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
76 public void TestRegisterRequirementFactoryOverridesWithSecondFactory() |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
77 { |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
78 string factoryID = "SomeID"; |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
79 MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
80 WarFoundryLoader.RegisterRequirementFactory(mockFactory1); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
81 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory1)); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
82 MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
83 WarFoundryLoader.RegisterRequirementFactory(mockFactory2); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
84 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.Not.EqualTo(mockFactory1)); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
85 Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory2)); |
17c5030485dc
Re #351: Add extensible requirement handling method
IBBoard <dev@ibboard.co.uk>
parents:
86
diff
changeset
|
86 } |
0 | 87 |
9 | 88 private AbstractNativeWarFoundryFactory GetSystemFactory() |
0 | 89 { |
9 | 90 if (sysFactory == null) |
0 | 91 { |
9 | 92 sysFactory = new MockSystemFactory(); |
0 | 93 } |
94 | |
9 | 95 return sysFactory; |
0 | 96 } |
97 } | |
98 } |