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 diff
     1.1 --- a/API/Savers/IWarFoundryFileSaverTests.cs	Wed Oct 26 15:46:48 2011 +0100
     1.2 +++ b/API/Savers/IWarFoundryFileSaverTests.cs	Fri Oct 28 20:52:01 2011 +0100
     1.3 @@ -367,6 +367,38 @@
     1.4  			}
     1.5  		}
     1.6  
     1.7 +		[Test()]
     1.8 +		public void TestGameSystemWithCategories()
     1.9 +		{
    1.10 +
    1.11 +			string tempFile = Path.GetTempFileName();
    1.12 +			try
    1.13 +			{
    1.14 +				MockGameSystem obj = new MockGameSystem();
    1.15 +				Category heroCat = new Category("cat1", "Heroes");
    1.16 +				heroCat.MaximumPercentage = 25;
    1.17 +				heroCat.MaximumPoints = 1000;
    1.18 +				obj.AddCategory(heroCat);
    1.19 +				Category warriorCat = new Category("cat2", "Warriors");
    1.20 +				warriorCat.MinimumPercentage = 35;
    1.21 +				warriorCat.MinimumPoints = 500;
    1.22 +				obj.AddCategory(warriorCat);
    1.23 +				GetSaver().Save(tempFile, obj);
    1.24 +				ZipFile file = new ZipFile(tempFile);
    1.25 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
    1.26 +				Stream stream = file.GetInputStream(zipEntry);
    1.27 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentWithCategories()));
    1.28 +				file.Close();
    1.29 +			}
    1.30 +			finally
    1.31 +			{
    1.32 +				if (File.Exists(tempFile))
    1.33 +				{
    1.34 +					File.Delete(tempFile);
    1.35 +				}
    1.36 +			}
    1.37 +		}
    1.38 +
    1.39  		protected abstract IWarFoundryFileSaver GetSaver();
    1.40  
    1.41  		protected abstract string GetEntryName(WarFoundryLoadedObject obj);
    1.42 @@ -390,5 +422,7 @@
    1.43  		protected abstract byte[] GetGameSystemContentWithPointsNameBytes(string singular, string plural);
    1.44  
    1.45  		protected abstract byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName);
    1.46 +
    1.47 +		protected abstract byte[] GetGameSystemContentWithCategories();
    1.48  	}
    1.49  }
     2.1 --- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Wed Oct 26 15:46:48 2011 +0100
     2.2 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Fri Oct 28 20:52:01 2011 +0100
     2.3 @@ -66,7 +66,12 @@
     2.4  
     2.5  		protected override byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName)
     2.6  		{
     2.7 -			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>");
     2.8 +			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>");
     2.9 +		}
    2.10 +
    2.11 +		protected override byte[] GetGameSystemContentWithCategories ()
    2.12 +		{
    2.13 +			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>");
    2.14  		}
    2.15  	}
    2.16  }