view API/Factories/Xml/WarFoundryXmlFactoryTests.cs @ 228:7c21ca1482cb

Re #419: Remove assumptions of a file-based install * Update tests to use new "loadable object" and "loadable object source" wrappers
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Jul 2012 21:02:53 +0100
parents 3c2c108a2f08
children 6ec46f3db2d4
line source
1 using System;
2 using NUnit.Framework;
3 using System.IO;
4 using System.Collections.Generic;
5 using IBBoard.WarFoundry.API.Objects;
6 using NUnit.Framework.SyntaxHelpers;
7 using IBBoard.WarFoundry.API.Loading;
9 namespace IBBoard.WarFoundry.API.Factories.Xml
10 {
11 [TestFixture()]
12 public class WarFoundryXmlFactoryTests
13 {
14 [Test()]
15 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip()
16 {
17 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
18 WarFoundryLoader.SetDefault(loader);
19 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
20 try
21 {
22 loader.RegisterFactory(factory);
23 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.system"));
24 Assert.That(objs, Has.Count(2));
25 int raceCount = 0;
26 int systemCount = 0;
28 foreach (IWarFoundryObject obj in objs)
29 {
30 if (obj is Race)
31 {
32 raceCount++;
33 }
34 else
35 if (obj is GameSystem)
36 {
37 systemCount++;
38 }
39 }
41 Assert.That(raceCount, Is.EqualTo(1));
42 Assert.That(systemCount, Is.EqualTo(1));
43 }
44 finally
45 {
46 loader.UnregisterFactory(factory);
47 }
48 }
50 [Test()]
51 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneRaceZip()
52 {
53 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
54 WarFoundryLoader.SetDefault(loader);
55 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
56 loader.RegisterFactory(factory);
57 try
58 {
59 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.race"));
60 Assert.That(objs, Has.Count(2));
61 int raceCount = 0;
62 int systemCount = 0;
64 foreach (IWarFoundryObject obj in objs)
65 {
66 if (obj is Race)
67 {
68 raceCount++;
69 }
70 else
71 if (obj is GameSystem)
72 {
73 systemCount++;
74 }
75 }
77 Assert.That(raceCount, Is.EqualTo(1));
78 Assert.That(systemCount, Is.EqualTo(1));
79 }
80 finally
81 {
82 loader.UnregisterFactory(factory);
83 }
84 }
86 [Test()]
87 public void TestFactoryHandlesMultipleFilesWithMultipleNewNamesInOneSystemZip()
88 {
89 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
90 WarFoundryLoader.SetDefault(loader);
91 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
92 loader.RegisterFactory(factory);
93 try
94 {
95 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Multipack.system"));
96 Assert.That(objs, Has.Count(4));
97 int raceCount = 0;
98 int systemCount = 0;
100 foreach (IWarFoundryObject obj in objs)
101 {
102 if (obj is Race)
103 {
104 raceCount++;
105 }
106 else
107 if (obj is GameSystem)
108 {
109 systemCount++;
110 }
111 }
113 Assert.That(raceCount, Is.EqualTo(2));
114 Assert.That(systemCount, Is.EqualTo(2));
115 }
116 finally
117 {
118 loader.UnregisterFactory(factory);
119 }
120 }
121 }
122 }