Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 214:1674a499168e
Re #379:
* Make all tests test both Unit and UnitType by modifying abstract class's helper methods
* Re-implement UnitRequiresAtLeastNUnitsRequirementTest tests (adding and validation)
* Remove unused tests from Requires...
TODO: Re-implement equality testing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Feb 2012 20:18:45 +0000 |
parents | 0416df2ab39b |
children | 7e7296c0ae1f |
files | API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/RequiresNUnitsForMObjectsRequirementTest.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 8 files changed, 97 insertions(+), 1560 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs Sun Feb 26 20:18:45 2012 +0000 @@ -16,10 +16,7 @@ { Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Passed)); Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty); - } - - protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army) - { + Unit unit = CreateUnitOfType(unitType, army); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty); } @@ -28,10 +25,7 @@ { Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.NotApplicable)); Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty); - } - - protected static void Assert_That__AddingNotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army) - { + Unit unit = CreateUnitOfType(unitType, army); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty); } @@ -40,10 +34,7 @@ { Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Failed)); Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.EqualTo(message)); - } - - protected static void Assert_That__FailsAdding(AbstractUnitRequirement<OBJECT_TYPE> req, Unit unit, Army army, string message) - { + Unit unit = CreateUnitOfType(unitType, army); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); Assert.That(req.GetAllowsAddingMessage(unit, army), Is.EqualTo(message)); }
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,327 +0,0 @@ -// 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; -using System.Reflection; -using IBBoard.NUnit; -using IBBoard.WarFoundry.API.Factories; - -namespace IBBoard.WarFoundry.API.Objects.Requirement -{ - [TestFixture()] - public class RequiresAtLeastNUnitsRequirementTest : AbstractEqualityTest<RequiresAtLeastNUnitsRequirement<UnitType>> - { - private MockRace mockRace; - private UnitType allowedUnitType; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - allowedUnitType = new MockUnitType("allowed", "Allowed Type"); - mockRace.AddUnitType(allowedUnitType); - 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 TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - Unit unit = CreateUnitOfType(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); - } - - [Test()] - public void TestAddingOneUnitWithOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - Unit unit = CreateUnitOfType(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitWithOneUnitAndTwoOfUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - AddUnitOfTypeToArmy(unitType1, army); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnrelatedUnitTypeWithNoUnitsAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.NotApplicable)); - } - - [Test()] - public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2, unitType3); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2, unitType3); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2, unitType3); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingOneOfUnitTypeWithTwoOfOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestAddingOneUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - } - - [Test] - public void TestAddingMinNumberUnitTypePassesRequirement() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); - AddUnitOfTypeToArmy(unitType1, army); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test] - public void TestValidationMessageIsBlankForPass() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithOneUnitRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (have 0).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0); 1 × " + unitType2.Name + " (have 0).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0).")); - } - - [Test] - public void TestAllowsAddingMessageIsBlankForPass() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 2 × " + unitType1.Name + " (would have 1).")); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0).")); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0).")); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0).")); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (would have 0).")); - } - - 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)); - } - - public override RequiresAtLeastNUnitsRequirement<UnitType> GetObject() - { - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - return req; - } - - public override RequiresAtLeastNUnitsRequirement<UnitType> GetSameObject() - { - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - return req; - } - - public override RequiresAtLeastNUnitsRequirement<UnitType> GetDifferentObject() - { - RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); - DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); - GameSystem gameSystem = new GameSystem("system", "system", factory); - Race race = new Race("race", "race", gameSystem, factory); - req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2); - return req; - } - } -} -
--- a/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,754 +0,0 @@ -// This file (UnitRequiresNUnitsForMObjectsRequirement.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; -using System.Reflection; -using IBBoard.NUnit; -using IBBoard.WarFoundry.API.Factories; - -namespace IBBoard.WarFoundry.API.Objects.Requirement -{ - public abstract class RequiresNUnitsForMObjectsRequirementTest : AbstractEqualityTest<RequiresNUnitsForMObjectsRequirement<UnitType>> - { - private MockRace mockRace; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - private UnitType unitType4; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = MockRace.GetMockRace(); - 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); - unitType4 = new MockUnitType("type4", "Unit Type 4"); - mockRace.AddUnitType(unitType4); - } - - [Test()] - public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequiredIsNA() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Unit unit = CreateUnitOfType(unitType3, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingOneUnitWithOneUnitTypeRequiredAndOneUnitOfTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingOneUnitWithOneUnitTypeRequiredAndNoUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).")); - } - - [Test()] - public void TestAddingOneUnitWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - req.AddUnitTypeRequirement(unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).")); - } - - [Test()] - public void TestAddingTwoUnitsWithOneUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 2).")); - } - - [Test()] - public void TestAddingTwoUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 2); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingTwoUnitsWithTwoAllowedAndOneAllowedForDifferentTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 2); - req.AddUnitTypeRequirement(unitType3, 1, 1); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 2).")); - } - - [Test()] - public void TestAddingSecondUnitsWithOneAllowedForTwoTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 1); - req.AddUnitTypeRequirement(unitType3, 1, 1); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 2); 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 2).")); - } - - [Test()] - public void TestAddingSecondUnitsWithOneAllowedForTwoTypesFails_ShorthandMethod() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 2); 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 2).")); - } - - [Test()] - public void TestAddingThreeUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 2); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 1 for 3).")); - } - - [Test()] - public void TestAddingOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2, 3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every 3 × " + unitType1.Name + " (would have 1 for 1).")); - } - - [Test()] - public void TestAddingSecondUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2, 3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every 3 × " + unitType1.Name + " (would have 1 for 2).")); - } - - [Test()] - public void TestAddingFourthUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndThreeUnitsOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(3, unitType2, army); - AddUnitsOfTypeToArmy(3, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2, 3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every 3 × " + unitType1.Name + " (would have 3 for 4).")); - } - - [Test()] - public void TestAddingUnrelatedUnitWithNoUnitsAndTwoCombinedUnitTypesRequiredIsNA() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType4, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOneTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 2 for 3).")); - } - - [Test()] - public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 2 for 3).")); - } - - [Test()] - public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 2 for 3).")); - } - - [Test()] - public void TestAddingUnrelatedUnitWithNoUnitsAndThreeForEachTwoCombinedUnitTypesRequiredIsNA() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType4, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingThirdUnitWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOneTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(2, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingThirdUnitWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitsOfTypeToArmy(2, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(5, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType3, army); - AddUnitsOfTypeToArmy(5, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType2, army); - AddUnitsOfTypeToArmy(5, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); - } - - [Test()] - public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(6, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 3 × " + unitType1.Name + " (would have 2 for 7).")); - } - - [Test()] - public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType3, army); - AddUnitsOfTypeToArmy(6, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 3 × " + unitType1.Name + " (would have 2 for 7).")); - } - - [Test()] - public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType2, army); - AddUnitsOfTypeToArmy(6, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Unit unit = CreateUnitOfType(unitType1, army); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 3 × " + unitType1.Name + " (would have 2 for 7).")); - } - - [Test()] - public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithOneUnitTypeRequiredAndOneUnitOfTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithOneUnitTypeRequiredAndNoUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).")); - } - - [Test()] - public void TestValidatingArmyWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - req.AddUnitTypeRequirement(unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).")); - } - - [Test()] - public void TestValidatingArmyWithTwoUnitsAndOneUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).")); - } - - [Test()] - public void TestValidatingArmyWithTwoUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithTwoUnitsWithTwoAllowedAndOneAllowedForDifferentTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 2); - req.AddUnitTypeRequirement(unitType3, 1, 1); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).")); - } - - [Test()] - public void TestValidatingArmyWithTwoUnitsWithOneAllowedForTwoTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 1); - req.AddUnitTypeRequirement(unitType3, 1, 1); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2); 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).")); - } - - [Test()] - public void TestValidatingArmyWithTwoUnitsWithOneAllowedForTwoTypesFails_ShorthandMethod() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2); 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).")); - } - - [Test()] - public void TestValidatingArmyWithOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2, 3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every 3 × " + unitType1.Name + " (have 1 for 1).")); - } - - [Test()] - public void TestValidatingArmyWithTwoUnitsWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(2, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2, 3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every 3 × " + unitType1.Name + " (have 1 for 2).")); - } - - [Test()] - public void TestValidatingArmyWithFourUnitsWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndThreeUnitsOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(3, unitType2, army); - AddUnitsOfTypeToArmy(4, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2, 3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every 3 × " + unitType1.Name + " (have 3 for 4).")); - } - - [Test()] - public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 1, 2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 1 for 3).")); - } - - [Test()] - public void TestValidatingArmyWithNoUnitsAndThreeForEachTwoCombinedUnitTypesRequiredIsNA() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType4, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithThreeUnitsWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOneTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(3, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithThreeUnitsWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitsOfTypeToArmy(3, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(6, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType3, army); - AddUnitsOfTypeToArmy(6, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType2, army); - AddUnitsOfTypeToArmy(6, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test()] - public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType3, army); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitsOfTypeToArmy(7, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 3 × " + unitType1.Name + " (have 2 for 7).")); - } - - [Test()] - public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType3, army); - AddUnitsOfTypeToArmy(7, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 3 × " + unitType1.Name + " (have 2 for 7).")); - } - - [Test()] - public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitsOfTypeToArmy(2, unitType2, army); - AddUnitsOfTypeToArmy(7, unitType1, army); - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType1); - req.AddUnitTypeRequirement(3, unitType2, unitType3); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 3 × " + unitType1.Name + " (have 2 for 7).")); - } - - private static void AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army) - { - for (int i = 0; i < count; i++) - { - AddUnitOfTypeToArmy(unitType, army); - } - } - - 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)); - } - - public override RequiresNUnitsForMObjectsRequirement<UnitType> GetObject() - { - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType3); - req.AddUnitTypeRequirement(unitType1, 2, 3); - return req; - } - - public override RequiresNUnitsForMObjectsRequirement<UnitType> GetSameObject() - { - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType3); - req.AddUnitTypeRequirement(unitType1, 2, 3); - return req; - } - - public override RequiresNUnitsForMObjectsRequirement<UnitType> GetDifferentObject() - { - RequiresNUnitsForMObjectsRequirement<UnitType> req = CreateRequirement(unitType3); - DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); - GameSystem gameSystem = new GameSystem("system", "system", factory); - Race race = new Race("race", "race", gameSystem, factory); - req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2, 3); - return req; - } - - protected abstract RequiresNUnitsForMObjectsRequirement<UnitType> CreateRequirement(UnitType allowedType, params UnitType[] requiredUnitTypes); - } -} -
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,272 +0,0 @@ -// 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; -using System.Reflection; -using IBBoard.NUnit; -using IBBoard.WarFoundry.API.Factories; - -namespace IBBoard.WarFoundry.API.Objects.Requirement -{ - public abstract class RequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractEqualityTest<RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>> - { - private MockRace mockRace; - private UnitType allowedUnitType; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - allowedUnitType = new MockUnitType("allowed", "Allowed Type"); - mockRace.AddUnitType(allowedUnitType); - 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<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - Unit unit = CreateUnitOfType(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestAddingUnitTypeSetsLimit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType2, 1); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeSetsLimitForFailure() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType2, 1); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestAddingUnitTypeDefaultsToNoMoreThanZero() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - AddUnitOfTypeToArmy(unitType2, army); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); - } - - [Test] - public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); - AddUnitOfTypeToArmy(unitType2, army); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - } - - [Test] - public void TestValidationMessageIsBlankForPass() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetValidationMessage(army), Is.Empty); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithOneUnitProhibited() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (have 1).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType1.Name + " (have 3).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (have 1); 0 × " + unitType2.Name + " (have 1).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (have 1).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); - } - - [Test] - public void TestAllowsAddMessageIsBlankForPass() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty); - } - - [Test] - public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType1); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1).")); - } - - [Test] - public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType1.Name + " (would have 3).")); - } - - [Test] - public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited() - { - Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1).")); - } - - [Test] - public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1); 0 × " + unitType2.Name + " (would have 1).")); - } - - [Test] - public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType1.Name + " (would have 1); 0 × " + unitType2.Name + " (would have 1).")); - } - - 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)); - } - - public override RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> GetObject() - { - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - return req; - } - - public override RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> GetSameObject() - { - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - req.AddUnitTypeRequirement(unitType1, 2); - return req; - } - - public override RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> GetDifferentObject() - { - RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); - DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); - GameSystem gameSystem = new GameSystem("system", "system", factory); - Race race = new Race("race", "race", gameSystem, factory); - req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2); - return req; - } - } -} -
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun Feb 26 20:18:45 2012 +0000 @@ -1,4 +1,4 @@ -// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard +// This file (UnitRequiresAtLeastNUnitsRequirementTest.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; @@ -32,30 +32,9 @@ public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - Unit unit = CreateUnitOfType(unitType1, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - Unit unit = CreateUnitOfType(unitType1, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); - } - - [Test()] - public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0)."); } [Test()] @@ -65,7 +44,7 @@ AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + Assert_That__PassesAdding(req, unitType1, army); } [Test()] @@ -75,7 +54,7 @@ UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0); 1 × " + unitType3.Name + " (would have 0)."); } [Test()] @@ -86,7 +65,7 @@ UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType3.Name + " (would have 0)."); } [Test()] @@ -97,7 +76,7 @@ UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0)."); } [Test()] @@ -109,7 +88,7 @@ UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + Assert_That__PassesAdding(req, unitType1, army); } [Test()] @@ -119,17 +98,26 @@ AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " (would have 1)."); } [Test()] - public void TestAddingUnrelatedUnitTypeIsAllowedWhenRequirementsNotMet() + public void TestAddingUnrelatedUnitTypeValidatesAsNotApplicable() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable)); + Assert_That__AddingNotApplicable(req, unitType3, army); + } + + [Test()] + public void TestAddingUnrelatedUnitTypeValidatesAsNotApplicableWhenRequirementsNotMet() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert_That__AddingNotApplicable(req, unitType3, army); } [Test()] @@ -140,7 +128,7 @@ AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + Assert_That__PassesAdding(req, unitType1, army); } [Test()] @@ -150,7 +138,7 @@ AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + Assert_That__PassesAdding(req, unitType1, army); } [Test()] @@ -160,166 +148,137 @@ AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " (would have 1)."); AddUnitOfTypeToArmy(unitType2, army); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + Assert_That__PassesAdding(req, unitType1, army); } [Test()] - public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() + public void TestValidatingWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - } - - [Test()] - public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType1, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0)."); } [Test()] - public void TestValidityOfArmyWhenNoRequireeAndRequirementNotMet() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); - } - - [Test] - public void TestSatisfyingRequirementChangesResult() + public void TestValidatingWithOneUnitAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); - AddUnitOfTypeToArmy(unitType2, army); - Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); + Assert_That__ValidationPasses(req, army); } - [Test] - public void TestAddingMinNumberUnitTypePassesRequirement() + [Test()] + public void TestValidatingWithNoUnitsAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); AddUnitOfTypeToArmy(unitType1, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); - AddUnitOfTypeToArmy(unitType2, army); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (have 0)."); } - [Test] - public void TestValidationMessageIsBlankForPass() + [Test()] + public void TestValidatingWithOneUnitAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.Empty); + req.AddUnitTypeRequirement(unitType3); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " (have 0)."); } - [Test] - public void TestValidationMessageIsCorrectForFailWithOneUnitRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired() + [Test()] + public void TestValidatingWithOtherOneUnitAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " (have 0).")); - } - - [Test] - public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); - Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (have 0).")); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0)."); } - [Test] - public void TestAllowsAddingMessageIsBlankForPass() + [Test()] + public void TestValidatingWithBothUnitsAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired() - { - Army army = new Army(mockRace, "Test", 1000); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " (would have 1).")); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired() - { - Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " (would have 0).")); - } - - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit() - { - Army army = new Army(mockRace, "Test", 1000); - UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - req.AddUnitTypeRequirement(unitType3); - Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0).")); + Assert_That__ValidationPasses(req, army); } - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOneUnit() + [Test()] + public void TestValidatingWithOneUnitAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - req.AddUnitTypeRequirement(unitType3); - Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " (would have 0).")); + req.AddUnitTypeRequirement(unitType2, 2); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 1)."); } - [Test] - public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredWithOtherUnit() + [Test()] + public void TestValidatingWithUnrelatedUnitTypeValidatesAsNotApplicable() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert_That__NotApplicable(req, army); + } + + [Test()] + public void TestValidatingWithTwoUnitsAndTwoOfOneUnitTypeRequired() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert_That__ValidationPasses(req, army); + } + + [Test()] + public void TestValidatingRequirementWithNoNumberDefaultsToHavingOne() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - req.AddUnitTypeRequirement(unitType3); - Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (would have 0).")); + Assert_That__ValidationPasses(req, army); + } + + [Test()] + public void TestAddingUnitTypeMakesRequirementPassValidating() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); } } }
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sun Feb 26 15:38:13 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sun Feb 26 20:18:45 2012 +0000 @@ -29,16 +29,6 @@ } [Test()] - public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredFails() - { - Army army = new Army(mockRace, "Test", 1000); - Unit unit = CreateUnitOfType(unitType1, army); - UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert_That__FailsAdding(req, unit, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."); - } - - [Test()] public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredFails() { Army army = new Army(mockRace, "Test", 1000); @@ -48,17 +38,6 @@ } [Test()] - public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredPasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - Unit unit = CreateUnitOfType(unitType1, army); - UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert_That__PassesAdding(req, unit, army); - } - - [Test()] public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredPasses() { Army army = new Army(mockRace, "Test", 1000); @@ -69,17 +48,6 @@ } [Test()] - public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredPassesWhenAddingRequiredUnit() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType1, army); - Unit unit = CreateUnitOfType(unitType2, army); - UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert_That__PassesAdding(req, unit, army); - } - - [Test()] public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredPassesWhenAddingRequiredUnitType() { Army army = new Army(mockRace, "Test", 1000); @@ -151,9 +119,7 @@ UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__AddingNotApplicable(req, unitType3, army); - Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType3, army), army); Assert_That__AddingNotApplicable(req, unitType2, army); - Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType2, army), army); } [Test]
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sun Feb 26 20:18:45 2012 +0000 @@ -29,16 +29,6 @@ } [Test()] - public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed() - { - Army army = new Army(mockRace, "Test", 1000); - Unit unit = CreateUnitOfType(unitType1, army); - UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert_That__PassesAdding(req, unit, army); - } - - [Test()] public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() { Army army = new Army(mockRace, "Test", 1000); @@ -48,17 +38,6 @@ } [Test()] - public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - Unit unit = CreateUnitOfType(unitType1, army); - UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); - req.AddUnitTypeRequirement(unitType2); - Assert_That__FailsAdding(req, unit, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1)."); - } - - [Test()] public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() { Army army = new Army(mockRace, "Test", 1000); @@ -119,9 +98,7 @@ UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__AddingNotApplicable(req, unitType3, army); - Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType3, army), army); Assert_That__AddingNotApplicable(req, unitType2, army); - Assert_That__AddingNotApplicable(req, CreateUnitOfType(unitType2, army), army); } [Test]
--- a/IBBoard.WarFoundry.API.Tests.csproj Sun Feb 26 15:38:13 2012 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sun Feb 26 20:18:45 2012 +0000 @@ -89,11 +89,9 @@ <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" /> <Compile Include="API\EventListeningWarFoundryLoader.cs" /> <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" /> - <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\ValidationTests.cs" /> <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs" /> - <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" /> <Compile Include="API\Objects\RaceTests.cs" /> <Compile Include="API\Objects\Requirement\RequirementHandlerTests.cs" /> <Compile Include="API\Objects\Requirement\Mock\FailingRequirement.cs" /> @@ -117,7 +115,6 @@ <Compile Include="API\Factories\Mock\FileSearchingWarFoundryFactory.cs" /> <Compile Include="API\Objects\ArmyTests.cs" /> <Compile Include="API\Objects\Requirement\UnitRequiresNUnitsForMUnitsRequirementTests.cs" /> - <Compile Include="API\Objects\Requirement\RequiresNUnitsForMObjectsRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\Mock\MockRequiresNUnitsForMObjectsRequirement.cs" /> <Compile Include="API\Objects\Requirement\AbstractUnitRequirementTest.cs" /> </ItemGroup>