120
|
1 // This file (RequiresNoMoreThanNOfUnitTypeRequirementTest.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
|
|
9 namespace IBBoard.WarFoundry.API.Objects.Requirement
|
|
10 {
|
|
11 [TestFixture()]
|
|
12 public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest
|
|
13 {
|
|
14 private MockRace mockRace;
|
|
15 private UnitType unitType1;
|
|
16 private UnitType unitType2;
|
|
17 private UnitType unitType3;
|
|
18
|
|
19 [TestFixtureSetUp()]
|
|
20 public void SetupRace()
|
|
21 {
|
|
22 mockRace = new MockRace();
|
|
23 unitType1 = new MockUnitType("type1", "Unit Type 1");
|
|
24 mockRace.AddUnitType(unitType1);
|
|
25 unitType2 = new MockUnitType("type2", "Unit Type 2");
|
|
26 mockRace.AddUnitType(unitType2);
|
|
27 unitType3 = new MockUnitType("type3", "Unit Type 3");
|
|
28 mockRace.AddUnitType(unitType3);
|
|
29 }
|
|
30
|
|
31 [Test()]
|
|
32 public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
|
|
33 {
|
|
34 Army army = new Army(mockRace, "Test", 1000);
|
|
35 Unit unit = CreateUnitOfType(unitType1, army);
|
|
36 RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
37 req.AddUnitTypeRequirement(unitType2);
|
|
38 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
|
|
39 }
|
|
40
|
|
41 [Test()]
|
|
42 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
|
|
43 {
|
|
44 Army army = new Army(mockRace, "Test", 1000);
|
|
45 AddUnitOfTypeToArmy(unitType2, army);
|
|
46 Unit unit = CreateUnitOfType(unitType1, army);
|
|
47 RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
48 req.AddUnitTypeRequirement(unitType2);
|
|
49 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
|
|
50 }
|
|
51
|
|
52 [Test()]
|
|
53 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
|
|
54 {
|
|
55 Army army = new Army(mockRace, "Test", 1000);
|
|
56 RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
57 req.AddUnitTypeRequirement(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 UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
67 req.AddUnitTypeRequirement(unitType2);
|
|
68 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
|
|
69 }
|
|
70
|
|
71 [Test()]
|
|
72 public void TestAddingUnitTypeSetsLimit()
|
|
73 {
|
|
74 Army army = new Army(mockRace, "Test", 1000);
|
|
75 AddUnitOfTypeToArmy(unitType2, army);
|
|
76 RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
77 req.AddUnitTypeRequirement(unitType2, 1);
|
|
78 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
|
|
79 }
|
|
80
|
|
81 [Test()]
|
|
82 public void TestAddingUnitTypeSetsLimitForFailure()
|
|
83 {
|
|
84 Army army = new Army(mockRace, "Test", 1000);
|
|
85 AddUnitOfTypeToArmy(unitType2, army);
|
|
86 AddUnitOfTypeToArmy(unitType2, army);
|
|
87 RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
88 req.AddUnitTypeRequirement(unitType2, 1);
|
|
89 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
|
|
90 }
|
|
91
|
|
92 [Test()]
|
|
93 public void TestAddingUnitTypeDefaultsToNoMoreThanZero()
|
|
94 {
|
|
95 Army army = new Army(mockRace, "Test", 1000);
|
|
96 AddUnitOfTypeToArmy(unitType2, army);
|
|
97 RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
|
|
98 req.AddUnitTypeRequirement(unitType2);
|
|
99 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
|
|
100 }
|
|
101
|
|
102 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
|
|
103 {
|
|
104 army.AddUnit(CreateUnitOfType(unitType, army));
|
|
105 }
|
|
106
|
|
107 private static Unit CreateUnitOfType(UnitType unitType, Army army)
|
|
108 {
|
|
109 return new Unit(unitType, army.GetCategory(unitType.MainCategory));
|
|
110 }
|
|
111 }
|
|
112 }
|
|
113
|