annotate API/Savers/IWarFoundryFileSaverTests.cs @ 172:c026c02583ca

* Remove MockArmy.GetMockArmy as it only causes problems in unit tests * Remove MockArmyCategory as MockArmy change would make it do nothing special * Close streams as well as files to fix Windows unit test errors
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Sep 2011 11:46:20 +0100
parents 08fd75eafb67
children 9a1763af5fd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 using System;
95
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
2 using System.Collections;
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
3 using System.Collections.Generic;
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System.IO;
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using IBBoard.WarFoundry.API.Objects;
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Objects.Mock;
95
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
7 using ICSharpCode.SharpZipLib.Zip;
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using NUnit.Framework;
94
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
9 using NUnit.Framework.SyntaxHelpers;
98
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
10 using ICSharpCode.SharpZipLib.Core;
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
11 using IBBoard.IO;
101
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
12 using IBBoard.WarFoundry.API.Factories;
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 namespace IBBoard.WarFoundry.API.Savers
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public abstract class IWarFoundryFileSaverTests
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 [Test()]
92
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
19 public void TestSaverCreatesFile()
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 string tempFile = Path.GetTempFileName();
98
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
22
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 try
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 {
92
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
25 bool saved = GetSaver().Save(tempFile, new MockGameSystem());
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
26 Assert.That(saved);
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 Assert.That(File.Exists(tempFile));
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 }
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 finally
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 if (File.Exists(tempFile))
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 {
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 File.Delete(tempFile);
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 }
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 }
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
95
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
37
92
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
38 [Test()]
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
39 public void TestSaverCreatesZipFile()
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
40 {
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
41 string tempFile = Path.GetTempFileName();
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
42 try
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
43 {
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
44 GetSaver().Save(tempFile, new MockGameSystem());
93
72b2f9a5fe8f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 92
diff changeset
45 ZipFile file = new ZipFile(tempFile);
72b2f9a5fe8f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 92
diff changeset
46 file.Close();
92
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
47 }
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
48 finally
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
49 {
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
50 if (File.Exists(tempFile))
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
51 {
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
52 File.Delete(tempFile);
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
53 }
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
54 }
43c44d0bf97f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
55 }
95
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
56
94
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
57 [Test()]
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
58 public void TestSaverCreatesSingleEntryForOneObject()
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
59 {
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
60 string tempFile = Path.GetTempFileName();
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
61 try
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
62 {
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
63 GetSaver().Save(tempFile, new MockGameSystem());
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
64 ZipFile file = new ZipFile(tempFile);
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
65 Assert.That(file.Count, Is.EqualTo(1));
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
66 file.Close();
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
67 }
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
68 finally
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
69 {
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
70 if (File.Exists(tempFile))
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
71 {
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
72 File.Delete(tempFile);
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
73 }
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
74 }
10da200c7799 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
75 }
95
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
76
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
77 [Test()]
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
78 public void TestSaverCreatesSingleEntryWithCorrectNameForOneObject()
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
79 {
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
80 string tempFile = Path.GetTempFileName();
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
81 try
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
82 {
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
83 MockGameSystem obj = new MockGameSystem();
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
84 GetSaver().Save(tempFile, obj);
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
85 ZipFile file = new ZipFile(tempFile);
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
86 IEnumerator enumerator = file.GetEnumerator();
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
87 enumerator.MoveNext();
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
88 ZipEntry current = (ZipEntry)enumerator.Current;
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
89 Assert.That(current.Name, Is.EqualTo(GetEntryName(obj)));
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
90 Assert.That(current.Name, Text.EndsWith(GetFileExtensionForType(obj)));
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
91 file.Close();
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
92 }
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
93 finally
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
94 {
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
95 if (File.Exists(tempFile))
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
96 {
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
97 File.Delete(tempFile);
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
98 }
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
99 }
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
100 }
98
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
101
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
102 [Test()]
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
103 public void TestSaverCreatesSingleEntryWithCorrectContentForOneSystem()
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
104 {
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
105 string tempFile = Path.GetTempFileName();
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
106 try
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
107 {
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
108 MockGameSystem obj = new MockGameSystem();
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
109 GetSaver().Save(tempFile, obj);
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
110 ZipFile file = new ZipFile(tempFile);
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
111 ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
112 Stream stream = file.GetInputStream(zipEntry);
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
113 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes()));
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
114 file.Close();
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
115 }
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
116 finally
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
117 {
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
118 if (File.Exists(tempFile))
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
119 {
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
120 File.Delete(tempFile);
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
121 }
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
122 }
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
123 }
99
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
124
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
125 [Test()]
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
126 public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy()
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
127 {
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
128 string tempFile = Path.GetTempFileName();
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
129 try
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
130 {
172
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
131 MockArmy obj = new MockArmy();
99
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
132 GetSaver().Save(tempFile, obj);
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
133 ZipFile file = new ZipFile(tempFile);
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
134 ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
135 Stream stream = file.GetInputStream(zipEntry);
172
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
136 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes()));
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
137 stream.Close();
99
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
138 file.Close();
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
139 }
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
140 finally
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
141 {
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
142 if (File.Exists(tempFile))
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
143 {
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
144 File.Delete(tempFile);
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
145 }
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
146 }
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
147 }
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
148
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
149 [Test()]
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
150 public void TestSaverCreatesTwoEntriesForOneSystemOneArmy()
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
151 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
152 string tempFile = Path.GetTempFileName();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
153 try
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
154 {
172
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
155 GetSaver().Save(tempFile, new MockGameSystem(), new MockArmy());
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
156 ZipFile file = new ZipFile(tempFile);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
157 Assert.That(file.Count, Is.EqualTo(2));
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
158 file.Close();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
159 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
160 finally
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
161 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
162 if (File.Exists(tempFile))
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
163 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
164 File.Delete(tempFile);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
165 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
166 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
167 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
168
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
169 [Test()]
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
170 public void TestSaverCreatesTwoEntriesWithCorrectContentForOneSystemOneArmy()
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
171 {
101
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
172 //This doesn't make much sense (system and army in one file) but at the time of writing then Race saving isn't implemented
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
173 string tempFile = Path.GetTempFileName();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
174 try
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
175 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
176 MockGameSystem system = new MockGameSystem();
172
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
177 MockArmy army = new MockArmy();
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
178 GetSaver().Save(tempFile, system, army);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
179 ZipFile file = new ZipFile(tempFile);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
180 ZipEntry zipEntry = file.GetEntry(GetEntryName(system));
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
181 Stream stream = file.GetInputStream(zipEntry);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
182 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes()));
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
183 zipEntry = file.GetEntry(GetEntryName(army));
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
184 stream = file.GetInputStream(zipEntry);
172
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
185 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes()));
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
186 stream.Close();
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
187 file.Close();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
188 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
189 finally
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
190 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
191 if (File.Exists(tempFile))
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
192 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
193 File.Delete(tempFile);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
194 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
195 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
196 }
101
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
197
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
198 [Test()]
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
199 public void TestSaverCreatesTwoEntriesForTwoSystems()
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
200 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
201 string tempFile = Path.GetTempFileName();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
202 try
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
203 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
204 GetSaver().Save(tempFile, new MockGameSystem(), new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()));
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
205 ZipFile file = new ZipFile(tempFile);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
206 Assert.That(file.Count, Is.EqualTo(2));
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
207 file.Close();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
208 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
209 finally
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
210 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
211 if (File.Exists(tempFile))
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
212 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
213 File.Delete(tempFile);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
214 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
215 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
216 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
217
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
218 [Test()]
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
219 public void TestSaverCreatesTwoEntriesWithCorrectContentForTwoSystems()
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
220 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
221 string tempFile = Path.GetTempFileName();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
222 try
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
223 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
224 MockGameSystem system1 = new MockGameSystem();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
225 GameSystem system2 = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory());
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
226 GetSaver().Save(tempFile, system1, system2);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
227 ZipFile file = new ZipFile(tempFile);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
228 ZipEntry zipEntry = file.GetEntry(GetEntryName(system1));
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
229 Stream stream = file.GetInputStream(zipEntry);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
230 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes()));
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
231 zipEntry = file.GetEntry(GetEntryName(system2));
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
232 stream = file.GetInputStream(zipEntry);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
233 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetOtherGameSystemContentBytes()));
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
234 file.Close();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
235 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
236 finally
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
237 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
238 if (File.Exists(tempFile))
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
239 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
240 File.Delete(tempFile);
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
241 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
242 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
243 }
97
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
244
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
245 [Test()]
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
246 public void TestFileExtensionsAreCorrectForType()
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
247 {
172
c026c02583ca * Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
248 Assert.That(GetSaver().GetFileExtension(new MockArmy()), Is.EqualTo(GetArmyExtension()));
97
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
249 Assert.That(GetSaver().GetFileExtension(new MockRace()), Is.EqualTo(GetRaceExtension()));
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
250 Assert.That(GetSaver().GetFileExtension(new MockGameSystem()), Is.EqualTo(GetGameSystemExtension()));
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
251 }
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 protected abstract IWarFoundryFileSaver GetSaver();
95
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
254
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
255 protected abstract string GetEntryName(WarFoundryLoadedObject obj);
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
256
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
257 protected abstract string GetFileExtensionForType(WarFoundryLoadedObject obj);
97
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
258
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
259 protected abstract string GetArmyExtension();
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
260
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
261 protected abstract string GetRaceExtension();
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
262
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
263 protected abstract string GetGameSystemExtension();
98
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
264
99
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
265 protected abstract byte[] GetGameSystemContentBytes();
101
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
266
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
267 protected abstract byte[] GetOtherGameSystemContentBytes();
99
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
268
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
269 protected abstract byte[] GetArmyContentBytes();
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 }
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
271 }