changeset 129:95dac00e9330

Re #27: Unit requirements * Test getting all unit requirements for race
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Apr 2011 19:13:42 +0000
parents 7ca536ccd27a
children 7fa4d5215afe
files API/Objects/RaceTests.cs
diffstat 1 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/RaceTests.cs	Sat Apr 09 15:59:55 2011 +0000
+++ b/API/Objects/RaceTests.cs	Sat Apr 09 19:13:42 2011 +0000
@@ -4,7 +4,9 @@
 using System;
 using NUnit.Framework;
 using IBBoard.WarFoundry.API.Objects.Mock;
-using NUnit.Framework.SyntaxHelpers;
+using NUnit.Framework.SyntaxHelpers;
+using IBBoard.WarFoundry.API.Objects.Requirement;
+using System.Collections.Generic;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
@@ -15,6 +17,48 @@
 		public void TestRaceWithNoUnitTypesHasNoRequirements()
 		{
 			Assert.That(new MockRace().GetRequirements(), Has.Count(0));
+		}
+
+		[Test()]
+		public void TestRaceWithOneUnitTypeHasNoRequirements()
+		{
+			MockRace race = new MockRace();
+			race.AddUnitType(new MockUnitType());
+			Assert.That(race.GetRequirements(), Has.Count(0));
+		}
+
+		[Test()]
+		public void TestRaceWithOneUnitTypeWithOneRequirementHasOneRequirement()
+		{
+			MockRace race = new MockRace();
+			MockUnitType unitType = new MockUnitType();
+			UnitRequiresAtLeastNUnitsRequirement unitRequirement = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			unitType.AddRequirement(unitRequirement);
+			race.AddUnitType(unitType);
+			ICollection<IRequirement> raceRequirements = race.GetRequirements();
+			Assert.That(raceRequirements, Has.Count(1));
+			Assert.That(raceRequirements, Has.All.EqualTo(unitRequirement));
+		}
+
+		[Test()]
+		public void TestRaceWithTwoUnitTypesWithMultipleRequirementsHasMultipleRequirements()
+		{
+			MockRace race = new MockRace();
+			MockUnitType unitType1 = new MockUnitType("type1", "Type 1");
+			UnitRequiresAtLeastNUnitsRequirement unitRequirement1 = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			unitType1.AddRequirement(unitRequirement1);
+			UnitRequiresNoMoreThanNOfUnitTypeRequirement unitRequirement2 = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			unitType1.AddRequirement(unitRequirement2);
+			race.AddUnitType(unitType1);
+			MockUnitType unitType2 = new MockUnitType("type2", "Type 2");
+			UnitRequiresAtLeastNUnitsRequirement unitRequirement3 = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
+			unitType2.AddRequirement(unitRequirement3);
+			race.AddUnitType(unitType2);
+			ICollection<IRequirement> raceRequirements = race.GetRequirements();
+			Assert.That(raceRequirements, Has.Count(3));
+			Assert.That(raceRequirements, Has.Member(unitRequirement1));
+			Assert.That(raceRequirements, Has.Member(unitRequirement2));
+			Assert.That(raceRequirements, Has.Member(unitRequirement3));
 		}
 	}
 }