Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
annotate API/Savers/IWarFoundryFileSaverTests.cs @ 95:db6db25921fb
Re #324: Add saving of Race and System data to files
* Add tests for the zip entry name
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 05 Mar 2011 15:53:29 +0000 |
parents | 10da200c7799 |
children | 45b80fed5e2a |
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; |
91
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 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
|
12 { |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 public abstract class IWarFoundryFileSaverTests |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 { |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 [Test()] |
92
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
16 public void TestSaverCreatesFile() |
91
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 string tempFile = Path.GetTempFileName(); |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 try |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 { |
92
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
21 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
|
22 Assert.That(saved); |
91
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 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
|
24 } |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 finally |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 if (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 File.Delete(tempFile); |
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 } |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 } |
95
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
33 |
92
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
34 [Test()] |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
35 public void TestSaverCreatesZipFile() |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
36 { |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
37 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
|
38 try |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
39 { |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
40 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
|
41 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
|
42 file.Close(); |
92
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 finally |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
45 { |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
46 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
|
47 { |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
48 File.Delete(tempFile); |
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 } |
43c44d0bf97f
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
91
diff
changeset
|
51 } |
95
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
52 |
94
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
53 [Test()] |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
54 public void TestSaverCreatesSingleEntryForOneObject() |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
55 { |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
56 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
|
57 try |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
58 { |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 file.Close(); |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
63 } |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
64 finally |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
65 { |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
66 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
|
67 { |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
68 File.Delete(tempFile); |
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 } |
10da200c7799
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
71 } |
95
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
72 |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
73 [Test()] |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
74 public void TestSaverCreatesSingleEntryWithCorrectNameForOneObject() |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
75 { |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
76 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
|
77 try |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
78 { |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
79 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
|
80 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
|
81 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
|
82 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
|
83 enumerator.MoveNext(); |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 file.Close(); |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
88 } |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
89 finally |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
90 { |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
91 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
|
92 { |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
93 File.Delete(tempFile); |
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 } |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
96 } |
91
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
97 |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 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
|
99 |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
100 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
|
101 |
db6db25921fb
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
94
diff
changeset
|
102 protected abstract string GetFileExtensionForType(WarFoundryLoadedObject obj); |
91
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
103 } |
98539b2fe8fa
Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 } |