Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 142:f36b5e5e51e6
Re #345: Add failure message to requirements
* Add tests for "unit at least" requirement
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 01 May 2011 14:32:24 +0000 |
parents | cd95fc6400b2 |
children | 6fdb76d48e04 |
files | API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs |
diffstat | 1 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun May 01 14:21:58 2011 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun May 01 14:32:24 2011 +0000 @@ -220,13 +220,53 @@ Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); } + [Test] + public void TestValidationMessageIsBlankForPass() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.GetValidationMessage(army), Is.Empty); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithOneUnitRequired() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (have 0).")); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 2 × " + unitType2.Name + " (have 0).")); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army contains " + unitType1.Name + " and so must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (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));