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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
8d9d49332d44 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 9
diff changeset
1 // This file (WarFoundryLoaderTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard.
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
11
8d9d49332d44 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 9
diff changeset
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
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 using System;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.IO;
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 namespace IBBoard.WarFoundry.API.Factories
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 [TestFixture()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 public class WarFoundryLoaderTest
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
21 private AbstractNativeWarFoundryFactory sysFactory;
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 public void TestLoadWithoutFactoriesCompletesWithoutError()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 WarFoundryLoader.GetDefault().LoadFiles();
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
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 [Test()]
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 public void TestLoadingSystemCompletesWithoutError()
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 {
35
4302e6b2c5c1 Re #228: Crash with missing abilityID
IBBoard <dev@ibboard.co.uk>
parents: 12
diff changeset
32 AbstractWarFoundryLoader loader = WarFoundryLoader.GetDefault();
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
33 DirectoryInfo dir = new DirectoryInfo("testdata");
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
34 loader.RegisterFactory(GetSystemFactory());
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 loader.AddLoadDirectory(dir);
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 loader.LoadFiles();
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 Assert.Greater(loader.GetGameSystems().Length, 0);
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 loader.RemoveLoadDirectory(dir);
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
39 loader.UnregisterFactory(GetSystemFactory());
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
88 private AbstractNativeWarFoundryFactory GetSystemFactory()
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 {
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
90 if (sysFactory == null)
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 {
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
92 sysFactory = new MockSystemFactory();
0
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 }
faf976fe57df Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94
9
f96169484ba5 Fixes #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 4
diff changeset
95 return sysFactory;
0
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 }