comparison 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
comparison
equal deleted inserted replaced
94:10da200c7799 95:db6db25921fb
1 using System; 1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
2 using System.IO; 4 using System.IO;
3 using IBBoard.WarFoundry.API.Objects; 5 using IBBoard.WarFoundry.API.Objects;
4 using IBBoard.WarFoundry.API.Objects.Mock; 6 using IBBoard.WarFoundry.API.Objects.Mock;
7 using ICSharpCode.SharpZipLib.Zip;
5 using NUnit.Framework; 8 using NUnit.Framework;
6 using ICSharpCode.SharpZipLib.Zip;
7 using NUnit.Framework.SyntaxHelpers; 9 using NUnit.Framework.SyntaxHelpers;
8 10
9 namespace IBBoard.WarFoundry.API.Savers 11 namespace IBBoard.WarFoundry.API.Savers
10 { 12 {
11 public abstract class IWarFoundryFileSaverTests 13 public abstract class IWarFoundryFileSaverTests
26 { 28 {
27 File.Delete(tempFile); 29 File.Delete(tempFile);
28 } 30 }
29 } 31 }
30 } 32 }
31 33
32 [Test()] 34 [Test()]
33 public void TestSaverCreatesZipFile() 35 public void TestSaverCreatesZipFile()
34 { 36 {
35 string tempFile = Path.GetTempFileName(); 37 string tempFile = Path.GetTempFileName();
36 try 38 try
45 { 47 {
46 File.Delete(tempFile); 48 File.Delete(tempFile);
47 } 49 }
48 } 50 }
49 } 51 }
50 52
51 [Test()] 53 [Test()]
52 public void TestSaverCreatesSingleEntryForOneObject() 54 public void TestSaverCreatesSingleEntryForOneObject()
53 { 55 {
54 string tempFile = Path.GetTempFileName(); 56 string tempFile = Path.GetTempFileName();
55 try 57 try
65 { 67 {
66 File.Delete(tempFile); 68 File.Delete(tempFile);
67 } 69 }
68 } 70 }
69 } 71 }
70 72
73 [Test()]
74 public void TestSaverCreatesSingleEntryWithCorrectNameForOneObject()
75 {
76 string tempFile = Path.GetTempFileName();
77 try
78 {
79 MockGameSystem obj = new MockGameSystem();
80 GetSaver().Save(tempFile, obj);
81 ZipFile file = new ZipFile(tempFile);
82 IEnumerator enumerator = file.GetEnumerator();
83 enumerator.MoveNext();
84 ZipEntry current = (ZipEntry)enumerator.Current;
85 Assert.That(current.Name, Is.EqualTo(GetEntryName(obj)));
86 Assert.That(current.Name, Text.EndsWith(GetFileExtensionForType(obj)));
87 file.Close();
88 }
89 finally
90 {
91 if (File.Exists(tempFile))
92 {
93 File.Delete(tempFile);
94 }
95 }
96 }
71 97
72 protected abstract IWarFoundryFileSaver GetSaver(); 98 protected abstract IWarFoundryFileSaver GetSaver();
99
100 protected abstract string GetEntryName(WarFoundryLoadedObject obj);
101
102 protected abstract string GetFileExtensionForType(WarFoundryLoadedObject obj);
73 } 103 }
74 } 104 }