Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 177:01f7a713fe82
Re #338: WarFoundry.API - Save System Data
* Extract "CreateOtherSystem" method for consistency
* Make "other system" excercise some of the other attributes that can be changed
TODO: Still need to work on content (categories, etc)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 26 Oct 2011 15:46:48 +0100 |
parents | 9a1763af5fd2 |
children | 50b8466783ed |
files | API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs |
diffstat | 2 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Savers/IWarFoundryFileSaverTests.cs Wed Oct 26 15:40:52 2011 +0100 +++ b/API/Savers/IWarFoundryFileSaverTests.cs Wed Oct 26 15:46:48 2011 +0100 @@ -123,6 +123,38 @@ } [Test()] + public void TestSaverCreatesSingleEntryWithCorrectContentForOtherSystem() + { + string tempFile = Path.GetTempFileName(); + try + { + GameSystem obj = CreateOtherSystem(); + GetSaver().Save(tempFile, obj); + ZipFile file = new ZipFile(tempFile); + ZipEntry zipEntry = file.GetEntry(GetEntryName(obj)); + Stream stream = file.GetInputStream(zipEntry); + Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetOtherGameSystemContentBytes())); + file.Close(); + } + finally + { + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + } + } + + private GameSystem CreateOtherSystem() + { + GameSystem system = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()); + system.AllowAllies = true; + system.WarnOnError = false; + system.SystemArmyDefaultSize = 2000; + return system; + } + + [Test()] public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy() { string tempFile = Path.GetTempFileName(); @@ -201,7 +233,7 @@ string tempFile = Path.GetTempFileName(); try { - GetSaver().Save(tempFile, new MockGameSystem(), new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory())); + GetSaver().Save(tempFile, new MockGameSystem(), CreateOtherSystem()); ZipFile file = new ZipFile(tempFile); Assert.That(file.Count, Is.EqualTo(2)); file.Close(); @@ -222,7 +254,7 @@ try { MockGameSystem system1 = new MockGameSystem(); - GameSystem system2 = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()); + GameSystem system2 = CreateOtherSystem(); GetSaver().Save(tempFile, system1, system2); ZipFile file = new ZipFile(tempFile); ZipEntry zipEntry = file.GetEntry(GetEntryName(system1));
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Wed Oct 26 15:40:52 2011 +0100 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Wed Oct 26 15:46:48 2011 +0100 @@ -46,7 +46,7 @@ protected override byte[] GetOtherGameSystemContentBytes() { - return StringManipulation.StringToBytes(@"<?xml version=""1.0"" encoding=""UTF-8""?><system xmlns=""http://ibboard.co.uk/warfoundry/system"" xmlns:cats=""http://ibboard.co.uk/warfoundry/cats"" id=""otherSystem"" name=""Other System"" defaultArmySize=""1000"" warn=""true"" allowAllies=""false"" defaultPtsAbbreviationSingular="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""_"" /></system>"); + return StringManipulation.StringToBytes(@"<?xml version=""1.0"" encoding=""UTF-8""?><system xmlns=""http://ibboard.co.uk/warfoundry/system"" xmlns:cats=""http://ibboard.co.uk/warfoundry/cats"" id=""otherSystem"" name=""Other System"" defaultArmySize=""2000"" warn=""false"" allowAllies=""true"" defaultPtsAbbreviationSingular="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""_"" /></system>"); } protected override byte[] GetArmyContentBytes()