view API/Factories/Xml/WarFoundryXmlSystemFactoryTest.cs @ 239:370bec16a364 default tip

Add initial testing for equipment with type (incomplete)
author IBBoard <dev@ibboard.co.uk>
date Sun, 16 Oct 2016 20:29:35 +0100
parents e173c5512067
children
line wrap: on
line source

//  This file (WarFoundryXmlSystemFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
// 
//  // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.

using System;
using NUnit.Framework;
using System.IO;
using IBBoard.WarFoundry.API.Objects;
using IBBoard.IO;
using System.Xml.Schema;
using IBBoard.WarFoundry.API.Loading;

namespace IBBoard.WarFoundry.API.Factories.Xml
{
	[TestFixture()]
	public class WarFoundryXmlSystemFactoryTest
	{
		[Test()]
		public void TestBug311InvalidVersionToExtract788()
		{
			ILoadableObject repackFile = new LoadableFileObject("testdata/zip-format/Repack.system");
			Assert.That(WarFoundryXmlFactory.GetFactory().CanHandleFileAsGameSystem(repackFile), Is.True);
			Assert.That(WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(repackFile), Has.Count.EqualTo(1));
		}

		[Test()]
		public void TestGettingDefaultStatsIDFullyLoadsGameSystem()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-one-stats-set.systemx"));
			Assert.That(system.IsFullyLoaded, Is.False);
			string defaultStatsID = system.StandardSystemStatsID;
			Assert.That(defaultStatsID, Is.Not.Null);
			Assert.That(defaultStatsID, Is.Not.Empty);
			Assert.That(system.IsFullyLoaded, Is.True);
		}

		[Test()]
		public void TestValidDefaultStatsIDLoadsCorrectly()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-one-stats-set.systemx"));
			Assert.That(system.StandardSystemStatsID, Is.EqualTo("defaultStats"));
			Assert.That(system.SystemStats, Has.Length.EqualTo(1));
		}

		[Test()]
		public void TestValidDefaultStatsIDLoadsCorrectlyWithMultipleStatsSets()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-default-stats-multiple-stats-set.systemx"));
			Assert.That(system.StandardSystemStatsID, Is.EqualTo("defaultStats"));
			Assert.That(system.SystemStats, Has.Length.EqualTo(2));
		}

		[Test()]
		public void TestIncorrectDefaultStatsIDErrors()
		{
			TestFileValidationFailure("testdata/xml-system-factory/invalid-default-stats.systemx");
		}

		[Test()]
		public void TestDuplicateStatsIDErrors()
		{
			TestFileValidationFailure("testdata/xml-system-factory/duplicate-stats-set-id.systemx");
		}

		[Test()]
		public void TestValidCategoriesLoadsCorrectly()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/xml-system-factory/valid-categories.systemx"));
			Assert.That(system.Categories, Has.Length.EqualTo(5));
		}

		[Test()]
		public void TestDuplicateCategoryIDErrors()
		{
			TestFileValidationFailure("testdata/xml-system-factory/duplicate-category-ids.systemx");
		}
		
		[Test()]
		public void TestLoadingPointsNamesAndAbbreviations()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/points-strings/names.systemx"));
			Assert.That(system.SystemPtsAbbrevPlural, Is.EqualTo("ptii"));
			Assert.That(system.SystemPtsAbbrevSingle, Is.EqualTo("ptus"));
			Assert.That(system.SystemPtsNamePlural, Is.EqualTo("pointii"));
			Assert.That(system.SystemPtsNameSingle, Is.EqualTo("pointus"));
		}
		
		[Test()]
		public void TestLoadingDefaultPointsNamesAndAbbreviations()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
			Assert.That(system.SystemPtsAbbrevPlural, Is.EqualTo("pts"));
			Assert.That(system.SystemPtsAbbrevSingle, Is.EqualTo("pt"));
			Assert.That(system.SystemPtsNamePlural, Is.EqualTo("points"));
			Assert.That(system.SystemPtsNameSingle, Is.EqualTo("point"));
		}

		[Test]
		public void TestLoadingEquipmentCategories()
		{
			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
			Assert.That(system.EquipmentCategories, Is.EquivalentTo(new EquipmentCategory[]{new EquipmentCategory("equip1", "Weapons"), new EquipmentCategory("equip2", "Armour")}));
		}

		private void TestFileValidationFailure(string filePath)
		{
			FileInfo systemFile = new FileInfo(filePath);
			
			try
			{
				SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), systemFile);
				Assert.Fail("Excepted exception not thrown");
			}
			catch (InvalidFileException ex)
			{
				Exception innerException = ex.InnerException;
				Assert.That(innerException, Is.InstanceOf(typeof(XmlSchemaValidationException)));
			}
		}
	}
}