view API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs @ 152:dd283afa5971

Re #351: Add extensible requirement handling method * Add first test for failed loading
author IBBoard <dev@ibboard.co.uk>
date Sat, 02 Jul 2011 15:00:16 +0000
parents 60de02ce78d8
children e84149f37478
line source
1 // This file (UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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;
5 using NUnit.Framework;
6 using IBBoard.WarFoundry.API.Objects.Mock;
7 using NUnit.Framework.SyntaxHelpers;
8 using IBBoard.WarFoundry.API.Objects;
9 using IBBoard.WarFoundry.API.Objects.Requirement;
11 namespace IBBoard.WarFoundry.API.Factories.Requirement
12 {
13 [TestFixture()]
14 public class UnitRequiresAtLeastNUnitsRequirementFactoryTest
15 {
16 private static Race race;
17 private static string typeID1 = "unit1";
18 private static string typeID2 = "unit2";
19 private UnitType unitType1;
20 private UnitType unitType2;
22 [TestFixtureSetUp()]
23 public void Setup()
24 {
25 race = new MockRace();
26 unitType1 = new UnitType(typeID1, "Unit 1", race);
27 race.AddUnitType(unitType1);
28 unitType2 = new UnitType(typeID2, "Unit 2", race);
29 race.AddUnitType(unitType2);
30 }
32 [Test()]
33 public void TestCreatesRequirement()
34 {
35 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
36 Assert.That(factory.CreateRequirement(unitType2, typeID1), Is.Not.Null);
37 }
39 [Test()]
40 public void TestCreatesCorrectRequirement()
41 {
42 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
43 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
44 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
45 expectedReq.AddUnitTypeRequirement(unitType1);
46 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1);
47 Assert.That(req, Is.EqualTo(expectedReq));
48 }
50 [Test()]
51 public void TestCreatesCorrectRequirementForTwoIDs()
52 {
53 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
54 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
55 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
56 expectedReq.AddUnitTypeRequirement(unitType1);
57 expectedReq.AddUnitTypeRequirement(unitType2);
58 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2);
59 Assert.That(req, Is.EqualTo(expectedReq));
60 }
62 [Test()]
63 public void TestCreatesCorrectRequirementWithNumber()
64 {
65 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
66 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
67 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
68 expectedReq.AddUnitTypeRequirement(unitType1, 2);
69 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2");
70 Assert.That(req, Is.EqualTo(expectedReq));
71 }
73 [Test()]
74 public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
75 {
76 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
77 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
78 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
79 expectedReq.AddUnitTypeRequirement(unitType1, 2);
80 expectedReq.AddUnitTypeRequirement(unitType2, 3);
81 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3");
82 Assert.That(req, Is.EqualTo(expectedReq));
83 }
85 [Test()]
86 public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
87 {
88 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
89 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
90 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
91 expectedReq.AddUnitTypeRequirement(unitType1, 2);
92 expectedReq.AddUnitTypeRequirement(unitType2);
93 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2);
94 Assert.That(req, Is.EqualTo(expectedReq));
95 }
97 [Test()]
98 public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
99 {
100 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
101 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
102 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
103 expectedReq.AddUnitTypeRequirement(unitType1);
104 expectedReq.AddUnitTypeRequirement(unitType2, 3);
105 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3");
106 Assert.That(req, Is.EqualTo(expectedReq));
107 }
109 [Test()]
110 [ExpectedException()]
111 public void TestCreatesCorrectRequirementForInvalidID()
112 {
113 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
114 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
115 factory.CreateRequirement(unitType, "fibble");
116 }
117 }
118 }