comparison API/Factories/Xml/WarFoundryXmlLimitParserTest.cs @ 54:084049c8dff4

Re #279: Create composite limit * Add first tests for limit parser - composites are parsed, but children aren't picked up by XPath query yet
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Jun 2010 15:37:03 +0000
parents
children 7f9e1fef069e
comparison
equal deleted inserted replaced
53:f6bbd77b5473 54:084049c8dff4
1 // This file (WarFoundryXmlLimitParserTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
2 //
3 // // 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.
4 using System.IO;
5 using System.Xml;
6 using NUnit.Framework;
7 using IBBoard.Limits;
8 using NUnit.Framework.SyntaxHelpers;
9 namespace IBBoard.WarFoundry.API.Factories.Xml
10 {
11 [TestFixture()]
12 public class WarFoundryXmlLimitParserTest
13 {
14 [Test()]
15 public void TestCompositeLimit()
16 {
17 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-limit.xml"));
18 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
19 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
20 ILimit limit = parser.GetLimitFromElement(limitElem);
21 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
22 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
23 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
24 Assert.That(limit.GetLimit(10), Is.EqualTo(10));
25 Assert.That(limit.GetLimit(20), Is.EqualTo(10));
26 }
27
28 [Test()]
29 public void TestAbsoluteLimit()
30 {
31 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml"));
32 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
33 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
34 ILimit limit = parser.GetLimitFromElement(limitElem);
35 Assert.That(limit, Is.InstanceOfType(typeof(AbsoluteNumericLimit)));
36 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
37 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
38 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
39 }
40 }
41 }
42