139
|
1 // This file (RequiresNoMoreThanNOfUnitTypeRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
|
111
|
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;
|
139
|
5 using NUnit.Framework;
|
|
6 using IBBoard.WarFoundry.API.Objects.Mock;
|
111
|
7 using NUnit.Framework.SyntaxHelpers;
|
139
|
8 using System.Reflection;
|
|
9 using IBBoard.NUnit;
|
|
10 using IBBoard.WarFoundry.API.Factories;
|
111
|
11
|
|
12 namespace IBBoard.WarFoundry.API.Objects.Requirement
|
|
13 {
|
|
14 [TestFixture()]
|
139
|
15 public class RequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractEqualityTest<RequiresNoMoreThanNOfUnitTypeRequirement>
|
|
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 = new MockRace();
|
|
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 TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
|
|
36 {
|
|
37 Army army = new Army(mockRace, "Test", 1000);
|
|
38 Unit unit = CreateUnitOfType(unitType1, army);
|
|
39 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
|
|
40 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
|
|
41 }
|
|
42
|
|
43 [Test()]
|
|
44 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
|
|
45 {
|
|
46 Army army = new Army(mockRace, "Test", 1000);
|
|
47 AddUnitOfTypeToArmy(unitType2, army);
|
|
48 Unit unit = CreateUnitOfType(unitType1, army);
|
|
49 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
|
|
50 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
|
|
51 }
|
|
52
|
|
53 [Test()]
|
|
54 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
|
|
55 {
|
|
56 Army army = new Army(mockRace, "Test", 1000);
|
|
57 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
|
|
58 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
|
|
59 }
|
|
60
|
|
61 [Test()]
|
|
62 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
|
|
63 {
|
|
64 Army army = new Army(mockRace, "Test", 1000);
|
|
65 AddUnitOfTypeToArmy(unitType2, army);
|
|
66 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
|
|
67 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
|
|
68 }
|
|
69
|
|
70 [Test()]
|
|
71 public void TestAddingUnitTypeSetsLimit()
|
|
72 {
|
|
73 Army army = new Army(mockRace, "Test", 1000);
|
|
74 AddUnitOfTypeToArmy(unitType2, army);
|
|
75 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
76 req.AddUnitTypeRequirement(unitType2, 1);
|
|
77 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
|
|
78 }
|
|
79
|
|
80 [Test()]
|
|
81 public void TestAddingUnitTypeSetsLimitForFailure()
|
|
82 {
|
|
83 Army army = new Army(mockRace, "Test", 1000);
|
|
84 AddUnitOfTypeToArmy(unitType2, army);
|
|
85 AddUnitOfTypeToArmy(unitType2, army);
|
|
86 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
87 req.AddUnitTypeRequirement(unitType2, 1);
|
|
88 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
|
|
89 }
|
|
90
|
|
91 [Test()]
|
|
92 public void TestAddingUnitTypeDefaultsToNoMoreThanZero()
|
|
93 {
|
|
94 Army army = new Army(mockRace, "Test", 1000);
|
|
95 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
96 req.AddUnitTypeRequirement(unitType2);
|
|
97 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
|
|
98 AddUnitOfTypeToArmy(unitType2, army);
|
|
99 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
|
|
100 }
|
|
101
|
|
102 [Test]
|
|
103 public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange()
|
|
104 {
|
|
105 Army army = new Army(mockRace, "Test", 1000);
|
|
106 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
107 req.AddUnitTypeRequirement(unitType2);
|
|
108 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
|
|
109 AddUnitOfTypeToArmy(unitType2, army);
|
|
110 Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
|
|
111 }
|
|
112
|
|
113 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
|
|
114 {
|
|
115 army.AddUnit(CreateUnitOfType(unitType, army));
|
|
116 }
|
|
117
|
|
118 private static Unit CreateUnitOfType(UnitType unitType, Army army)
|
|
119 {
|
|
120 return new Unit(unitType, army.GetCategory(unitType.MainCategory));
|
|
121 }
|
|
122
|
|
123 public override RequiresNoMoreThanNOfUnitTypeRequirement GetObject ()
|
|
124 {
|
|
125 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
126 req.AddUnitTypeRequirement(unitType1, 2);
|
|
127 return req;
|
|
128 }
|
|
129
|
|
130 public override RequiresNoMoreThanNOfUnitTypeRequirement GetSameObject ()
|
|
131 {
|
|
132 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
133 req.AddUnitTypeRequirement(unitType1, 2);
|
|
134 return req;
|
|
135 }
|
|
136
|
|
137 public override RequiresNoMoreThanNOfUnitTypeRequirement GetDifferentObject ()
|
|
138 {
|
|
139 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement();
|
|
140 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
|
|
141 GameSystem gameSystem = new GameSystem("system", "system", factory);
|
|
142 Race race = new Race("race", "race", gameSystem, factory);
|
|
143 req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2);
|
|
144 return req;
|
111
|
145 }
|
|
146 }
|
|
147 }
|
|
148
|