Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs @ 188:0762766bd3f2
Re #350: Add requirement to allow N of unit for specific other units
* Remove static access to mock race - it broke tests
* Add first tests for new requirement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 29 Nov 2011 20:56:34 +0000 |
parents | |
children | eea440e5891b |
comparison
equal
deleted
inserted
replaced
187:cd2aeab2357f | 188:0762766bd3f2 |
---|---|
1 // This file (UnitRequiresNUnitsForMUnitsRequirement.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 System.Reflection; | |
9 using IBBoard.NUnit; | |
10 using IBBoard.WarFoundry.API.Factories; | |
11 | |
12 namespace IBBoard.WarFoundry.API.Objects.Requirement | |
13 { | |
14 [TestFixture()] | |
15 public class RequiresNUnitsForMUnitsRequirementTest : AbstractEqualityTest<RequiresNUnitsForMUnitsRequirement> | |
16 { | |
17 private MockRace mockRace; | |
18 private UnitType unitType1; | |
19 private UnitType unitType2; | |
20 private UnitType unitType3; | |
21 | |
22 [TestFixtureSetUp()] | |
23 public void SetupRace() | |
24 { | |
25 mockRace = MockRace.GetMockRace(); | |
26 unitType1 = new MockUnitType("type1", "Unit Type 1"); | |
27 mockRace.AddUnitType(unitType1); | |
28 unitType2 = new MockUnitType("type2", "Unit Type 2"); | |
29 mockRace.AddUnitType(unitType2); | |
30 unitType3 = new MockUnitType("type3", "Unit Type 3"); | |
31 mockRace.AddUnitType(unitType3); | |
32 } | |
33 | |
34 [Test()] | |
35 public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequiredIsNA() | |
36 { | |
37 Army army = new Army(mockRace, "Test", 1000); | |
38 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
39 Unit unit = CreateUnitOfType(unitType3, army); | |
40 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); | |
41 } | |
42 | |
43 [Test()] | |
44 public void TestAddingOneUnitWithOneUnitTypeRequiredAndOneUnitOfTypePasses() | |
45 { | |
46 Army army = new Army(mockRace, "Test", 1000); | |
47 AddUnitOfTypeToArmy(unitType2, army); | |
48 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
49 Unit unit = CreateUnitOfType(unitType1, army); | |
50 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
51 } | |
52 | |
53 [Test()] | |
54 public void TestAddingOneUnitWithOneUnitTypeRequiredAndNoUnitOfTypeFails() | |
55 { | |
56 Army army = new Army(mockRace, "Test", 1000); | |
57 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
58 Unit unit = CreateUnitOfType(unitType1, army); | |
59 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
60 } | |
61 | |
62 [Test()] | |
63 public void TestAddingTwoUnitsWithOneUnitTypeRequiredAndOneUnitOfTypeFails() | |
64 { | |
65 Army army = new Army(mockRace, "Test", 1000); | |
66 AddUnitOfTypeToArmy(unitType2, army); | |
67 AddUnitOfTypeToArmy(unitType1, army); | |
68 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); | |
69 Unit unit = CreateUnitOfType(unitType1, army); | |
70 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
71 } | |
72 | |
73 [Test()] | |
74 public void TestAddingTwoUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses() | |
75 { | |
76 Army army = new Army(mockRace, "Test", 1000); | |
77 AddUnitOfTypeToArmy(unitType2, army); | |
78 AddUnitOfTypeToArmy(unitType1, army); | |
79 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
80 req.AddUnitTypeRequirement(unitType2, 1, 2); | |
81 Unit unit = CreateUnitOfType(unitType1, army); | |
82 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
83 } | |
84 | |
85 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) | |
86 { | |
87 army.AddUnit(CreateUnitOfType(unitType, army)); | |
88 } | |
89 | |
90 private static Unit CreateUnitOfType(UnitType unitType, Army army) | |
91 { | |
92 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); | |
93 } | |
94 | |
95 public override RequiresNUnitsForMUnitsRequirement GetObject() | |
96 { | |
97 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3); | |
98 req.AddUnitTypeRequirement(unitType1, 2, 3); | |
99 return req; | |
100 } | |
101 | |
102 public override RequiresNUnitsForMUnitsRequirement GetSameObject() | |
103 { | |
104 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3); | |
105 req.AddUnitTypeRequirement(unitType1, 2, 3); | |
106 return req; | |
107 } | |
108 | |
109 public override RequiresNUnitsForMUnitsRequirement GetDifferentObject() | |
110 { | |
111 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3); | |
112 DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); | |
113 GameSystem gameSystem = new GameSystem("system", "system", factory); | |
114 Race race = new Race("race", "race", gameSystem, factory); | |
115 req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2, 3); | |
116 return req; | |
117 } | |
118 } | |
119 } | |
120 |