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 diff
     1.1 --- a/API/Savers/IWarFoundryFileSaverTests.cs	Sun Sep 25 20:53:47 2011 +0100
     1.2 +++ b/API/Savers/IWarFoundryFileSaverTests.cs	Wed Oct 26 15:40:52 2011 +0100
     1.3 @@ -250,6 +250,91 @@
     1.4  			Assert.That(GetSaver().GetFileExtension(new MockGameSystem()), Is.EqualTo(GetGameSystemExtension()));
     1.5  		}
     1.6  
     1.7 +		[Test()]
     1.8 +		public void TestPointsValueAbbreviationsSaved()
     1.9 +		{
    1.10 +			string tempFile = Path.GetTempFileName();
    1.11 +			try
    1.12 +			{
    1.13 +				MockGameSystem obj = new MockGameSystem();
    1.14 +				string plural = "ptii";
    1.15 +				string singular = "ptus";
    1.16 +				obj.SystemPtsAbbrevPlural = plural;
    1.17 +				obj.SystemPtsAbbrevSingle = singular;
    1.18 +				GetSaver().Save(tempFile, obj);
    1.19 +				ZipFile file = new ZipFile(tempFile);
    1.20 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
    1.21 +				Stream stream = file.GetInputStream(zipEntry);
    1.22 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentWithPointsAbbrevsBytes(singular, plural)));
    1.23 +				file.Close();
    1.24 +			}
    1.25 +			finally
    1.26 +			{
    1.27 +				if (File.Exists(tempFile))
    1.28 +				{
    1.29 +					File.Delete(tempFile);
    1.30 +				}
    1.31 +			}
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestPointsValueNamesSaved()
    1.36 +		{
    1.37 +			string tempFile = Path.GetTempFileName();
    1.38 +			try
    1.39 +			{
    1.40 +				MockGameSystem obj = new MockGameSystem();
    1.41 +				string plural = "pointii";
    1.42 +				string singular = "pointus";
    1.43 +				obj.SystemPtsNamePlural = plural;
    1.44 +				obj.SystemPtsNameSingle = singular;
    1.45 +				GetSaver().Save(tempFile, obj);
    1.46 +				ZipFile file = new ZipFile(tempFile);
    1.47 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
    1.48 +				Stream stream = file.GetInputStream(zipEntry);
    1.49 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentWithPointsNameBytes(singular, plural)));
    1.50 +				file.Close();
    1.51 +			}
    1.52 +			finally
    1.53 +			{
    1.54 +				if (File.Exists(tempFile))
    1.55 +				{
    1.56 +					File.Delete(tempFile);
    1.57 +				}
    1.58 +			}
    1.59 +		}
    1.60 +
    1.61 +		[Test()]
    1.62 +		public void TestPointsValueAbbreviationsAndNamesSaved()
    1.63 +		{
    1.64 +			string tempFile = Path.GetTempFileName();
    1.65 +			try
    1.66 +			{
    1.67 +				MockGameSystem obj = new MockGameSystem();
    1.68 +				string plural = "ptii";
    1.69 +				string singular = "ptus";
    1.70 +				string pluralName = "pointii";
    1.71 +				string singularName = "pointus";
    1.72 +				obj.SystemPtsAbbrevPlural = plural;
    1.73 +				obj.SystemPtsAbbrevSingle = singular;
    1.74 +				obj.SystemPtsNamePlural = pluralName;
    1.75 +				obj.SystemPtsNameSingle = singularName;
    1.76 +				GetSaver().Save(tempFile, obj);
    1.77 +				ZipFile file = new ZipFile(tempFile);
    1.78 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
    1.79 +				Stream stream = file.GetInputStream(zipEntry);
    1.80 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentWithPointsAbbrevsAndNameBytes(singular, plural, singularName, pluralName)));
    1.81 +				file.Close();
    1.82 +			}
    1.83 +			finally
    1.84 +			{
    1.85 +				if (File.Exists(tempFile))
    1.86 +				{
    1.87 +					File.Delete(tempFile);
    1.88 +				}
    1.89 +			}
    1.90 +		}
    1.91 +
    1.92  		protected abstract IWarFoundryFileSaver GetSaver();
    1.93  
    1.94  		protected abstract string GetEntryName(WarFoundryLoadedObject obj);
    1.95 @@ -267,5 +352,11 @@
    1.96  		protected abstract byte[] GetOtherGameSystemContentBytes();
    1.97  		
    1.98  		protected abstract byte[] GetArmyContentBytes();
    1.99 +
   1.100 +		protected abstract byte[] GetGameSystemContentWithPointsAbbrevsBytes(string singular, string plural);
   1.101 +
   1.102 +		protected abstract byte[] GetGameSystemContentWithPointsNameBytes(string singular, string plural);
   1.103 +
   1.104 +		protected abstract byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName);
   1.105  	}
   1.106  }
     2.1 --- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sun Sep 25 20:53:47 2011 +0100
     2.2 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Wed Oct 26 15:40:52 2011 +0100
     2.3 @@ -41,17 +41,32 @@
     2.4  
     2.5  		protected override byte[] GetGameSystemContentBytes()
     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""><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="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>");
     2.9  		}
    2.10  
    2.11  		protected override byte[] GetOtherGameSystemContentBytes()
    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=""otherSystem"" name=""Other System"" defaultArmySize=""1000"" warn=""true"" allowAllies=""false""><categories /><sysStatsList defaultStats=""_"" /></system>");
    2.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=""otherSystem"" name=""Other System"" defaultArmySize=""1000"" warn=""true"" allowAllies=""false"" defaultPtsAbbreviationSingular="""" defaultPtsAbbreviationPlural="""" defaultPtsNameSingular="""" defaultPtsNamePlural=""""><categories /><sysStatsList defaultStats=""_"" /></system>");
    2.15  		}
    2.16  
    2.17 -		protected override byte[] GetArmyContentBytes ()
    2.18 +		protected override byte[] GetArmyContentBytes()
    2.19  		{
    2.20  			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>");
    2.21  		}
    2.22 +
    2.23 +		protected override byte[] GetGameSystemContentWithPointsAbbrevsBytes(string singular, string plural)
    2.24 +		{
    2.25 +			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>");
    2.26 +		}
    2.27 +
    2.28 +		protected override byte[] GetGameSystemContentWithPointsNameBytes(string singular, string plural)
    2.29 +		{
    2.30 +			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>");
    2.31 +		}
    2.32 +
    2.33 +		protected override byte[] GetGameSystemContentWithPointsAbbrevsAndNameBytes(string singular, string plural, string singularName, string pluralName)
    2.34 +		{
    2.35 +			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.36 +		}
    2.37  	}
    2.38  }