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 diff
     1.1 --- a/API/Objects/Mock/MockCategory.cs	Sat Mar 12 20:16:30 2011 +0000
     1.2 +++ b/API/Objects/Mock/MockCategory.cs	Sat Mar 26 17:04:09 2011 +0000
     1.3 @@ -8,7 +8,19 @@
     1.4  {
     1.5  	public class MockCategory : Category
     1.6  	{
     1.7 -		public MockCategory () : base("mockcat", "Mock Category")
     1.8 +		private static MockCategory cat;
     1.9 +
    1.10 +		public static MockCategory GetCategory()
    1.11 +		{
    1.12 +			if (cat == null)
    1.13 +			{
    1.14 +				cat = new MockCategory();
    1.15 +			}
    1.16 +
    1.17 +			return cat;
    1.18 +		}
    1.19 +
    1.20 +		private MockCategory () : base("mockcat", "Mock Category")
    1.21  		{
    1.22  		}
    1.23  	}
     2.1 --- a/API/Objects/Mock/MockRace.cs	Sat Mar 12 20:16:30 2011 +0000
     2.2 +++ b/API/Objects/Mock/MockRace.cs	Sat Mar 26 17:04:09 2011 +0000
     2.3 @@ -24,6 +24,7 @@
     2.4  		
     2.5  		public MockRace () : base("mockrace", "Mock Race", MockGameSystem.GetMockSystem(), MockSystemFactory.GetMockFactory())
     2.6  		{
     2.7 +			AddCategory(MockCategory.GetCategory());
     2.8  		}
     2.9  	}
    2.10  }
     3.1 --- a/API/Objects/Mock/MockUnitType.cs	Sat Mar 12 20:16:30 2011 +0000
     3.2 +++ b/API/Objects/Mock/MockUnitType.cs	Sat Mar 26 17:04:09 2011 +0000
     3.3 @@ -9,9 +9,13 @@
     3.4  {
     3.5  	public class MockUnitType : UnitType
     3.6  	{
     3.7 -		public MockUnitType () : base("mockunittype", "Mock Unit Type", MockRace.GetMockRace())
     3.8 +		public MockUnitType () : this("mockunittype", "Mock Unit Type")
     3.9  		{
    3.10 -			MainCategory = new MockCategory();
    3.11 +		}
    3.12 +
    3.13 +		public MockUnitType(string id, string name) : base(id, name, MockRace.GetMockRace())
    3.14 +		{
    3.15 +			MainCategory = MockCategory.GetCategory();
    3.16  		}
    3.17  	}
    3.18  }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Mar 26 17:04:09 2011 +0000
     4.3 @@ -0,0 +1,29 @@
     4.4 +// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     4.5 +// 
     4.6 +// 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.7 +using System;
     4.8 +using NUnit.Framework;
     4.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    4.10 +using NUnit.Framework.SyntaxHelpers;
    4.11 +
    4.12 +namespace IBBoard.WarFoundry.API.Objects.Requirements
    4.13 +{
    4.14 +	[TestFixture()]
    4.15 +	public class UnitRequiresAtLeastNUnitsRequirementTest
    4.16 +	{
    4.17 +		[Test()]
    4.18 +		public void TestWithNoUnits()
    4.19 +		{
    4.20 +			MockRace mockRace = MockRace.GetMockRace();
    4.21 +			UnitType unitType1 = new MockUnitType("type1", "Unit Type 1");
    4.22 +			mockRace.AddUnitType(unitType1);
    4.23 +			UnitType unitType2 = new MockUnitType("type2", "Unit Type 2");
    4.24 +			mockRace.AddUnitType(unitType2);
    4.25 +			Army army = new Army(mockRace, "Test", 1000);
    4.26 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1, unitType2);
    4.27 +			Unit unit = new Unit(unitType1, army.GetCategory(unitType1.MainCategory));
    4.28 +			Assert.That(req.CanAddToArmy(unit, army), Is.False);
    4.29 +		}
    4.30 +	}
    4.31 +}
    4.32 +
     5.1 --- a/API/Objects/UnitTypeTest.cs	Sat Mar 12 20:16:30 2011 +0000
     5.2 +++ b/API/Objects/UnitTypeTest.cs	Sat Mar 26 17:04:09 2011 +0000
     5.3 @@ -15,7 +15,7 @@
     5.4  		public void TestSettingMainCategorySetsCategoriesCollection()
     5.5  		{
     5.6  			UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
     5.7 -			MockCategory mockCategory = new MockCategory();
     5.8 +			MockCategory mockCategory = MockCategory.GetCategory();
     5.9  			unitType.MainCategory = mockCategory;
    5.10  			Assert.That(unitType.Categories, Has.Member(mockCategory));
    5.11  		}
    5.12 @@ -24,7 +24,7 @@
    5.13  		public void TestAddingFirstCategorySetsMainCategory()
    5.14  		{
    5.15  			UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
    5.16 -			MockCategory mockCategory = new MockCategory();
    5.17 +			MockCategory mockCategory = MockCategory.GetCategory();
    5.18  			unitType.AddCategory(mockCategory);
    5.19  			Assert.That(unitType.Categories.Length, Is.EqualTo(1));
    5.20  			Assert.That(unitType.Categories, Has.Member(mockCategory));
    5.21 @@ -35,7 +35,7 @@
    5.22  		public void TestAddingMultipleCategoriesSetsMainCategory()
    5.23  		{
    5.24  			UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
    5.25 -			MockCategory mockCategory = new MockCategory();
    5.26 +			MockCategory mockCategory = MockCategory.GetCategory();
    5.27  			unitType.AddCategory(mockCategory);
    5.28  			Category mockCategory2 = new Category("id1", "CatName");
    5.29  			unitType.AddCategory(mockCategory2);
     6.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Mar 12 20:16:30 2011 +0000
     6.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Mar 26 17:04:09 2011 +0000
     6.3 @@ -91,7 +91,7 @@
     6.4      <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" />
     6.5      <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     6.6      <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
     6.7 -    <Compile Include="API\Savers\Xml\WarFoundryXmlFileSaverTests.cs" />
     6.8 +    <Compile Include="API\Objects\Requirements\UnitRequiresAtLeastNUnitsRequirementTest.cs" />
     6.9    </ItemGroup>
    6.10    <ItemGroup>
    6.11      <None Include="app.config" />
    6.12 @@ -342,5 +342,7 @@
    6.13      <Folder Include="testdata\multifile-zips\" />
    6.14      <Folder Include="API\Savers\" />
    6.15      <Folder Include="API\Savers\Xml\" />
    6.16 +    <Folder Include="API\" />
    6.17 +    <Folder Include="API\Objects\Requirements\" />
    6.18    </ItemGroup>
    6.19  </Project>
    6.20 \ No newline at end of file