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 wrap: on
line diff
--- a/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 12 19:54:07 2011 +0000
+++ b/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 12 20:16:30 2011 +0000
@@ -9,6 +9,7 @@
 using NUnit.Framework.SyntaxHelpers;
 using ICSharpCode.SharpZipLib.Core;
 using IBBoard.IO;
+using IBBoard.WarFoundry.API.Factories;
 
 namespace IBBoard.WarFoundry.API.Savers
 {
@@ -167,7 +168,7 @@
 		[Test()]
 		public void TestSaverCreatesTwoEntriesWithCorrectContentForOneSystemOneArmy()
 		{
-			//This doesn't make much sense (system and army in one file) but at the time of writing then Race isn't implemented
+			//This doesn't make much sense (system and army in one file) but at the time of writing then Race saving isn't implemented
 			string tempFile = Path.GetTempFileName();
 			try
 			{
@@ -191,6 +192,53 @@
 				}
 			}
 		}
+
+		[Test()]
+		public void TestSaverCreatesTwoEntriesForTwoSystems()
+		{
+			string tempFile = Path.GetTempFileName();
+			try
+			{
+				GetSaver().Save(tempFile, new MockGameSystem(), new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory()));
+				ZipFile file = new ZipFile(tempFile);
+				Assert.That(file.Count, Is.EqualTo(2));
+				file.Close();
+			}
+			finally
+			{
+				if (File.Exists(tempFile))
+				{
+					File.Delete(tempFile);
+				}
+			}
+		}
+
+		[Test()]
+		public void TestSaverCreatesTwoEntriesWithCorrectContentForTwoSystems()
+		{
+			string tempFile = Path.GetTempFileName();
+			try
+			{
+				MockGameSystem system1 = new MockGameSystem();
+				GameSystem system2 = new GameSystem("otherSystem", "Other System", new DummyWarFoundryFactory());
+				GetSaver().Save(tempFile, system1, system2);
+				ZipFile file = new ZipFile(tempFile);
+				ZipEntry zipEntry = file.GetEntry(GetEntryName(system1));
+				Stream stream = file.GetInputStream(zipEntry);
+				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes()));
+				zipEntry = file.GetEntry(GetEntryName(system2));
+				stream = file.GetInputStream(zipEntry);
+				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetOtherGameSystemContentBytes()));
+				file.Close();
+			}
+			finally
+			{
+				if (File.Exists(tempFile))
+				{
+					File.Delete(tempFile);
+				}
+			}
+		}
 		
 		[Test()]
 		public void TestFileExtensionsAreCorrectForType()
@@ -213,6 +261,8 @@
 		protected abstract string GetGameSystemExtension();
 
 		protected abstract byte[] GetGameSystemContentBytes();
+
+		protected abstract byte[] GetOtherGameSystemContentBytes();
 		
 		protected abstract byte[] GetArmyContentBytes();
 	}
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 12 19:54:07 2011 +0000
+++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 12 20:16:30 2011 +0000
@@ -44,6 +44,11 @@
 			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>");
 		}
 
+		protected override byte[] GetOtherGameSystemContentBytes()
+		{
+			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>");
+		}
+
 		protected override byte[] GetArmyContentBytes ()
 		{
 			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>");