view API/Objects/ArmyCategoryTests.cs @ 226:763ce93f1bfb

Re #359: Add "only contained" attribute to unit types * Add tests for "main units" methods not getting nested units
author IBBoard <dev@ibboard.co.uk>
date Sun, 15 Apr 2012 20:53:15 +0100
parents
children
line source
1 // This file (ArmyCategoryTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 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 IBBoard.WarFoundry.API.Objects.Requirement;
8 using IBBoard.WarFoundry.API.Objects.Requirement.Mock;
9 using NUnit.Framework.SyntaxHelpers;
12 namespace IBBoard.WarFoundry.API.Objects
13 {
14 [TestFixture()]
15 public class ArmyCategoryTests
16 {
17 private MockRace mockRace;
18 private UnitType unitType1;
19 private IRequirement unitType1Requirement;
20 private UnitType unitType2;
21 private IRequirement unitType2Requirement;
22 private UnitType unitType3;
23 private IRequirement unitType3Requirement;
24 private UnitType containedType;
26 [TestFixtureSetUp()]
27 public void SetupRace()
28 {
29 mockRace = new MockRace();
30 unitType1 = new MockUnitType("type1", "Unit Type 1");
31 mockRace.AddUnitType(unitType1);
32 unitType1Requirement = new PassingRequirement();
33 unitType1.AddRequirement(unitType1Requirement);
34 unitType2 = new MockUnitType("type2", "Unit Type 2");
35 mockRace.AddUnitType(unitType2);
36 unitType2Requirement = new FailingRequirement();
37 unitType2.AddRequirement(unitType2Requirement);
38 unitType3 = new MockUnitType("type3", "Unit Type 3");
39 mockRace.AddUnitType(unitType3);
40 unitType3Requirement = new NotApplicableRequirement();
41 unitType3.AddRequirement(unitType3Requirement);
42 containedType = new MockContainedUnitType();
43 unitType1.AddContainedUnitType(containedType);
44 mockRace.AddUnitType(containedType);
45 }
47 [Test()]
48 public void TestGetUnitsGetsAllUnitsIncludingContained()
49 {
50 Army army = new Army(mockRace, "Test", 1000);
51 Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
52 army.AddUnit(unit1);
53 Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory));
54 army.AddUnit(unit2);
55 unit1.AddContainedUnit(unit2);
56 ArmyCategory category = army.GetCategory(MockCategory.GetCategory());
57 Assert.That(category.GetUnits(), Has.Length(2));
58 Assert.That(category.GetUnits(), Has.Member(unit1));
59 Assert.That(category.GetUnits(), Has.Member(unit2));
60 }
62 [Test()]
63 public void TestGetMainUnitsGetsNoContainedUnits()
64 {
65 Army army = new Army(mockRace, "Test", 1000);
66 Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
67 army.AddUnit(unit1);
68 Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory));
69 army.AddUnit(unit2);
70 unit1.AddContainedUnit(unit2);
71 ArmyCategory category = army.GetCategory(MockCategory.GetCategory());
72 Assert.That(category.GetMainUnits(), Has.Length(1));
73 Assert.That(category.GetMainUnits(), Has.Member(unit1));
74 }
75 }
76 }