Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 122:aa37b31976e6
Re #27: Unit requirements
* Restructure "check default" tests so that we actually check the default (test before and after)
* Add test to make sure requirement checks on each request
* Add test to make sure that adding more prohibited units than the limit causes a failure
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 09 Apr 2011 10:43:01 +0000 |
parents | 6f46fa3c47e5 |
children | dd0ef8526a4e |
files | API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs |
diffstat | 2 files changed, 27 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sat Apr 09 10:18:27 2011 +0000 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sat Apr 09 10:43:01 2011 +0000 @@ -89,9 +89,10 @@ public void TestAddingUnitTypeDefaultsToNoMoreThanZero() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); 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)); }
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sat Apr 09 10:18:27 2011 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sat Apr 09 10:43:01 2011 +0000 @@ -105,10 +105,10 @@ public void TestAddingUnitTypeDefaultsToNoMoreThanZero() { Army army = new Army(mockRace, "Test", 1000); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); - req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } @@ -122,6 +122,28 @@ Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable)); } + [Test] + public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + 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 TestAddingLimitedUnitTriggersFailure() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); + } + private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) { army.AddUnit(CreateUnitOfType(unitType, army));