Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 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 | c6313a2c08a2 |
children | d8cd6b259a9f |
files | API/Objects/ArmyCategoryTests.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 2 files changed, 78 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/ArmyCategoryTests.cs Sun Apr 15 20:53:15 2012 +0100 @@ -0,0 +1,77 @@ +// This file (ArmyCategoryTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard +// +// 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. +using System; +using NUnit.Framework; +using IBBoard.WarFoundry.API.Objects.Mock; +using IBBoard.WarFoundry.API.Objects.Requirement; +using IBBoard.WarFoundry.API.Objects.Requirement.Mock; +using NUnit.Framework.SyntaxHelpers; + + +namespace IBBoard.WarFoundry.API.Objects +{ + [TestFixture()] + public class ArmyCategoryTests + { + private MockRace mockRace; + private UnitType unitType1; + private IRequirement unitType1Requirement; + private UnitType unitType2; + private IRequirement unitType2Requirement; + private UnitType unitType3; + private IRequirement unitType3Requirement; + private UnitType containedType; + + [TestFixtureSetUp()] + public void SetupRace() + { + mockRace = new MockRace(); + unitType1 = new MockUnitType("type1", "Unit Type 1"); + mockRace.AddUnitType(unitType1); + unitType1Requirement = new PassingRequirement(); + unitType1.AddRequirement(unitType1Requirement); + unitType2 = new MockUnitType("type2", "Unit Type 2"); + mockRace.AddUnitType(unitType2); + unitType2Requirement = new FailingRequirement(); + unitType2.AddRequirement(unitType2Requirement); + unitType3 = new MockUnitType("type3", "Unit Type 3"); + mockRace.AddUnitType(unitType3); + unitType3Requirement = new NotApplicableRequirement(); + unitType3.AddRequirement(unitType3Requirement); + containedType = new MockContainedUnitType(); + unitType1.AddContainedUnitType(containedType); + mockRace.AddUnitType(containedType); + } + + [Test()] + public void TestGetUnitsGetsAllUnitsIncludingContained() + { + Army army = new Army(mockRace, "Test", 1000); + Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory)); + army.AddUnit(unit1); + Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory)); + army.AddUnit(unit2); + unit1.AddContainedUnit(unit2); + ArmyCategory category = army.GetCategory(MockCategory.GetCategory()); + Assert.That(category.GetUnits(), Has.Length(2)); + Assert.That(category.GetUnits(), Has.Member(unit1)); + Assert.That(category.GetUnits(), Has.Member(unit2)); + } + + [Test()] + public void TestGetMainUnitsGetsNoContainedUnits() + { + Army army = new Army(mockRace, "Test", 1000); + Unit unit1 = new Unit(unitType1, army.GetCategory(unitType1.MainCategory)); + army.AddUnit(unit1); + Unit unit2 = new Unit(containedType, army.GetCategory(containedType.MainCategory)); + army.AddUnit(unit2); + unit1.AddContainedUnit(unit2); + ArmyCategory category = army.GetCategory(MockCategory.GetCategory()); + Assert.That(category.GetMainUnits(), Has.Length(1)); + Assert.That(category.GetMainUnits(), Has.Member(unit1)); + } + } +} +
--- a/IBBoard.WarFoundry.API.Tests.csproj Sat Apr 14 19:57:32 2012 +0100 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sun Apr 15 20:53:15 2012 +0100 @@ -122,6 +122,7 @@ <Compile Include="API\Objects\Requirement\AbstractUnitTypeUnitRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\AbstractRaceUnitRequirementTest.cs" /> <Compile Include="API\Objects\Mock\MockContainedUnitType.cs" /> + <Compile Include="API\Objects\ArmyCategoryTests.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />