Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 176:9a1763af5fd2
Re #338: WarFoundry.API - Save System Data
* Add tests for saving point names
* Add expected values for new tests
* Add points names to existing expected values (because we don't know if they were default or not)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 26 Oct 2011 15:40:52 +0100 |
parents | 0f144576e5eb |
children | 01f7a713fe82 |
files | API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs |
diffstat | 2 files changed, 109 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Savers/IWarFoundryFileSaverTests.cs Sun Sep 25 20:53:47 2011 +0100 +++ b/API/Savers/IWarFoundryFileSaverTests.cs Wed Oct 26 15:40:52 2011 +0100 @@ -250,6 +250,91 @@ Assert.That(GetSaver().GetFileExtension(new MockGameSystem()), Is.EqualTo(GetGameSystemExtension())); } + [Test()] + public void TestPointsValueAbbreviationsSaved() + { + string tempFile = Path.GetTempFileName(); + try + { + MockGameSystem obj = new MockGameSystem(); + string plural = "ptii"; + string singular = "ptus"; + obj.SystemPtsAbbrevPlural = plural; + obj.SystemPtsAbbrevSingle = singular; + 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(GetGameSystemContentWithPointsAbbrevsBytes(singular, plural))); + file.Close(); + } + finally + { + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + } + } + + [Test()] + public void TestPointsValueNamesSaved() + { + string tempFile = Path.GetTempFileName(); + try + { + MockGameSystem obj = new MockGameSystem(); + string plural = "pointii"; + string singular = "pointus"; + obj.SystemPtsNamePlural = plural; + obj.SystemPtsNameSingle = singular; + 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(GetGameSystemContentWithPointsNameBytes(singular, plural))); + file.Close(); + } + finally + { + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + } + } + + [Test()] + public void TestPointsValueAbbreviationsAndNamesSaved() + { + string tempFile = Path.GetTempFileName(); + try + { + MockGameSystem obj = new MockGameSystem(); + string plural = "ptii"; + string singular = "ptus"; + string pluralName = "pointii"; + string singularName = "pointus"; + obj.SystemPtsAbbrevPlural = plural; + obj.SystemPtsAbbrevSingle = singular; + obj.SystemPtsNamePlural = pluralName; + obj.SystemPtsNameSingle = singularName; + 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(GetGameSystemContentWithPointsAbbrevsAndNameBytes(singular, plural, singularName, pluralName))); + file.Close(); + } + finally + { + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + } + } + protected abstract IWarFoundryFileSaver GetSaver(); protected abstract string GetEntryName(WarFoundryLoadedObject obj); @@ -267,5 +352,11 @@ protected abstract byte[] GetOtherGameSystemContentBytes(); protected abstract byte[] GetArmyContentBytes(); + + protected abstract byte[] GetGameSystemContentWithPointsAbbrevsBytes(string singular, string plural); + + protected abstract byte[] GetGameSystemContentWithPointsNameBytes(string singular, string plural); + + protected abstract byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName); } }
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Sun Sep 25 20:53:47 2011 +0100 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs Wed Oct 26 15:40:52 2011 +0100 @@ -41,17 +41,32 @@ protected override byte[] GetGameSystemContentBytes() { - 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""><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="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>"); } 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""><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=""1000"" warn=""true"" allowAllies=""false"" defaultPtsAbbreviationSingular="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""_"" /></system>"); } - protected override byte[] GetArmyContentBytes () + protected override byte[] GetArmyContentBytes() { return StringManipulation.StringToBytes(@"<?xml version=""1.0"" encoding=""UTF-8""?><army xmlns=""http://ibboard.co.uk/warfoundry/army"" xmlns:core=""http://ibboard.co.uk/warfoundry/core"" id=""MockArmy"" name=""Mock Army"" system=""mocksystem"" race=""mockrace"" maxPoints=""2000""><units /></army>"); } + + protected override byte[] GetGameSystemContentWithPointsAbbrevsBytes(string singular, string plural) + { + 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="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>"); + } + + protected override byte[] GetGameSystemContentWithPointsNameBytes(string singular, string plural) + { + 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=""" + singular + @""" defaultPtsNamePlural=""" + plural + @"""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>"); + } + + 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>"); + } } }