view API/Factories/Xml/WarFoundryXmlFactoryTests.cs @ 228:7c21ca1482cb

Re #419: Remove assumptions of a file-based install * Update tests to use new "loadable object" and "loadable object source" wrappers
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Jul 2012 21:02:53 +0100
parents 3c2c108a2f08
children 6ec46f3db2d4
line wrap: on
line source

using System;
using NUnit.Framework;
using System.IO;
using System.Collections.Generic;
using IBBoard.WarFoundry.API.Objects;
using NUnit.Framework.SyntaxHelpers;
using IBBoard.WarFoundry.API.Loading;

namespace IBBoard.WarFoundry.API.Factories.Xml
{
	[TestFixture()]
	public class WarFoundryXmlFactoryTests
	{
		[Test()]
		public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip()
		{
			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
			WarFoundryLoader.SetDefault(loader);
			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
			try
			{
				loader.RegisterFactory(factory);
				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.system"));
				Assert.That(objs, Has.Count(2));
				int raceCount = 0;
				int systemCount = 0;
				
				foreach (IWarFoundryObject obj in objs)
				{
					if (obj is Race)
					{
						raceCount++;
					}
					else
					if (obj is GameSystem)
					{
						systemCount++;
					}
				}
				
				Assert.That(raceCount, Is.EqualTo(1));
				Assert.That(systemCount, Is.EqualTo(1));
			}
			finally
			{				
				loader.UnregisterFactory(factory);
			}
		}
			
		[Test()]
		public void TestFactoryHandlesMultipleFilesWithOldNamesInOneRaceZip()
		{
			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
			WarFoundryLoader.SetDefault(loader);
			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
			loader.RegisterFactory(factory);
			try
			{
				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.race"));
				Assert.That(objs, Has.Count(2));
				int raceCount = 0;
				int systemCount = 0;
				
				foreach (IWarFoundryObject obj in objs)
				{
					if (obj is Race)
					{
						raceCount++;
					}
					else
					if (obj is GameSystem)
					{
						systemCount++;
					}
				}
				
				Assert.That(raceCount, Is.EqualTo(1));
				Assert.That(systemCount, Is.EqualTo(1));
			}
			finally
			{				
				loader.UnregisterFactory(factory);
			}
		}
		
		[Test()]
		public void TestFactoryHandlesMultipleFilesWithMultipleNewNamesInOneSystemZip()
		{
			EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader();
			WarFoundryLoader.SetDefault(loader);
			WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory();
			loader.RegisterFactory(factory);
			try
			{
				ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Multipack.system"));
				Assert.That(objs, Has.Count(4));
				int raceCount = 0;
				int systemCount = 0;
				
				foreach (IWarFoundryObject obj in objs)
				{
					if (obj is Race)
					{
						raceCount++;
					}
					else
					if (obj is GameSystem)
					{
						systemCount++;
					}
				}
				
				Assert.That(raceCount, Is.EqualTo(2));
				Assert.That(systemCount, Is.EqualTo(2));
			}
			finally
			{				
				loader.UnregisterFactory(factory);
			}
		}
	}
}