Mercurial > repos > IBBoard.WarFoundry.API.Tests
annotate API/Factories/Xml/WarFoundryXmlFactoryTests.cs @ 96:3c2c108a2f08
Re #253: Allow multiple data files in a single zip
* Fix unit tests by unsubscribing at end of test
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 05 Mar 2011 19:53:25 +0000 |
parents | 5d19fee8e9dc |
children | 7c21ca1482cb |
rev | line source |
---|---|
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 using System; |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 using NUnit.Framework; |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 using System.IO; |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System.Collections.Generic; |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using IBBoard.WarFoundry.API.Objects; |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using NUnit.Framework.SyntaxHelpers; |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 namespace IBBoard.WarFoundry.API.Factories.Xml |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 { |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 [TestFixture()] |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 public class WarFoundryXmlFactoryTests |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 [Test()] |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip() |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 { |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
16 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); |
89
90dee8d781ee
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
87
diff
changeset
|
17 WarFoundryLoader.SetDefault(loader); |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
18 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
19 try |
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 { |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
21 loader.RegisterFactory(factory); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
22 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system")); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
23 Assert.That(objs, Has.Count(2)); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
24 int raceCount = 0; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
25 int systemCount = 0; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
26 |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
27 foreach (IWarFoundryObject obj in objs) |
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
29 if (obj is Race) |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
30 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
31 raceCount++; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
32 } |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
33 else if (obj is GameSystem) |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
34 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
35 systemCount++; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
36 } |
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 } |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
38 |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
39 Assert.That(raceCount, Is.EqualTo(1)); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
40 Assert.That(systemCount, Is.EqualTo(1)); |
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 } |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
42 finally |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
43 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
44 loader.UnregisterFactory(factory); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
45 } |
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 } |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
47 |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
48 [Test()] |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
49 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneRaceZip() |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
50 { |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
51 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
52 WarFoundryLoader.SetDefault(loader); |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
53 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
54 loader.RegisterFactory(factory); |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
55 try |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
56 { |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
57 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race")); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
58 Assert.That(objs, Has.Count(2)); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
59 int raceCount = 0; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
60 int systemCount = 0; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
61 |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
62 foreach (IWarFoundryObject obj in objs) |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
63 { |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
64 if (obj is Race) |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
65 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
66 raceCount++; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
67 } |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
68 else if (obj is GameSystem) |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
69 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
70 systemCount++; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
71 } |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
72 } |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
73 |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
74 Assert.That(raceCount, Is.EqualTo(1)); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
75 Assert.That(systemCount, Is.EqualTo(1)); |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
76 } |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
77 finally |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
78 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
79 loader.UnregisterFactory(factory); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
80 } |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
81 } |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
82 |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
83 [Test()] |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
84 public void TestFactoryHandlesMultipleFilesWithMultipleNewNamesInOneSystemZip() |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
85 { |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
86 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
87 WarFoundryLoader.SetDefault(loader); |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
88 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); |
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
89 loader.RegisterFactory(factory); |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
90 try |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
91 { |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
92 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system")); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
93 Assert.That(objs, Has.Count(4)); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
94 int raceCount = 0; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
95 int systemCount = 0; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
96 |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
97 foreach (IWarFoundryObject obj in objs) |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
98 { |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
99 if (obj is Race) |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
100 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
101 raceCount++; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
102 } |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
103 else if (obj is GameSystem) |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
104 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
105 systemCount++; |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
106 } |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
107 } |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
108 |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
109 Assert.That(raceCount, Is.EqualTo(2)); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
110 Assert.That(systemCount, Is.EqualTo(2)); |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
111 } |
96
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
112 finally |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
113 { |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
114 loader.UnregisterFactory(factory); |
3c2c108a2f08
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
90
diff
changeset
|
115 } |
90
5d19fee8e9dc
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
116 } |
87
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 } |
5c04db41d643
Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 } |