changeset 102:a3bc8174299f

Re #27: Define unit requirements * First test for first new style requirement * Update some of the Mock objects to add a few more required elements (mainly Category)
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Mar 2011 17:04:09 +0000
parents 08fd75eafb67
children c6562eb62d04
files API/Objects/Mock/MockCategory.cs API/Objects/Mock/MockRace.cs API/Objects/Mock/MockUnitType.cs API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/UnitTypeTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 6 files changed, 55 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Mock/MockCategory.cs	Sat Mar 12 20:16:30 2011 +0000
+++ b/API/Objects/Mock/MockCategory.cs	Sat Mar 26 17:04:09 2011 +0000
@@ -8,7 +8,19 @@
 {
 	public class MockCategory : Category
 	{
-		public MockCategory () : base("mockcat", "Mock Category")
+		private static MockCategory cat;
+
+		public static MockCategory GetCategory()
+		{
+			if (cat == null)
+			{
+				cat = new MockCategory();
+			}
+
+			return cat;
+		}
+
+		private MockCategory () : base("mockcat", "Mock Category")
 		{
 		}
 	}
--- a/API/Objects/Mock/MockRace.cs	Sat Mar 12 20:16:30 2011 +0000
+++ b/API/Objects/Mock/MockRace.cs	Sat Mar 26 17:04:09 2011 +0000
@@ -24,6 +24,7 @@
 		
 		public MockRace () : base("mockrace", "Mock Race", MockGameSystem.GetMockSystem(), MockSystemFactory.GetMockFactory())
 		{
+			AddCategory(MockCategory.GetCategory());
 		}
 	}
 }
--- a/API/Objects/Mock/MockUnitType.cs	Sat Mar 12 20:16:30 2011 +0000
+++ b/API/Objects/Mock/MockUnitType.cs	Sat Mar 26 17:04:09 2011 +0000
@@ -9,9 +9,13 @@
 {
 	public class MockUnitType : UnitType
 	{
-		public MockUnitType () : base("mockunittype", "Mock Unit Type", MockRace.GetMockRace())
+		public MockUnitType () : this("mockunittype", "Mock Unit Type")
 		{
-			MainCategory = new MockCategory();
+		}
+
+		public MockUnitType(string id, string name) : base(id, name, MockRace.GetMockRace())
+		{
+			MainCategory = MockCategory.GetCategory();
 		}
 	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Mar 26 17:04:09 2011 +0000
@@ -0,0 +1,29 @@
+// This file (UnitRequiresAtLeastNUnitsRequirement.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.Requirements
+{
+	[TestFixture()]
+	public class UnitRequiresAtLeastNUnitsRequirementTest
+	{
+		[Test()]
+		public void TestWithNoUnits()
+		{
+			MockRace mockRace = MockRace.GetMockRace();
+			UnitType unitType1 = new MockUnitType("type1", "Unit Type 1");
+			mockRace.AddUnitType(unitType1);
+			UnitType unitType2 = new MockUnitType("type2", "Unit Type 2");
+			mockRace.AddUnitType(unitType2);
+			Army army = new Army(mockRace, "Test", 1000);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1, unitType2);
+			Unit unit = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
+			Assert.That(req.CanAddToArmy(unit, army), Is.False);
+		}
+	}
+}
+
--- a/API/Objects/UnitTypeTest.cs	Sat Mar 12 20:16:30 2011 +0000
+++ b/API/Objects/UnitTypeTest.cs	Sat Mar 26 17:04:09 2011 +0000
@@ -15,7 +15,7 @@
 		public void TestSettingMainCategorySetsCategoriesCollection()
 		{
 			UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
-			MockCategory mockCategory = new MockCategory();
+			MockCategory mockCategory = MockCategory.GetCategory();
 			unitType.MainCategory = mockCategory;
 			Assert.That(unitType.Categories, Has.Member(mockCategory));
 		}
@@ -24,7 +24,7 @@
 		public void TestAddingFirstCategorySetsMainCategory()
 		{
 			UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
-			MockCategory mockCategory = new MockCategory();
+			MockCategory mockCategory = MockCategory.GetCategory();
 			unitType.AddCategory(mockCategory);
 			Assert.That(unitType.Categories.Length, Is.EqualTo(1));
 			Assert.That(unitType.Categories, Has.Member(mockCategory));
@@ -35,7 +35,7 @@
 		public void TestAddingMultipleCategoriesSetsMainCategory()
 		{
 			UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
-			MockCategory mockCategory = new MockCategory();
+			MockCategory mockCategory = MockCategory.GetCategory();
 			unitType.AddCategory(mockCategory);
 			Category mockCategory2 = new Category("id1", "CatName");
 			unitType.AddCategory(mockCategory2);
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Mar 12 20:16:30 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Mar 26 17:04:09 2011 +0000
@@ -91,7 +91,7 @@
     <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" />
     <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
-    <Compile Include="API\Savers\Xml\WarFoundryXmlFileSaverTests.cs" />
+    <Compile Include="API\Objects\Requirements\UnitRequiresAtLeastNUnitsRequirementTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -342,5 +342,7 @@
     <Folder Include="testdata\multifile-zips\" />
     <Folder Include="API\Savers\" />
     <Folder Include="API\Savers\Xml\" />
+    <Folder Include="API\" />
+    <Folder Include="API\Objects\Requirements\" />
   </ItemGroup>
 </Project>
\ No newline at end of file