changeset 95:db6db25921fb

Re #324: Add saving of Race and System data to files * Add tests for the zip entry name
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Mar 2011 15:53:29 +0000
parents 10da200c7799
children 3c2c108a2f08
files API/Savers/IWarFoundryFileSaverTests.cs API/Savers/Xml/WarFoundryXmlFileSaverTests.cs
diffstat 2 files changed, 45 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 05 15:24:11 2011 +0000
     1.2 +++ b/API/Savers/IWarFoundryFileSaverTests.cs	Sat Mar 05 15:53:29 2011 +0000
     1.3 @@ -1,9 +1,11 @@
     1.4  using System;
     1.5 +using System.Collections;
     1.6 +using System.Collections.Generic;
     1.7  using System.IO;
     1.8  using IBBoard.WarFoundry.API.Objects;
     1.9  using IBBoard.WarFoundry.API.Objects.Mock;
    1.10 +using ICSharpCode.SharpZipLib.Zip;
    1.11  using NUnit.Framework;
    1.12 -using ICSharpCode.SharpZipLib.Zip;
    1.13  using NUnit.Framework.SyntaxHelpers;
    1.14  
    1.15  namespace IBBoard.WarFoundry.API.Savers
    1.16 @@ -28,7 +30,7 @@
    1.17  				}
    1.18  			}
    1.19  		}
    1.20 -		
    1.21 +
    1.22  		[Test()]
    1.23  		public void TestSaverCreatesZipFile()
    1.24  		{
    1.25 @@ -47,7 +49,7 @@
    1.26  				}
    1.27  			}
    1.28  		}
    1.29 -		
    1.30 +
    1.31  		[Test()]
    1.32  		public void TestSaverCreatesSingleEntryForOneObject()
    1.33  		{
    1.34 @@ -67,8 +69,36 @@
    1.35  				}
    1.36  			}
    1.37  		}
    1.38 -		
    1.39 +
    1.40 +		[Test()]
    1.41 +		public void TestSaverCreatesSingleEntryWithCorrectNameForOneObject()
    1.42 +		{
    1.43 +			string tempFile = Path.GetTempFileName();
    1.44 +			try
    1.45 +			{
    1.46 +				MockGameSystem obj = new MockGameSystem();
    1.47 +				GetSaver().Save(tempFile, obj);
    1.48 +				ZipFile file = new ZipFile(tempFile);
    1.49 +				IEnumerator enumerator = file.GetEnumerator();
    1.50 +				enumerator.MoveNext();
    1.51 +				ZipEntry current = (ZipEntry)enumerator.Current;
    1.52 +				Assert.That(current.Name, Is.EqualTo(GetEntryName(obj)));
    1.53 +				Assert.That(current.Name, Text.EndsWith(GetFileExtensionForType(obj)));
    1.54 +				file.Close();
    1.55 +			}
    1.56 +			finally
    1.57 +			{
    1.58 +				if (File.Exists(tempFile))
    1.59 +				{
    1.60 +					File.Delete(tempFile);
    1.61 +				}
    1.62 +			}
    1.63 +		}
    1.64  
    1.65  		protected abstract IWarFoundryFileSaver GetSaver();
    1.66 +
    1.67 +		protected abstract string GetEntryName(WarFoundryLoadedObject obj);
    1.68 +
    1.69 +		protected abstract string GetFileExtensionForType(WarFoundryLoadedObject obj);
    1.70  	}
    1.71  }
     2.1 --- a/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 05 15:24:11 2011 +0000
     2.2 +++ b/API/Savers/Xml/WarFoundryXmlFileSaverTests.cs	Sat Mar 05 15:53:29 2011 +0000
     2.3 @@ -1,6 +1,7 @@
     2.4  using System;
     2.5  using NUnit.Framework;
     2.6  using System.IO;
     2.7 +using IBBoard.WarFoundry.API.Objects;
     2.8  
     2.9  namespace IBBoard.WarFoundry.API.Savers.Xml
    2.10  {
    2.11 @@ -11,5 +12,15 @@
    2.12  		{
    2.13  			return new WarFoundryXmlFileSaver();
    2.14  		}
    2.15 +		
    2.16 +		protected override string GetEntryName (WarFoundryLoadedObject obj)
    2.17 +		{
    2.18 +			return obj.ID;
    2.19 +		}
    2.20 +		
    2.21 +		protected override string GetFileExtensionForType (WarFoundryLoadedObject obj)
    2.22 +		{
    2.23 +			return GetSaver().GetFileExtension(obj);
    2.24 +		}
    2.25  	}
    2.26  }