changeset 179:32b3e41bc8f0

Fixes #338: WarFoundry.API - Save System Data * Add final test to cover all of system data * Add "expected" data to XML test to check conformance
author IBBoard <dev@ibboard.co.uk>
date Mon, 31 Oct 2011 20:23:09 +0000
parents 50b8466783ed
children ce40484ad921
files API/Factories/Requirement/Mock/MockRequirement.cs API/Objects/Requirement/Mock/AbstractFixedRequirement.cs API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs
diffstat 4 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Requirement/Mock/MockRequirement.cs	Fri Oct 28 20:52:01 2011 +0100
+++ b/API/Factories/Requirement/Mock/MockRequirement.cs	Mon Oct 31 20:23:09 2011 +0000
@@ -13,6 +13,14 @@
 		{
 		}
 
+		public string RequirementID
+		{
+			get
+			{
+				throw new NotImplementedException();
+			}
+		}
+
 		public Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
 		{
 			throw new NotImplementedException();
--- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Fri Oct 28 20:52:01 2011 +0100
+++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Mon Oct 31 20:23:09 2011 +0000
@@ -5,10 +5,15 @@
 
 namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
 {
-	public class AbstractFixedRequirement : IRequirement
+	public abstract class AbstractFixedRequirement : IRequirement
 	{
 		private Validation result;
 
+		public string RequirementID
+		{
+			get { return GetType().Name; }
+		}
+
 		public AbstractFixedRequirement(Validation fixedResult)
 		{
 			result = fixedResult;
--- a/API/Savers/IWarFoundryFileSaverTests.cs	Fri Oct 28 20:52:01 2011 +0100
+++ b/API/Savers/IWarFoundryFileSaverTests.cs	Mon Oct 31 20:23:09 2011 +0000
@@ -370,7 +370,6 @@
 		[Test()]
 		public void TestGameSystemWithCategories()
 		{
-
 			string tempFile = Path.GetTempFileName();
 			try
 			{
@@ -399,6 +398,37 @@
 			}
 		}
 
+		[Test()]
+		public void TestGameSystemWithStatLines()
+		{
+			string tempFile = Path.GetTempFileName();
+			try
+			{
+				MockGameSystem obj = new MockGameSystem();
+				//MockGameSystem already has a stat line, so add one more
+				SystemStats systemStats = new SystemStats("stats");
+				systemStats.AddStatSlot("M");
+				systemStats.AddStatSlot("S");
+				systemStats.AddStatSlot("T");
+				systemStats.AddStatSlot("W");
+				obj.AddSystemStats(systemStats);
+				obj.StandardSystemStatsID = "stats";
+				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(GetGameSystemContentWithStats()));
+				file.Close();
+			}
+			finally
+			{
+				if (File.Exists(tempFile))
+				{
+					File.Delete(tempFile);
+				}
+			}
+		}
+
 		protected abstract IWarFoundryFileSaver GetSaver();
 
 		protected abstract string GetEntryName(WarFoundryLoadedObject obj);
@@ -424,5 +454,7 @@
 		protected abstract byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName);
 
 		protected abstract byte[] GetGameSystemContentWithCategories();
+
+		protected abstract byte[] GetGameSystemContentWithStats();
 	}
 }
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Fri Oct 28 20:52:01 2011 +0100
+++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Mon Oct 31 20:23:09 2011 +0000
@@ -69,9 +69,14 @@
 			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 ()
+		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>");
 		}
+
+		protected override byte[] GetGameSystemContentWithStats()
+		{
+			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=""stats""><sysStats id=""default"" /><sysStats id=""stats""><sysStat name=""M"" /><sysStat name=""S"" /><sysStat name=""T"" /><sysStat name=""W"" /></sysStats></sysStatsList></system>");
+		}
 	}
 }