Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Factories/Xml/WarFoundryXmlLimitParserTest.cs @ 76:fb60ff2002fd WarFoundry_v0.1.1
Fixes #311: can't read ZIP file packed by Linux app Archive Manager/File Roller
* Add the data files as well!
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 30 Oct 2010 14:46:06 +0000 |
parents | 7f9e1fef069e |
children | e173c5512067 |
line wrap: on
line source
// This file (WarFoundryXmlLimitParserTest.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.IO; using System.Xml; using NUnit.Framework; using IBBoard.Limits; using NUnit.Framework.SyntaxHelpers; using IBBoard.IO; namespace IBBoard.WarFoundry.API.Factories.Xml { [TestFixture()] public class WarFoundryXmlLimitParserTest { [Test()] public void TestCompositeMaxLimit() { XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit.xml")); XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*"); WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser(); ILimit limit = parser.GetLimitFromElement(limitElem); Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit))); Assert.That(limit.GetLimit(1), Is.EqualTo(5)); Assert.That(limit.GetLimit(5), Is.EqualTo(5)); Assert.That(limit.GetLimit(10), Is.EqualTo(10)); Assert.That(limit.GetLimit(20), Is.EqualTo(10)); } [Test()] public void TestCompositeMinLimit() { XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-min-limit.xml")); XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*"); WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser(); ILimit limit = parser.GetLimitFromElement(limitElem); Assert.That(limit, Is.InstanceOfType(typeof(CompositeMinimumLimit))); Assert.That(limit.GetLimit(1), Is.EqualTo(1)); Assert.That(limit.GetLimit(5), Is.EqualTo(5)); Assert.That(limit.GetLimit(10), Is.EqualTo(5)); Assert.That(limit.GetLimit(20), Is.EqualTo(5)); } [Test()] public void TestNestedCompositeLimit() { XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit-nested.xml")); XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*"); WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser(); ILimit limit = parser.GetLimitFromElement(limitElem); Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit))); Assert.That(limit.GetLimit(1), Is.EqualTo(5)); Assert.That(limit.GetLimit(5), Is.EqualTo(5)); Assert.That(limit.GetLimit(10), Is.EqualTo(5)); } [Test()] [ExpectedException(typeof(InvalidFileException))] public void TestEmptyCompositeFailsValidation() { SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/empty-composite.xml")); } [Test()] public void TestAbsoluteLimit() { XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml")); XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*"); WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser(); ILimit limit = parser.GetLimitFromElement(limitElem); Assert.That(limit, Is.InstanceOfType(typeof(AbsoluteNumericLimit))); Assert.That(limit.GetLimit(1), Is.EqualTo(5)); Assert.That(limit.GetLimit(5), Is.EqualTo(5)); Assert.That(limit.GetLimit(10), Is.EqualTo(5)); } } }