54
|
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;
|
55
|
9 using IBBoard.IO;
|
54
|
10 namespace IBBoard.WarFoundry.API.Factories.Xml
|
|
11 {
|
|
12 [TestFixture()]
|
|
13 public class WarFoundryXmlLimitParserTest
|
|
14 {
|
|
15 [Test()]
|
55
|
16 public void TestCompositeMaxLimit()
|
54
|
17 {
|
55
|
18 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit.xml"));
|
54
|
19 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
|
|
20 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
|
|
21 ILimit limit = parser.GetLimitFromElement(limitElem);
|
|
22 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
|
|
23 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
|
|
24 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
|
|
25 Assert.That(limit.GetLimit(10), Is.EqualTo(10));
|
|
26 Assert.That(limit.GetLimit(20), Is.EqualTo(10));
|
|
27 }
|
|
28
|
|
29 [Test()]
|
55
|
30 public void TestCompositeMinLimit()
|
|
31 {
|
|
32 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-min-limit.xml"));
|
|
33 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
|
|
34 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
|
|
35 ILimit limit = parser.GetLimitFromElement(limitElem);
|
|
36 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMinimumLimit)));
|
|
37 Assert.That(limit.GetLimit(1), Is.EqualTo(1));
|
|
38 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
|
|
39 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
|
|
40 Assert.That(limit.GetLimit(20), Is.EqualTo(5));
|
|
41 }
|
|
42
|
|
43 [Test()]
|
|
44 public void TestNestedCompositeLimit()
|
|
45 {
|
|
46 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit-nested.xml"));
|
|
47 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
|
|
48 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
|
|
49 ILimit limit = parser.GetLimitFromElement(limitElem);
|
|
50 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
|
|
51 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
|
|
52 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
|
|
53 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
|
|
54 }
|
|
55
|
|
56 [Test()]
|
|
57 [ExpectedException(typeof(InvalidFileException))]
|
|
58 public void TestEmptyCompositeFailsValidation()
|
|
59 {
|
|
60 SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/empty-composite.xml"));
|
|
61 }
|
|
62
|
|
63 [Test()]
|
54
|
64 public void TestAbsoluteLimit()
|
|
65 {
|
|
66 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml"));
|
|
67 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
|
|
68 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
|
|
69 ILimit limit = parser.GetLimitFromElement(limitElem);
|
|
70 Assert.That(limit, Is.InstanceOfType(typeof(AbsoluteNumericLimit)));
|
|
71 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
|
|
72 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
|
|
73 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
|
|
74 }
|
|
75 }
|
|
76 }
|
|
77
|