annotate API/Savers/IWarFoundryFileSaverTests.cs @ 163:b0b41bf8ad68 Ticket341-DefaultArmySize

Re #101: Make army names and sizes modifiable after creation * Add unit tests for new command
author IBBoard <dev@ibboard.co.uk>
date Mon, 29 Aug 2011 16:48:29 +0100
parents 08fd75eafb67
children c026c02583ca
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 {
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
131 MockArmy obj = MockArmy.GetMockArmy();
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);
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
136 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes()));
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
137 file.Close();
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
138 }
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
139 finally
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
140 {
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
141 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
142 {
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
143 File.Delete(tempFile);
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
144 }
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 }
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
147
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
148 [Test()]
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
149 public void TestSaverCreatesTwoEntriesForOneSystemOneArmy()
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
150 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
151 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
152 try
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
153 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
154 GetSaver().Save(tempFile, new MockGameSystem(), MockArmy.GetMockArmy());
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
155 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
156 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
157 file.Close();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
158 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
159 finally
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
160 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
161 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
162 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
163 File.Delete(tempFile);
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
164 }
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 [Test()]
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
169 public void TestSaverCreatesTwoEntriesWithCorrectContentForOneSystemOneArmy()
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
170 {
101
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
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
100
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
172 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
173 try
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
174 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
175 MockGameSystem system = new MockGameSystem();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
176 MockArmy army = MockArmy.GetMockArmy();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes()));
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
185 file.Close();
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
186 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
187 finally
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 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
190 {
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
191 File.Delete(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 }
5addcb8f7766 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
194 }
101
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
195
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
196 [Test()]
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
197 public void TestSaverCreatesTwoEntriesForTwoSystems()
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
198 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
199 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
200 try
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
201 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
202 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
203 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
204 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
205 file.Close();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
206 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
207 finally
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 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
210 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
211 File.Delete(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 }
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 [Test()]
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
217 public void TestSaverCreatesTwoEntriesWithCorrectContentForTwoSystems()
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
218 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
219 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
220 try
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
221 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 file.Close();
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
233 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
234 finally
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 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
237 {
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
238 File.Delete(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 }
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
241 }
97
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
242
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
243 [Test()]
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
244 public void TestFileExtensionsAreCorrectForType()
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
245 {
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
246 Assert.That(GetSaver().GetFileExtension(MockArmy.GetMockArmy()), Is.EqualTo(GetArmyExtension()));
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
247 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
248 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
249 }
91
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 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
252
db6db25921fb Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 94
diff changeset
253 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
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 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
256
45b80fed5e2a Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
257 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
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 GetRaceExtension();
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 GetGameSystemExtension();
98
49c5e24decb9 Re #338: WarFoundry.API - Save System Data
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
262
99
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
263 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
264
08fd75eafb67 Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 100
diff changeset
265 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
266
dd384f35a96f Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
267 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
268 }
98539b2fe8fa Re #324: Add saving of Race and System data to files
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269 }