view API/Factories/Xml/WarFoundryXmlFactoryUtilTest.cs @ 237:833f72be715a default tip

* Remove rogue print statements
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Nov 2012 20:58:48 +0000
parents b2517bb113d0
children
line wrap: on
line source

//  This file (WarFoundryXmlFactoryUtilTest.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 System.Xml;
using System.Xml.Schema;
using IBBoard.IO;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace IBBoard.WarFoundry.API.Factories.Xml
{
	[TestFixture()]
	public class WarFoundryXmlFactoryUtilTest
	{
		[Test()]
		public void TestParsingExtendedDataFiles()
		{
			TestValidFileLoading("testdata/extended-data.racex");
			TestValidFileLoading("testdata/extended-data.systemx");
			TestValidFileLoading("testdata/extended-data.armyx");
		}
		
		[Test()]
		public void TestParsingValidArmyContainedID()
		{
			TestValidFileLoading("testdata/xml-factory-util/valid-contained-id.armyx");
		}
		
		private static void TestValidFileLoading(string path)
		{
			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(path);
			Assert.IsNotNull(document);
		}
		
		[Test()]
		public void TestArmyFileValidationFailsForDuplicateUnitID()
		{
			TestFileValidationFailure("testdata/xml-factory-util/duplicate-unit-id.armyx");
		}

		[Test()]
		public void TestArmyFileValidationFailsForInvalidContainedID()
		{
			TestFileValidationFailure("testdata/xml-factory-util/invalid-contained-id.armyx");
		}

		private void TestFileValidationFailure(string filePath)
		{			
			try
			{
				SingleXmlObjectLoader.CreateDocumentElementFromFile(filePath);
				Assert.Fail("Excepted exception not thrown");
			}
			catch (InvalidFileException ex)
			{
				Exception innerException = ex.InnerException;
				Assert.That(innerException, Is.InstanceOfType(typeof(XmlSchemaValidationException)));
			}
		}
	}
}