Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Savers/IWarFoundryFileSaverTests.cs @ 177:01f7a713fe82
Re #338: WarFoundry.API - Save System Data
* Extract "CreateOtherSystem" method for consistency
* Make "other system" excercise some of the other attributes that can be changed
TODO: Still need to work on content (categories, etc)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 26 Oct 2011 15:46:48 +0100 |
parents | 9a1763af5fd2 |
children | 50b8466783ed |
comparison
equal
deleted
inserted
replaced
176:9a1763af5fd2 | 177:01f7a713fe82 |
---|---|
121 } | 121 } |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 [Test()] | 125 [Test()] |
126 public void TestSaverCreatesSingleEntryWithCorrectContentForOtherSystem() | |
127 { | |
128 string tempFile = Path.GetTempFileName(); | |
129 try | |
130 { | |
131 GameSystem obj = CreateOtherSystem(); | |
132 GetSaver().Save(tempFile, obj); | |
133 ZipFile file = new ZipFile(tempFile); | |
134 ZipEntry zipEntry = file.GetEntry(GetEntryName(obj)); | |
135 Stream stream = file.GetInputStream(zipEntry); | |
136 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetOtherGameSystemContentBytes())); | |
137 file.Close(); | |
138 } | |
139 finally | |
140 { | |
141 if (File.Exists(tempFile)) | |
142 { | |
143 File.Delete(tempFile); | |
144 } | |
145 } | |
146 } | |
147 | |
148 private GameSystem CreateOtherSystem() | |
149 { | |
150 GameSystem system = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()); | |
151 system.AllowAllies = true; | |
152 system.WarnOnError = false; | |
153 system.SystemArmyDefaultSize = 2000; | |
154 return system; | |
155 } | |
156 | |
157 [Test()] | |
126 public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy() | 158 public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy() |
127 { | 159 { |
128 string tempFile = Path.GetTempFileName(); | 160 string tempFile = Path.GetTempFileName(); |
129 try | 161 try |
130 { | 162 { |
199 public void TestSaverCreatesTwoEntriesForTwoSystems() | 231 public void TestSaverCreatesTwoEntriesForTwoSystems() |
200 { | 232 { |
201 string tempFile = Path.GetTempFileName(); | 233 string tempFile = Path.GetTempFileName(); |
202 try | 234 try |
203 { | 235 { |
204 GetSaver().Save(tempFile, new MockGameSystem(), new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory())); | 236 GetSaver().Save(tempFile, new MockGameSystem(), CreateOtherSystem()); |
205 ZipFile file = new ZipFile(tempFile); | 237 ZipFile file = new ZipFile(tempFile); |
206 Assert.That(file.Count, Is.EqualTo(2)); | 238 Assert.That(file.Count, Is.EqualTo(2)); |
207 file.Close(); | 239 file.Close(); |
208 } | 240 } |
209 finally | 241 finally |
220 { | 252 { |
221 string tempFile = Path.GetTempFileName(); | 253 string tempFile = Path.GetTempFileName(); |
222 try | 254 try |
223 { | 255 { |
224 MockGameSystem system1 = new MockGameSystem(); | 256 MockGameSystem system1 = new MockGameSystem(); |
225 GameSystem system2 = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()); | 257 GameSystem system2 = CreateOtherSystem(); |
226 GetSaver().Save(tempFile, system1, system2); | 258 GetSaver().Save(tempFile, system1, system2); |
227 ZipFile file = new ZipFile(tempFile); | 259 ZipFile file = new ZipFile(tempFile); |
228 ZipEntry zipEntry = file.GetEntry(GetEntryName(system1)); | 260 ZipEntry zipEntry = file.GetEntry(GetEntryName(system1)); |
229 Stream stream = file.GetInputStream(zipEntry); | 261 Stream stream = file.GetInputStream(zipEntry); |
230 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes())); | 262 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes())); |