changeset 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 788ef54f5b5a
children 53cfd5b3d1bd
files API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Wed Mar 30 19:07:33 2011 +0000
@@ -0,0 +1,61 @@
+// This file (RequiresNoMoreThanNOfUnitTypeRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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 NUnit.Framework.SyntaxHelpers;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement
+{
+	[TestFixture()]
+	public class RequiresNoMoreThanNOfUnitTypeRequirementTest
+	{
+		private MockRace mockRace;
+		private UnitType unitType1;
+		private UnitType unitType2;
+		private UnitType unitType3;
+
+		[TestFixtureSetUp()]
+		public void SetupRace()
+		{
+			mockRace = new MockRace();
+			unitType1 = new MockUnitType("type1", "Unit Type 1");
+			mockRace.AddUnitType(unitType1);
+			unitType2 = new MockUnitType("type2", "Unit Type 2");
+			mockRace.AddUnitType(unitType2);
+			unitType3 = new MockUnitType("type3", "Unit Type 3");
+			mockRace.AddUnitType(unitType3);
+		}
+
+		[Test()]
+		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unit, army), Is.True);
+		}
+
+		[Test()]
+		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unit, army), Is.False);
+		}
+
+		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
+		{
+			army.AddUnit(CreateUnitOfType(unitType, army));
+		}
+
+		private static Unit CreateUnitOfType(UnitType unitType, Army army)
+		{
+			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Tue Mar 29 19:51:08 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Wed Mar 30 19:07:33 2011 +0000
@@ -92,6 +92,7 @@
     <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
     <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" />
+    <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />