Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 178:50b8466783ed
Re #338: WarFoundry.API - Save System Data
* Add test for saving categories
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 28 Oct 2011 20:52:01 +0100 |
parents | 01f7a713fe82 |
children | 32b3e41bc8f0 |
files | API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs |
diffstat | 2 files changed, 40 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Savers/IWarFoundryFileSaverTests.cs Wed Oct 26 15:46:48 2011 +0100 +++ b/API/Savers/IWarFoundryFileSaverTests.cs Fri Oct 28 20:52:01 2011 +0100 @@ -367,6 +367,38 @@ } } + [Test()] + public void TestGameSystemWithCategories() + { + + string tempFile = Path.GetTempFileName(); + try + { + MockGameSystem obj = new MockGameSystem(); + Category heroCat = new Category("cat1", "Heroes"); + heroCat.MaximumPercentage = 25; + heroCat.MaximumPoints = 1000; + obj.AddCategory(heroCat); + Category warriorCat = new Category("cat2", "Warriors"); + warriorCat.MinimumPercentage = 35; + warriorCat.MinimumPoints = 500; + obj.AddCategory(warriorCat); + 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(GetGameSystemContentWithCategories())); + file.Close(); + } + finally + { + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + } + } + protected abstract IWarFoundryFileSaver GetSaver(); protected abstract string GetEntryName(WarFoundryLoadedObject obj); @@ -390,5 +422,7 @@ protected abstract byte[] GetGameSystemContentWithPointsNameBytes(string singular, string plural); protected abstract byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName); + + protected abstract byte[] GetGameSystemContentWithCategories(); } }
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Wed Oct 26 15:46:48 2011 +0100 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Fri Oct 28 20:52:01 2011 +0100 @@ -66,7 +66,12 @@ protected override byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName) { - 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=""mocksystem"" name=""Mock Game System"" defaultArmySize=""1000"" warn=""true"" allowAllies=""false"" defaultPtsAbbreviationSingular=""" + singular + @""" defaultPtsAbbreviationPlural=""" + plural + @""" defaultPtsNameSingular=""" + singularName + @""" defaultPtsNamePlural=""" + pluralName + @"""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></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=""mocksystem"" name=""Mock Game System"" defaultArmySize=""1000"" warn=""true"" allowAllies=""false"" defaultPtsAbbreviationSingular=""" + singular + @""" defaultPtsAbbreviationPlural=""" + plural + @""" defaultPtsNameSingular=""" + singularName + @""" defaultPtsNamePlural=""" + pluralName + @"""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>"); + } + + protected override byte[] GetGameSystemContentWithCategories () + { + 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=""mocksystem"" name=""Mock Game System"" defaultArmySize=""1000"" warn=""true"" allowAllies=""false"" defaultPtsAbbreviationSingular="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories><cat id=""cat1"" name=""Heroes"" maxPoints=""1000"" maxPercentage=""25"" /><cat id=""cat2"" name=""Warriors"" minPoints=""500"" minPercentage=""35"" /></categories><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>"); } } }