changeset 99:dd384f35a96f

Re #324: Add saving of Race and System data to files * Start to migrate Army saving to same structure * Add first test * Give MockArmy a specific ID
author IBBoard <dev@ibboard.co.uk>
date Wed, 09 Mar 2011 20:55:35 +0000
parents 49c5e24decb9
children 5addcb8f7766
files API/Objects/Mock/MockArmy.cs API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs
diffstat 3 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Mock/MockArmy.cs	Wed Mar 09 20:45:13 2011 +0000
+++ b/API/Objects/Mock/MockArmy.cs	Wed Mar 09 20:55:35 2011 +0000
@@ -22,6 +22,7 @@
 
 		private MockArmy () : base(MockRace.GetMockRace (), "Mock Army", 2000)
 		{
+			ID = "MockArmy";
 		}
 	}
 }
--- a/API/Savers/IWarFoundryFileSaverTests.cs	Wed Mar 09 20:45:13 2011 +0000
+++ b/API/Savers/IWarFoundryFileSaverTests.cs	Wed Mar 09 20:55:35 2011 +0000
@@ -120,6 +120,29 @@
 				}
 			}
 		}
+
+		[Test()]
+		public void TestSaverCreatesSingleEntryWithCorrectContentForOneArmy()
+		{
+			string tempFile = Path.GetTempFileName();
+			try
+			{
+				MockArmy obj = MockArmy.GetMockArmy();
+				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(GetArmyContentBytes()));
+				file.Close();
+			}
+			finally
+			{
+				if (File.Exists(tempFile))
+				{
+					File.Delete(tempFile);
+				}
+			}
+		}
 		
 		[Test()]
 		public void TestFileExtensionsAreCorrectForType()
@@ -141,6 +164,8 @@
 		
 		protected abstract string GetGameSystemExtension();
 
-		public abstract byte[] GetGameSystemContentBytes();
+		protected abstract byte[] GetGameSystemContentBytes();
+		
+		protected abstract byte[] GetArmyContentBytes();
 	}
 }
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Wed Mar 09 20:45:13 2011 +0000
+++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Wed Mar 09 20:55:35 2011 +0000
@@ -39,9 +39,14 @@
 			return ".systemx";
 		}
 
-		public override byte[] GetGameSystemContentBytes()
+		protected override byte[] GetGameSystemContentBytes()
 		{
 			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[] 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>");
+		}
 	}
 }