changeset 98:49c5e24decb9

Re #338: WarFoundry.API - Save System Data * Make sure MockGameSystem doesn't cause null pointers during tests (separate bug to fix properly) * Add test for saving GameSystem * Add implementation of test to XML version
author IBBoard <dev@ibboard.co.uk>
date Wed, 09 Mar 2011 20:45:13 +0000
parents 45b80fed5e2a
children dd384f35a96f
files API/Objects/Mock/MockGameSystem.cs API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs
diffstat 3 files changed, 45 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Mock/MockGameSystem.cs	Sat Mar 05 20:08:13 2011 +0000
+++ b/API/Objects/Mock/MockGameSystem.cs	Wed Mar 09 20:45:13 2011 +0000
@@ -24,6 +24,8 @@
 		
 		public MockGameSystem () : base("mocksystem", "Mock Game System", MockSystemFactory.GetMockFactory())
 		{
+			AddSystemStats(new SystemStats("default"));
+			StandardSystemStatsID = "default";
 		}
 	}
 }
--- a/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 05 20:08:13 2011 +0000
+++ b/API/Savers/IWarFoundryFileSaverTests.cs	Wed Mar 09 20:45:13 2011 +0000
@@ -7,6 +7,8 @@
 using ICSharpCode.SharpZipLib.Zip;
 using NUnit.Framework;
 using NUnit.Framework.SyntaxHelpers;
+using ICSharpCode.SharpZipLib.Core;
+using IBBoard.IO;
 
 namespace IBBoard.WarFoundry.API.Savers
 {
@@ -16,6 +18,7 @@
 		public void TestSaverCreatesFile()
 		{
 			string tempFile = Path.GetTempFileName();
+			
 			try
 			{
 				bool saved = GetSaver().Save(tempFile, new MockGameSystem());
@@ -94,6 +97,29 @@
 				}
 			}
 		}
+
+		[Test()]
+		public void TestSaverCreatesSingleEntryWithCorrectContentForOneSystem()
+		{
+			string tempFile = Path.GetTempFileName();
+			try
+			{
+				MockGameSystem obj = new MockGameSystem();
+				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(GetGameSystemContentBytes()));
+				file.Close();
+			}
+			finally
+			{
+				if (File.Exists(tempFile))
+				{
+					File.Delete(tempFile);
+				}
+			}
+		}
 		
 		[Test()]
 		public void TestFileExtensionsAreCorrectForType()
@@ -114,5 +140,7 @@
 		protected abstract string GetRaceExtension();
 		
 		protected abstract string GetGameSystemExtension();
+
+		public abstract byte[] GetGameSystemContentBytes();
 	}
 }
--- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 05 20:08:13 2011 +0000
+++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Wed Mar 09 20:45:13 2011 +0000
@@ -2,6 +2,7 @@
 using NUnit.Framework;
 using System.IO;
 using IBBoard.WarFoundry.API.Objects;
+using IBBoard.Lang;
 
 namespace IBBoard.WarFoundry.API.Savers.Xml
 {
@@ -12,32 +13,35 @@
 		{
 			return new WarFoundryXmlFileSaver();
 		}
-		
-		protected override string GetEntryName (WarFoundryLoadedObject obj)
+
+		protected override string GetEntryName(WarFoundryLoadedObject obj)
 		{
 			return obj.ID + GetFileExtensionForType(obj);
 		}
-		
-		protected override string GetFileExtensionForType (WarFoundryLoadedObject obj)
+
+		protected override string GetFileExtensionForType(WarFoundryLoadedObject obj)
 		{
 			return GetSaver().GetFileExtension(obj);
 		}
 
-		protected override string GetArmyExtension ()
+		protected override string GetArmyExtension()
 		{
 			return ".armyx";
 		}
-		
-		
-		protected override string GetRaceExtension ()
+
+		protected override string GetRaceExtension()
 		{
 			return ".racex";
 		}
-		
-		
-		protected override string GetGameSystemExtension ()
+
+		protected override string GetGameSystemExtension()
 		{
 			return ".systemx";
 		}
+
+		public 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>");
+		}
 	}
 }