Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 189:eea440e5891b
Re #350: Add requirement to allow N of unit for specific other units
* Add extra test to check failure of limit with specific values
* Add extra lines to existing tests to check returned error
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 30 Nov 2011 20:45:12 +0000 |
parents | 0762766bd3f2 |
children | 702a0957f9e4 |
files | API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Tue Nov 29 20:56:34 2011 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Wed Nov 30 20:45:12 2011 +0000 @@ -38,6 +38,7 @@ RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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()] @@ -48,6 +49,7 @@ RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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()] @@ -57,6 +59,7 @@ RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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 + " (have 0 for 1).")); } [Test()] @@ -68,6 +71,7 @@ RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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 + " (have 1 for 2).")); } [Test()] @@ -80,6 +84,21 @@ 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 TestAddingThreeUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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 + " (have 1 for 3).")); } private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)