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 diff
     1.1 --- a/API/Objects/Mock/MockGameSystem.cs	Sat Mar 05 20:08:13 2011 +0000
     1.2 +++ b/API/Objects/Mock/MockGameSystem.cs	Wed Mar 09 20:45:13 2011 +0000
     1.3 @@ -24,6 +24,8 @@
     1.4  		
     1.5  		public MockGameSystem () : base("mocksystem", "Mock Game System", MockSystemFactory.GetMockFactory())
     1.6  		{
     1.7 +			AddSystemStats(new SystemStats("default"));
     1.8 +			StandardSystemStatsID = "default";
     1.9  		}
    1.10  	}
    1.11  }
     2.1 --- a/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 05 20:08:13 2011 +0000
     2.2 +++ b/API/Savers/IWarFoundryFileSaverTests.cs	Wed Mar 09 20:45:13 2011 +0000
     2.3 @@ -7,6 +7,8 @@
     2.4  using ICSharpCode.SharpZipLib.Zip;
     2.5  using NUnit.Framework;
     2.6  using NUnit.Framework.SyntaxHelpers;
     2.7 +using ICSharpCode.SharpZipLib.Core;
     2.8 +using IBBoard.IO;
     2.9  
    2.10  namespace IBBoard.WarFoundry.API.Savers
    2.11  {
    2.12 @@ -16,6 +18,7 @@
    2.13  		public void TestSaverCreatesFile()
    2.14  		{
    2.15  			string tempFile = Path.GetTempFileName();
    2.16 +			
    2.17  			try
    2.18  			{
    2.19  				bool saved = GetSaver().Save(tempFile, new MockGameSystem());
    2.20 @@ -94,6 +97,29 @@
    2.21  				}
    2.22  			}
    2.23  		}
    2.24 +
    2.25 +		[Test()]
    2.26 +		public void TestSaverCreatesSingleEntryWithCorrectContentForOneSystem()
    2.27 +		{
    2.28 +			string tempFile = Path.GetTempFileName();
    2.29 +			try
    2.30 +			{
    2.31 +				MockGameSystem obj = new MockGameSystem();
    2.32 +				GetSaver().Save(tempFile, obj);
    2.33 +				ZipFile file = new ZipFile(tempFile);
    2.34 +				ZipEntry zipEntry = file.GetEntry(GetEntryName(obj));
    2.35 +				Stream stream = file.GetInputStream(zipEntry);
    2.36 +				Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes()));
    2.37 +				file.Close();
    2.38 +			}
    2.39 +			finally
    2.40 +			{
    2.41 +				if (File.Exists(tempFile))
    2.42 +				{
    2.43 +					File.Delete(tempFile);
    2.44 +				}
    2.45 +			}
    2.46 +		}
    2.47  		
    2.48  		[Test()]
    2.49  		public void TestFileExtensionsAreCorrectForType()
    2.50 @@ -114,5 +140,7 @@
    2.51  		protected abstract string GetRaceExtension();
    2.52  		
    2.53  		protected abstract string GetGameSystemExtension();
    2.54 +
    2.55 +		public abstract byte[] GetGameSystemContentBytes();
    2.56  	}
    2.57  }
     3.1 --- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 05 20:08:13 2011 +0000
     3.2 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Wed Mar 09 20:45:13 2011 +0000
     3.3 @@ -2,6 +2,7 @@
     3.4  using NUnit.Framework;
     3.5  using System.IO;
     3.6  using IBBoard.WarFoundry.API.Objects;
     3.7 +using IBBoard.Lang;
     3.8  
     3.9  namespace IBBoard.WarFoundry.API.Savers.Xml
    3.10  {
    3.11 @@ -12,32 +13,35 @@
    3.12  		{
    3.13  			return new WarFoundryXmlFileSaver();
    3.14  		}
    3.15 -		
    3.16 -		protected override string GetEntryName (WarFoundryLoadedObject obj)
    3.17 +
    3.18 +		protected override string GetEntryName(WarFoundryLoadedObject obj)
    3.19  		{
    3.20  			return obj.ID + GetFileExtensionForType(obj);
    3.21  		}
    3.22 -		
    3.23 -		protected override string GetFileExtensionForType (WarFoundryLoadedObject obj)
    3.24 +
    3.25 +		protected override string GetFileExtensionForType(WarFoundryLoadedObject obj)
    3.26  		{
    3.27  			return GetSaver().GetFileExtension(obj);
    3.28  		}
    3.29  
    3.30 -		protected override string GetArmyExtension ()
    3.31 +		protected override string GetArmyExtension()
    3.32  		{
    3.33  			return ".armyx";
    3.34  		}
    3.35 -		
    3.36 -		
    3.37 -		protected override string GetRaceExtension ()
    3.38 +
    3.39 +		protected override string GetRaceExtension()
    3.40  		{
    3.41  			return ".racex";
    3.42  		}
    3.43 -		
    3.44 -		
    3.45 -		protected override string GetGameSystemExtension ()
    3.46 +
    3.47 +		protected override string GetGameSystemExtension()
    3.48  		{
    3.49  			return ".systemx";
    3.50  		}
    3.51 +
    3.52 +		public override byte[] GetGameSystemContentBytes()
    3.53 +		{
    3.54 +			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>");
    3.55 +		}
    3.56  	}
    3.57  }