Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 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 | 3c2c108a2f08 |
files | API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs |
diffstat | 2 files changed, 45 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Savers/IWarFoundryFileSaverTests.cs Sat Mar 05 15:24:11 2011 +0000 +++ b/API/Savers/IWarFoundryFileSaverTests.cs Sat Mar 05 15:53:29 2011 +0000 @@ -1,9 +1,11 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.IO; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Objects.Mock; +using ICSharpCode.SharpZipLib.Zip; using NUnit.Framework; -using ICSharpCode.SharpZipLib.Zip; using NUnit.Framework.SyntaxHelpers; namespace IBBoard.WarFoundry.API.Savers @@ -28,7 +30,7 @@ } } } - + [Test()] public void TestSaverCreatesZipFile() { @@ -47,7 +49,7 @@ } } } - + [Test()] public void TestSaverCreatesSingleEntryForOneObject() { @@ -67,8 +69,36 @@ } } } - + + [Test()] + public void TestSaverCreatesSingleEntryWithCorrectNameForOneObject() + { + string tempFile = Path.GetTempFileName(); + try + { + MockGameSystem obj = new MockGameSystem(); + GetSaver().Save(tempFile, obj); + ZipFile file = new ZipFile(tempFile); + IEnumerator enumerator = file.GetEnumerator(); + enumerator.MoveNext(); + ZipEntry current = (ZipEntry)enumerator.Current; + Assert.That(current.Name, Is.EqualTo(GetEntryName(obj))); + Assert.That(current.Name, Text.EndsWith(GetFileExtensionForType(obj))); + file.Close(); + } + finally + { + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + } + } protected abstract IWarFoundryFileSaver GetSaver(); + + protected abstract string GetEntryName(WarFoundryLoadedObject obj); + + protected abstract string GetFileExtensionForType(WarFoundryLoadedObject obj); } }
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Sat Mar 05 15:24:11 2011 +0000 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Sat Mar 05 15:53:29 2011 +0000 @@ -1,6 +1,7 @@ using System; using NUnit.Framework; using System.IO; +using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Savers.Xml { @@ -11,5 +12,15 @@ { return new WarFoundryXmlFileSaver(); } + + protected override string GetEntryName (WarFoundryLoadedObject obj) + { + return obj.ID; + } + + protected override string GetFileExtensionForType (WarFoundryLoadedObject obj) + { + return GetSaver().GetFileExtension(obj); + } } }