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