comparison API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs @ 157:17c5030485dc

Re #351: Add extensible requirement handling method * Swap to using IRequirement, as per interface * Test registration of factories
author IBBoard <dev@ibboard.co.uk>
date Sat, 23 Jul 2011 19:54:37 +0000
parents 3725fd449c77
children c40cb2048fc3
comparison
equal deleted inserted replaced
156:ae2f1db8290c 157:17c5030485dc
43 { 43 {
44 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); 44 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
45 UnitType unitType = new UnitType("testUnit", "Test Unit", race); 45 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
46 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); 46 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
47 expectedReq.AddUnitTypeRequirement(unitType1); 47 expectedReq.AddUnitTypeRequirement(unitType1);
48 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory); 48 IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory);
49 Assert.That(req, Is.EqualTo(expectedReq)); 49 Assert.That(req, Is.EqualTo(expectedReq));
50 } 50 }
51 51
52 [Test()] 52 [Test()]
53 public void TestCreatesCorrectRequirementForTwoIDs() 53 public void TestCreatesCorrectRequirementForTwoIDs()
55 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); 55 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
56 UnitType unitType = new UnitType("testUnit", "Test Unit", race); 56 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
57 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); 57 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
58 expectedReq.AddUnitTypeRequirement(unitType1); 58 expectedReq.AddUnitTypeRequirement(unitType1);
59 expectedReq.AddUnitTypeRequirement(unitType2); 59 expectedReq.AddUnitTypeRequirement(unitType2);
60 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); 60 IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory);
61 Assert.That(req, Is.EqualTo(expectedReq)); 61 Assert.That(req, Is.EqualTo(expectedReq));
62 } 62 }
63 63
64 [Test()] 64 [Test()]
65 public void TestCreatesCorrectRequirementWithNumber() 65 public void TestCreatesCorrectRequirementWithNumber()
66 { 66 {
67 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); 67 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
68 UnitType unitType = new UnitType("testUnit", "Test Unit", race); 68 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
69 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); 69 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
70 expectedReq.AddUnitTypeRequirement(unitType1, 2); 70 expectedReq.AddUnitTypeRequirement(unitType1, 2);
71 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory); 71 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory);
72 Assert.That(req, Is.EqualTo(expectedReq)); 72 Assert.That(req, Is.EqualTo(expectedReq));
73 } 73 }
74 74
75 [Test()] 75 [Test()]
76 public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers() 76 public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
78 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); 78 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
79 UnitType unitType = new UnitType("testUnit", "Test Unit", race); 79 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
80 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); 80 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
81 expectedReq.AddUnitTypeRequirement(unitType1, 2); 81 expectedReq.AddUnitTypeRequirement(unitType1, 2);
82 expectedReq.AddUnitTypeRequirement(unitType2, 3); 82 expectedReq.AddUnitTypeRequirement(unitType2, 3);
83 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory); 83 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory);
84 Assert.That(req, Is.EqualTo(expectedReq)); 84 Assert.That(req, Is.EqualTo(expectedReq));
85 } 85 }
86 86
87 [Test()] 87 [Test()]
88 public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber() 88 public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
90 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); 90 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
91 UnitType unitType = new UnitType("testUnit", "Test Unit", race); 91 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
92 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); 92 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
93 expectedReq.AddUnitTypeRequirement(unitType1, 2); 93 expectedReq.AddUnitTypeRequirement(unitType1, 2);
94 expectedReq.AddUnitTypeRequirement(unitType2); 94 expectedReq.AddUnitTypeRequirement(unitType2);
95 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); 95 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory);
96 Assert.That(req, Is.EqualTo(expectedReq)); 96 Assert.That(req, Is.EqualTo(expectedReq));
97 } 97 }
98 98
99 [Test()] 99 [Test()]
100 public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber() 100 public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
102 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory(); 102 UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
103 UnitType unitType = new UnitType("testUnit", "Test Unit", race); 103 UnitType unitType = new UnitType("testUnit", "Test Unit", race);
104 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType); 104 UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
105 expectedReq.AddUnitTypeRequirement(unitType1); 105 expectedReq.AddUnitTypeRequirement(unitType1);
106 expectedReq.AddUnitTypeRequirement(unitType2, 3); 106 expectedReq.AddUnitTypeRequirement(unitType2, 3);
107 UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); 107 IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory);
108 Assert.That(req, Is.EqualTo(expectedReq)); 108 Assert.That(req, Is.EqualTo(expectedReq));
109 } 109 }
110 110
111 [Test()] 111 [Test()]
112 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires at least N units' requirement")] 112 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires at least N units' requirement")]