annotate API/Factories/Xml/WarFoundryXmlLimitParserTest.cs @ 197:aa921248ffbf

Re #350: Add requirement to allow N of unit for specific other units * Add initial unit tests for handling multiple additive unit types
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Dec 2011 21:02:13 +0000
parents 7f9e1fef069e
children e173c5512067
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (WarFoundryXmlLimitParserTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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.
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System.IO;
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System.Xml;
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using NUnit.Framework;
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Limits;
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using NUnit.Framework.SyntaxHelpers;
55
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
9 using IBBoard.IO;
54
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API.Factories.Xml
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 {
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 [TestFixture()]
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 public class WarFoundryXmlLimitParserTest
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 [Test()]
55
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
16 public void TestCompositeMaxLimit()
54
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
55
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
18 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit.xml"));
54
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 ILimit limit = parser.GetLimitFromElement(limitElem);
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 Assert.That(limit.GetLimit(10), Is.EqualTo(10));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 Assert.That(limit.GetLimit(20), Is.EqualTo(10));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 [Test()]
55
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
30 public void TestCompositeMinLimit()
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
31 {
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
32 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-min-limit.xml"));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
33 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
34 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
35 ILimit limit = parser.GetLimitFromElement(limitElem);
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
36 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMinimumLimit)));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
37 Assert.That(limit.GetLimit(1), Is.EqualTo(1));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
38 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
39 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
40 Assert.That(limit.GetLimit(20), Is.EqualTo(5));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
41 }
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
42
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
43 [Test()]
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
44 public void TestNestedCompositeLimit()
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
45 {
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
46 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit-nested.xml"));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
47 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
48 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
49 ILimit limit = parser.GetLimitFromElement(limitElem);
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
50 Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
51 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
52 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
53 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
54 }
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
55
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
56 [Test()]
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
57 [ExpectedException(typeof(InvalidFileException))]
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
58 public void TestEmptyCompositeFailsValidation()
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
59 {
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
60 SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/empty-composite.xml"));
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
61 }
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
62
7f9e1fef069e Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents: 54
diff changeset
63 [Test()]
54
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 public void TestAbsoluteLimit()
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 {
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml"));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 ILimit limit = parser.GetLimitFromElement(limitElem);
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 Assert.That(limit, Is.InstanceOfType(typeof(AbsoluteNumericLimit)));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 Assert.That(limit.GetLimit(1), Is.EqualTo(5));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 Assert.That(limit.GetLimit(5), Is.EqualTo(5));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 Assert.That(limit.GetLimit(10), Is.EqualTo(5));
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 }
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 }
084049c8dff4 Re #279: Create composite limit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77