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 diff
     1.1 --- a/API/Factories/Requirement/Mock/MockRequirement.cs	Fri Oct 28 20:52:01 2011 +0100
     1.2 +++ b/API/Factories/Requirement/Mock/MockRequirement.cs	Mon Oct 31 20:23:09 2011 +0000
     1.3 @@ -13,6 +13,14 @@
     1.4  		{
     1.5  		}
     1.6  
     1.7 +		public string RequirementID
     1.8 +		{
     1.9 +			get
    1.10 +			{
    1.11 +				throw new NotImplementedException();
    1.12 +			}
    1.13 +		}
    1.14 +
    1.15  		public Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy)
    1.16  		{
    1.17  			throw new NotImplementedException();
     2.1 --- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Fri Oct 28 20:52:01 2011 +0100
     2.2 +++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs	Mon Oct 31 20:23:09 2011 +0000
     2.3 @@ -5,10 +5,15 @@
     2.4  
     2.5  namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock
     2.6  {
     2.7 -	public class AbstractFixedRequirement : IRequirement
     2.8 +	public abstract class AbstractFixedRequirement : IRequirement
     2.9  	{
    2.10  		private Validation result;
    2.11  
    2.12 +		public string RequirementID
    2.13 +		{
    2.14 +			get { return GetType().Name; }
    2.15 +		}
    2.16 +
    2.17  		public AbstractFixedRequirement(Validation fixedResult)
    2.18  		{
    2.19  			result = fixedResult;
     3.1 --- a/API/Savers/IWarFoundryFileSaverTests.cs	Fri Oct 28 20:52:01 2011 +0100
     3.2 +++ b/API/Savers/IWarFoundryFileSaverTests.cs	Mon Oct 31 20:23:09 2011 +0000
     3.3 @@ -370,7 +370,6 @@
     3.4  		[Test()]
     3.5  		public void TestGameSystemWithCategories()
     3.6  		{
     3.7 -
     3.8  			string tempFile = Path.GetTempFileName();
     3.9  			try
    3.10  			{
    3.11 @@ -399,6 +398,37 @@
    3.12  			}
    3.13  		}
    3.14  
    3.15 +		[Test()]
    3.16 +		public void TestGameSystemWithStatLines()
    3.17 +		{
    3.18 +			string tempFile = Path.GetTempFileName();
    3.19 +			try
    3.20 +			{
    3.21 +				MockGameSystem obj = new MockGameSystem();
    3.22 +				//MockGameSystem already has a stat line, so add one more
    3.23 +				SystemStats systemStats = new SystemStats("stats");
    3.24 +				systemStats.AddStatSlot("M");
    3.25 +				systemStats.AddStatSlot("S");
    3.26 +				systemStats.AddStatSlot("T");
    3.27 +				systemStats.AddStatSlot("W");
    3.28 +				obj.AddSystemStats(systemStats);
    3.29 +				obj.StandardSystemStatsID = "stats";
    3.30 +				GetSaver().Save(tempFile, obj);
    3.31 +				ZipFile file = new ZipFile(tempFile);
    3.32 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
    3.33 +				Stream stream = file.GetInputStream(zipEntry);
    3.34 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentWithStats()));
    3.35 +				file.Close();
    3.36 +			}
    3.37 +			finally
    3.38 +			{
    3.39 +				if (File.Exists(tempFile))
    3.40 +				{
    3.41 +					File.Delete(tempFile);
    3.42 +				}
    3.43 +			}
    3.44 +		}
    3.45 +
    3.46  		protected abstract IWarFoundryFileSaver GetSaver();
    3.47  
    3.48  		protected abstract string GetEntryName(WarFoundryLoadedObject obj);
    3.49 @@ -424,5 +454,7 @@
    3.50  		protected abstract byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName);
    3.51  
    3.52  		protected abstract byte[] GetGameSystemContentWithCategories();
    3.53 +
    3.54 +		protected abstract byte[] GetGameSystemContentWithStats();
    3.55  	}
    3.56  }
     4.1 --- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Fri Oct 28 20:52:01 2011 +0100
     4.2 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Mon Oct 31 20:23:09 2011 +0000
     4.3 @@ -69,9 +69,14 @@
     4.4  			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>");
     4.5  		}
     4.6  
     4.7 -		protected override byte[] GetGameSystemContentWithCategories ()
     4.8 +		protected override byte[] GetGameSystemContentWithCategories()
     4.9  		{
    4.10  			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>");
    4.11  		}
    4.12 +
    4.13 +		protected override byte[] GetGameSystemContentWithStats()
    4.14 +		{
    4.15 +			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>");
    4.16 +		}
    4.17  	}
    4.18  }