comparison API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs @ 111:f0b488c9f29b

Re #27: Define unit requirements * Rebuild and add unit test for "no more than N" requirement
author IBBoard <dev@ibboard.co.uk>
date Wed, 30 Mar 2011 19:07:33 +0000
parents
children a52cce66eb07
comparison
equal deleted inserted replaced
110:788ef54f5b5a 111:f0b488c9f29b
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 RequiresNoMoreThanNOfUnitTypeRequirementTest
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 RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
37 Assert.That(req.AllowsAdding(unit, army), Is.True);
38 }
39
40 [Test()]
41 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
42 {
43 Army army = new Army(mockRace, "Test", 1000);
44 AddUnitOfTypeToArmy(unitType2, army);
45 Unit unit = CreateUnitOfType(unitType1, army);
46 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
47 Assert.That(req.AllowsAdding(unit, army), Is.False);
48 }
49
50 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
51 {
52 army.AddUnit(CreateUnitOfType(unitType, army));
53 }
54
55 private static Unit CreateUnitOfType(UnitType unitType, Army army)
56 {
57 return new Unit(unitType, army.GetCategory(unitType.MainCategory));
58 }
59 }
60 }
61