Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison 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 |
comparison
equal
deleted
inserted
replaced
171:14d0450f295d | 172:c026c02583ca |
---|---|
126 public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy() | 126 public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy() |
127 { | 127 { |
128 string tempFile = Path.GetTempFileName(); | 128 string tempFile = Path.GetTempFileName(); |
129 try | 129 try |
130 { | 130 { |
131 MockArmy obj = MockArmy.GetMockArmy(); | 131 MockArmy obj = new MockArmy(); |
132 GetSaver().Save(tempFile, obj); | 132 GetSaver().Save(tempFile, obj); |
133 ZipFile file = new ZipFile(tempFile); | 133 ZipFile file = new ZipFile(tempFile); |
134 ZipEntry zipEntry = file.GetEntry(GetEntryName(obj)); | 134 ZipEntry zipEntry = file.GetEntry(GetEntryName(obj)); |
135 Stream stream = file.GetInputStream(zipEntry); | 135 Stream stream = file.GetInputStream(zipEntry); |
136 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); | 136 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); |
137 stream.Close(); | |
137 file.Close(); | 138 file.Close(); |
138 } | 139 } |
139 finally | 140 finally |
140 { | 141 { |
141 if (File.Exists(tempFile)) | 142 if (File.Exists(tempFile)) |
149 public void TestSaverCreatesTwoEntriesForOneSystemOneArmy() | 150 public void TestSaverCreatesTwoEntriesForOneSystemOneArmy() |
150 { | 151 { |
151 string tempFile = Path.GetTempFileName(); | 152 string tempFile = Path.GetTempFileName(); |
152 try | 153 try |
153 { | 154 { |
154 GetSaver().Save(tempFile, new MockGameSystem(), MockArmy.GetMockArmy()); | 155 GetSaver().Save(tempFile, new MockGameSystem(), new MockArmy()); |
155 ZipFile file = new ZipFile(tempFile); | 156 ZipFile file = new ZipFile(tempFile); |
156 Assert.That(file.Count, Is.EqualTo(2)); | 157 Assert.That(file.Count, Is.EqualTo(2)); |
157 file.Close(); | 158 file.Close(); |
158 } | 159 } |
159 finally | 160 finally |
171 //This doesn't make much sense (system and army in one file) but at the time of writing then Race saving isn't implemented | 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 |
172 string tempFile = Path.GetTempFileName(); | 173 string tempFile = Path.GetTempFileName(); |
173 try | 174 try |
174 { | 175 { |
175 MockGameSystem system = new MockGameSystem(); | 176 MockGameSystem system = new MockGameSystem(); |
176 MockArmy army = MockArmy.GetMockArmy(); | 177 MockArmy army = new MockArmy(); |
177 GetSaver().Save(tempFile, system, army); | 178 GetSaver().Save(tempFile, system, army); |
178 ZipFile file = new ZipFile(tempFile); | 179 ZipFile file = new ZipFile(tempFile); |
179 ZipEntry zipEntry = file.GetEntry(GetEntryName(system)); | 180 ZipEntry zipEntry = file.GetEntry(GetEntryName(system)); |
180 Stream stream = file.GetInputStream(zipEntry); | 181 Stream stream = file.GetInputStream(zipEntry); |
181 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes())); | 182 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes())); |
182 zipEntry = file.GetEntry(GetEntryName(army)); | 183 zipEntry = file.GetEntry(GetEntryName(army)); |
183 stream = file.GetInputStream(zipEntry); | 184 stream = file.GetInputStream(zipEntry); |
184 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); | 185 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); |
186 stream.Close(); | |
185 file.Close(); | 187 file.Close(); |
186 } | 188 } |
187 finally | 189 finally |
188 { | 190 { |
189 if (File.Exists(tempFile)) | 191 if (File.Exists(tempFile)) |
241 } | 243 } |
242 | 244 |
243 [Test()] | 245 [Test()] |
244 public void TestFileExtensionsAreCorrectForType() | 246 public void TestFileExtensionsAreCorrectForType() |
245 { | 247 { |
246 Assert.That(GetSaver().GetFileExtension(MockArmy.GetMockArmy()), Is.EqualTo(GetArmyExtension())); | 248 Assert.That(GetSaver().GetFileExtension(new MockArmy()), Is.EqualTo(GetArmyExtension())); |
247 Assert.That(GetSaver().GetFileExtension(new MockRace()), Is.EqualTo(GetRaceExtension())); | 249 Assert.That(GetSaver().GetFileExtension(new MockRace()), Is.EqualTo(GetRaceExtension())); |
248 Assert.That(GetSaver().GetFileExtension(new MockGameSystem()), Is.EqualTo(GetGameSystemExtension())); | 250 Assert.That(GetSaver().GetFileExtension(new MockGameSystem()), Is.EqualTo(GetGameSystemExtension())); |
249 } | 251 } |
250 | 252 |
251 protected abstract IWarFoundryFileSaver GetSaver(); | 253 protected abstract IWarFoundryFileSaver GetSaver(); |