comparison 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
comparison
equal deleted inserted replaced
95:db6db25921fb 96:3c2c108a2f08
14 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip() 14 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip()
15 { 15 {
16 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); 16 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
17 WarFoundryLoader.SetDefault(loader); 17 WarFoundryLoader.SetDefault(loader);
18 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); 18 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
19 loader.RegisterFactory(factory); 19 try
20 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
21 Assert.That(objs, Has.Count(2));
22 int raceCount = 0;
23 int systemCount = 0;
24
25 foreach (IWarFoundryObject obj in objs)
26 { 20 {
27 if (obj is Race) 21 loader.RegisterFactory(factory);
22 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.system"));
23 Assert.That(objs, Has.Count(2));
24 int raceCount = 0;
25 int systemCount = 0;
26
27 foreach (IWarFoundryObject obj in objs)
28 { 28 {
29 raceCount++; 29 if (obj is Race)
30 {
31 raceCount++;
32 }
33 else if (obj is GameSystem)
34 {
35 systemCount++;
36 }
30 } 37 }
31 else if (obj is GameSystem) 38
32 { 39 Assert.That(raceCount, Is.EqualTo(1));
33 systemCount++; 40 Assert.That(systemCount, Is.EqualTo(1));
34 }
35 } 41 }
36 42 finally
37 Assert.That(raceCount, Is.EqualTo(1)); 43 {
38 Assert.That(systemCount, Is.EqualTo(1)); 44 loader.UnregisterFactory(factory);
45 }
39 } 46 }
40 47
41 [Test()] 48 [Test()]
42 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneRaceZip() 49 public void TestFactoryHandlesMultipleFilesWithOldNamesInOneRaceZip()
43 { 50 {
44 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); 51 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
45 WarFoundryLoader.SetDefault(loader); 52 WarFoundryLoader.SetDefault(loader);
46 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); 53 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
47 loader.RegisterFactory(factory); 54 loader.RegisterFactory(factory);
48 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race")); 55 try
49 Assert.That(objs, Has.Count(2));
50 int raceCount = 0;
51 int systemCount = 0;
52
53 foreach (IWarFoundryObject obj in objs)
54 { 56 {
55 if (obj is Race) 57 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Test.race"));
58 Assert.That(objs, Has.Count(2));
59 int raceCount = 0;
60 int systemCount = 0;
61
62 foreach (IWarFoundryObject obj in objs)
56 { 63 {
57 raceCount++; 64 if (obj is Race)
65 {
66 raceCount++;
67 }
68 else if (obj is GameSystem)
69 {
70 systemCount++;
71 }
58 } 72 }
59 else if (obj is GameSystem) 73
60 { 74 Assert.That(raceCount, Is.EqualTo(1));
61 systemCount++; 75 Assert.That(systemCount, Is.EqualTo(1));
62 }
63 } 76 }
64 77 finally
65 Assert.That(raceCount, Is.EqualTo(1)); 78 {
66 Assert.That(systemCount, Is.EqualTo(1)); 79 loader.UnregisterFactory(factory);
80 }
67 } 81 }
68 82
69 [Test()] 83 [Test()]
70 public void TestFactoryHandlesMultipleFilesWithMultipleNewNamesInOneSystemZip() 84 public void TestFactoryHandlesMultipleFilesWithMultipleNewNamesInOneSystemZip()
71 { 85 {
72 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); 86 EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
73 WarFoundryLoader.SetDefault(loader); 87 WarFoundryLoader.SetDefault(loader);
74 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); 88 WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
75 loader.RegisterFactory(factory); 89 loader.RegisterFactory(factory);
76 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system")); 90 try
77 Assert.That(objs, Has.Count(4));
78 int raceCount = 0;
79 int systemCount = 0;
80
81 foreach (IWarFoundryObject obj in objs)
82 { 91 {
83 if (obj is Race) 92 ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new FileInfo("testdata/multifile-zips/Multipack.system"));
93 Assert.That(objs, Has.Count(4));
94 int raceCount = 0;
95 int systemCount = 0;
96
97 foreach (IWarFoundryObject obj in objs)
84 { 98 {
85 raceCount++; 99 if (obj is Race)
100 {
101 raceCount++;
102 }
103 else if (obj is GameSystem)
104 {
105 systemCount++;
106 }
86 } 107 }
87 else if (obj is GameSystem) 108
88 { 109 Assert.That(raceCount, Is.EqualTo(2));
89 systemCount++; 110 Assert.That(systemCount, Is.EqualTo(2));
90 }
91 } 111 }
92 112 finally
93 Assert.That(raceCount, Is.EqualTo(2)); 113 {
94 Assert.That(systemCount, Is.EqualTo(2)); 114 loader.UnregisterFactory(factory);
115 }
95 } 116 }
96 } 117 }
97 } 118 }