changeset 101:08fd75eafb67

Re #324: Add saving of Race and System data to files * Add tests for two systems in one file
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Mar 2011 20:16:30 +0000
parents 5addcb8f7766
children a3bc8174299f
files API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs
diffstat 2 files changed, 56 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 12 19:54:07 2011 +0000
     1.2 +++ b/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 12 20:16:30 2011 +0000
     1.3 @@ -9,6 +9,7 @@
     1.4  using NUnit.Framework.SyntaxHelpers;
     1.5  using ICSharpCode.SharpZipLib.Core;
     1.6  using IBBoard.IO;
     1.7 +using IBBoard.WarFoundry.API.Factories;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Savers
    1.10  {
    1.11 @@ -167,7 +168,7 @@
    1.12  		[Test()]
    1.13  		public void TestSaverCreatesTwoEntriesWithCorrectContentForOneSystemOneArmy()
    1.14  		{
    1.15 -			//This doesn't make much sense (system and army in one file) but at the time of writing then Race isn't implemented
    1.16 +			//This doesn't make much sense (system and army in one file) but at the time of writing then Race saving isn't implemented
    1.17  			string tempFile = Path.GetTempFileName();
    1.18  			try
    1.19  			{
    1.20 @@ -191,6 +192,53 @@
    1.21  				}
    1.22  			}
    1.23  		}
    1.24 +
    1.25 +		[Test()]
    1.26 +		public void TestSaverCreatesTwoEntriesForTwoSystems()
    1.27 +		{
    1.28 +			string tempFile = Path.GetTempFileName();
    1.29 +			try
    1.30 +			{
    1.31 +				GetSaver().Save(tempFile, new MockGameSystem(), new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()));
    1.32 +				ZipFile file = new ZipFile(tempFile);
    1.33 +				Assert.That(file.Count, Is.EqualTo(2));
    1.34 +				file.Close();
    1.35 +			}
    1.36 +			finally
    1.37 +			{
    1.38 +				if (File.Exists(tempFile))
    1.39 +				{
    1.40 +					File.Delete(tempFile);
    1.41 +				}
    1.42 +			}
    1.43 +		}
    1.44 +
    1.45 +		[Test()]
    1.46 +		public void TestSaverCreatesTwoEntriesWithCorrectContentForTwoSystems()
    1.47 +		{
    1.48 +			string tempFile = Path.GetTempFileName();
    1.49 +			try
    1.50 +			{
    1.51 +				MockGameSystem system1 = new MockGameSystem();
    1.52 +				GameSystem system2 = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory());
    1.53 +				GetSaver().Save(tempFile, system1, system2);
    1.54 +				ZipFile file = new ZipFile(tempFile);
    1.55 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(system1));
    1.56 +				Stream stream = file.GetInputStream(zipEntry);
    1.57 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes()));
    1.58 +				zipEntry = file.GetEntry(GetEntryName(system2));
    1.59 +				stream = file.GetInputStream(zipEntry);
    1.60 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetOtherGameSystemContentBytes()));
    1.61 +				file.Close();
    1.62 +			}
    1.63 +			finally
    1.64 +			{
    1.65 +				if (File.Exists(tempFile))
    1.66 +				{
    1.67 +					File.Delete(tempFile);
    1.68 +				}
    1.69 +			}
    1.70 +		}
    1.71  		
    1.72  		[Test()]
    1.73  		public void TestFileExtensionsAreCorrectForType()
    1.74 @@ -213,6 +261,8 @@
    1.75  		protected abstract string GetGameSystemExtension();
    1.76  
    1.77  		protected abstract byte[] GetGameSystemContentBytes();
    1.78 +
    1.79 +		protected abstract byte[] GetOtherGameSystemContentBytes();
    1.80  		
    1.81  		protected abstract byte[] GetArmyContentBytes();
    1.82  	}
     2.1 --- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 12 19:54:07 2011 +0000
     2.2 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 12 20:16:30 2011 +0000
     2.3 @@ -44,6 +44,11 @@
     2.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=""0"" warn=""false"" allowAllies=""false""><categories /><sysStatsList defaultStats=""default""><sysStats id=""default"" /></sysStatsList></system>");
     2.5  		}
     2.6  
     2.7 +		protected override byte[] GetOtherGameSystemContentBytes()
     2.8 +		{
     2.9 +			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=""0"" warn=""false"" allowAllies=""false""><categories /><sysStatsList defaultStats=""_"" /></system>");
    2.10 +		}
    2.11 +
    2.12  		protected override byte[] GetArmyContentBytes ()
    2.13  		{
    2.14  			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>");