Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 208:c323770e61c2
Re #379: Fix validation of requirements to check for unit
* Rename classes in tests to match API changes
* Alter tests to match new API (all classes require at least one UnitType that they're relevant to now)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 22 Feb 2012 20:48:40 +0000 |
parents | 27f163bf884a |
children | fc9a90d29ae0 |
files | API/Factories/Requirement/Mock/MockRequirement.cs API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs API/Objects/Requirement/Mock/AbstractFixedRequirement.cs API/Objects/Requirement/Mock/MockRequiresNUnitsForMObjectsRequirement.cs API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/RequiresNUnitsForMObjectsRequirementTest.cs API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs API/Objects/UnitTypeTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 13 files changed, 1238 insertions(+), 897 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Requirement/Mock/MockRequirement.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Factories/Requirement/Mock/MockRequirement.cs Wed Feb 22 20:48:40 2012 +0000 @@ -21,7 +21,7 @@ } } - public Validation AllowsAdding(WarFoundryObject wfObject, Army toArmy) + public Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) { throw new NotImplementedException(); } @@ -36,7 +36,7 @@ throw new NotImplementedException(); } - public string GetAllowsAddingMessage(UnitType toAdd, Army toArmy) + public string GetAllowsAddingMessage(IWarFoundryObject toAdd, Army toArmy) { throw new NotImplementedException(); }
--- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -12,7 +12,7 @@ namespace IBBoard.WarFoundry.API.Factories.Requirement { [TestFixture()] - public class UnitUnitRequiresNUnitsForMUnitsRequirementFactoryTest + public class UnitRequiresNUnitsForMUnitsRequirementFactoryTest { private static Race race; private static string typeID1 = "unit1"; @@ -47,7 +47,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -58,7 +58,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); @@ -70,7 +70,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2); expectedReq.AddUnitTypeRequirement(unitType3); @@ -83,7 +83,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -94,7 +94,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2, 3); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2;3", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -105,7 +105,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); expectedReq.AddUnitTypeRequirement(unitType2, 3); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory); @@ -117,7 +117,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, 2); expectedReq.AddUnitTypeRequirement(unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); @@ -129,7 +129,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1); expectedReq.AddUnitTypeRequirement(unitType2, 3); IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); @@ -151,7 +151,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - factory.CreateRequirement(unitType, typeID1+":a", raceFactory); + factory.CreateRequirement(unitType, typeID1 + ":a", raceFactory); } [Test()] @@ -177,7 +177,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -188,7 +188,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2, unitType3); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ";" + typeID3, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -199,7 +199,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory); @@ -211,7 +211,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -222,7 +222,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); @@ -233,7 +233,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1 + ":3", raceFactory); @@ -245,7 +245,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2, unitType1); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1, raceFactory); @@ -257,7 +257,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ";" + typeID1 + ":3", raceFactory); @@ -269,7 +269,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory); @@ -281,7 +281,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType2); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2, raceFactory); @@ -293,7 +293,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2, 3); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3", raceFactory); @@ -305,7 +305,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType2, 3); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2, raceFactory); @@ -317,7 +317,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2, raceFactory); @@ -329,7 +329,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType2); expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2 + ":3", raceFactory); @@ -341,7 +341,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); expectedReq.AddUnitTypeRequirement(3, 2, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3;2", raceFactory); @@ -353,10 +353,10 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(3, 2, unitType2); expectedReq.AddUnitTypeRequirement(unitType1, unitType2); - IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2, raceFactory); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2, raceFactory); Assert.That(req, Is.EqualTo(expectedReq)); } @@ -365,7 +365,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2, 3); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;2|" + typeID2 + ":3", raceFactory); @@ -377,7 +377,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType2, 3); expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2 + ":3;2", raceFactory); @@ -389,7 +389,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); expectedReq.AddUnitTypeRequirement(unitType2, 3, 2); IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2 + ":3;2", raceFactory); @@ -401,7 +401,7 @@ { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); - RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + UnitRequiresNUnitsForMUnitsRequirement expectedReq = new UnitRequiresNUnitsForMUnitsRequirement(unitType); expectedReq.AddUnitTypeRequirement(unitType2, 3, 2); expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2 + ":3", raceFactory);
--- a/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs Wed Feb 22 20:48:40 2012 +0000 @@ -19,22 +19,22 @@ result = fixedResult; } - public Validation AllowsAdding (WarFoundryObject wfObject, Army toArmy) + public Validation AllowsAdding(IWarFoundryObject wfObject, Army toArmy) { return result; } - public Validation ValidatesArmy (Army army) + public Validation ValidatesArmy(Army army) { return result; } - public string GetValidationMessage (Army army) + public string GetValidationMessage(Army army) { return (result.Equals(Validation.Failed)) ? "Validation failed" : ""; } - public string GetAllowsAddingMessage (UnitType toAdd, Army toArmy) + public string GetAllowsAddingMessage(IWarFoundryObject toAdd, Army toArmy) { return (result.Equals(Validation.Failed)) ? "Validation failed" : ""; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Mock/MockRequiresNUnitsForMObjectsRequirement.cs Wed Feb 22 20:48:40 2012 +0000 @@ -0,0 +1,38 @@ +// This file (MockRequiresNUnitsForMObjectsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 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; + +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock +{ + public class MockRequiresNUnitsForMObjectsRequirement : RequiresNUnitsForMObjectsRequirement<IWarFoundryObject> + { + public MockRequiresNUnitsForMObjectsRequirement(IWarFoundryObject allowedObject) : base(allowedObject) + { + } + + protected override int GetObjectCountFromArmy(Army toArmy, IWarFoundryObject obj) + { + throw new NotImplementedException(); + } + + protected override int GetObjectCountFromArmy(Army toArmy) + { + throw new NotImplementedException(); + } + + protected override int GetAllowedObjectCount(Army army) + { + throw new NotImplementedException(); + } + + public override string RequirementID + { + get + { + return GetType().FullName; + } + } + } +} +
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -12,9 +12,10 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] - public class RequiresAtLeastNUnitsRequirementTest : AbstractEqualityTest<RequiresAtLeastNUnitsRequirement> + public class RequiresAtLeastNUnitsRequirementTest : AbstractEqualityTest<RequiresAtLeastNUnitsRequirement<UnitType>> { private MockRace mockRace; + private UnitType allowedUnitType; private UnitType unitType1; private UnitType unitType2; private UnitType unitType3; @@ -23,6 +24,8 @@ 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"); @@ -36,7 +39,7 @@ { Army army = new Army(mockRace, "Test", 1000); Unit unit = CreateUnitOfType(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); } @@ -45,7 +48,7 @@ { Army army = new Army(mockRace, "Test", 1000); Unit unit = CreateUnitOfType(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); } @@ -53,7 +56,7 @@ public void TestAddingUnitWithOneUnitAndTwoOfUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); AddUnitOfTypeToArmy(unitType1, army); Unit unit = CreateUnitOfType(unitType1, army); @@ -64,7 +67,7 @@ public void TestAddingUnrelatedUnitTypeWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.NotApplicable)); } @@ -72,7 +75,7 @@ public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -81,7 +84,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -89,7 +92,7 @@ public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2, unitType3); Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); } @@ -98,7 +101,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType3, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2, unitType3); Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); } @@ -108,7 +111,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType3, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType2, unitType3); Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); } @@ -116,7 +119,7 @@ public void TestAddingOneOfUnitTypeWithTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } @@ -126,7 +129,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -135,7 +138,7 @@ public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -144,7 +147,7 @@ public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); } @@ -153,7 +156,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); } @@ -161,7 +164,7 @@ public void TestAddingMinNumberUnitTypePassesRequirement() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); AddUnitOfTypeToArmy(unitType1, army); @@ -173,7 +176,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.GetValidationMessage(army), Is.Empty); } @@ -181,7 +184,7 @@ public void TestValidationMessageIsCorrectForFailWithOneUnitRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType1.Name + " (have 0).")); } @@ -189,7 +192,7 @@ public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); } @@ -198,7 +201,7 @@ public void TestValidationMessageIsCorrectForFailWithTwoUnitsRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -209,7 +212,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -220,7 +223,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -231,7 +234,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty); } @@ -239,7 +242,7 @@ public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); } @@ -248,7 +251,7 @@ public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -258,7 +261,7 @@ public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -269,7 +272,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -280,7 +283,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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).")); @@ -296,23 +299,23 @@ return new Unit(unitType, army.GetCategory(unitType.MainCategory)); } - public override RequiresAtLeastNUnitsRequirement GetObject () + public override RequiresAtLeastNUnitsRequirement<UnitType> GetObject() { - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); return req; } - public override RequiresAtLeastNUnitsRequirement GetSameObject () + public override RequiresAtLeastNUnitsRequirement<UnitType> GetSameObject() { - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + RequiresAtLeastNUnitsRequirement<UnitType> req = new RequiresAtLeastNUnitsRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); return req; } - public override RequiresAtLeastNUnitsRequirement GetDifferentObject () + public override RequiresAtLeastNUnitsRequirement<UnitType> GetDifferentObject() { - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + 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);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMObjectsRequirementTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -0,0 +1,754 @@ +// 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/RequiresNUnitsForMUnitsRequirementTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,753 +0,0 @@ -// This file (UnitRequiresNUnitsForMUnitsRequirement.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 RequiresNUnitsForMUnitsRequirementTest : AbstractEqualityTest<RequiresNUnitsForMUnitsRequirement> - { - 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); - 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()] - public void TestAddingOneUnitWithOneUnitTypeRequiredAndOneUnitOfTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - 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()] - public void TestAddingOneUnitWithOneUnitTypeRequiredAndNoUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - 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 + " (would have 0 for 1).")); - } - - [Test()] - public void TestAddingOneUnitWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - 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 + " (would have 1 for 2).")); - } - - [Test()] - public void TestAddingTwoUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, 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.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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - 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 + " (would have 1 for 3).")); - } - - [Test()] - public void TestAddingOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() - { - Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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); - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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 RequiresNUnitsForMUnitsRequirement GetObject() - { - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3); - req.AddUnitTypeRequirement(unitType1, 2, 3); - return req; - } - - public override RequiresNUnitsForMUnitsRequirement GetSameObject() - { - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType3); - req.AddUnitTypeRequirement(unitType1, 2, 3); - return req; - } - - public override RequiresNUnitsForMUnitsRequirement GetDifferentObject() - { - RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(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; - } - } -} -
--- a/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -11,10 +11,10 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { - [TestFixture()] - public class RequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractEqualityTest<RequiresNoMoreThanNOfUnitTypeRequirement> + public abstract class RequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractEqualityTest<RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>> { private MockRace mockRace; + private UnitType allowedUnitType; private UnitType unitType1; private UnitType unitType2; private UnitType unitType3; @@ -23,6 +23,8 @@ 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"); @@ -36,7 +38,7 @@ { Army army = new Army(mockRace, "Test", 1000); Unit unit = CreateUnitOfType(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); } @@ -46,7 +48,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); Unit unit = CreateUnitOfType(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); } @@ -54,7 +56,7 @@ public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -63,7 +65,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType2); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } @@ -72,7 +74,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType2, 1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -83,7 +85,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType2, 1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } @@ -92,7 +94,7 @@ public void TestAddingUnitTypeDefaultsToNoMoreThanZero() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); AddUnitOfTypeToArmy(unitType2, army); @@ -103,7 +105,7 @@ public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType2); Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); AddUnitOfTypeToArmy(unitType2, army); @@ -114,7 +116,7 @@ public void TestValidationMessageIsBlankForPass() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.GetValidationMessage(army), Is.Empty); } @@ -123,7 +125,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + 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).")); } @@ -134,7 +136,7 @@ AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); } @@ -145,7 +147,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); @@ -156,7 +158,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); @@ -167,7 +169,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); @@ -177,7 +179,7 @@ public void TestAllowsAddMessageIsBlankForPass() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType, unitType1); Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty); } @@ -185,7 +187,7 @@ public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + 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).")); } @@ -195,7 +197,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); } @@ -204,7 +206,7 @@ public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); @@ -215,7 +217,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); @@ -226,7 +228,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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).")); @@ -242,23 +244,23 @@ return new Unit(unitType, army.GetCategory(unitType.MainCategory)); } - public override RequiresNoMoreThanNOfUnitTypeRequirement GetObject () + public override RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> GetObject() { - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); return req; } - public override RequiresNoMoreThanNOfUnitTypeRequirement GetSameObject () + public override RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> GetSameObject() { - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> req = new RequiresNoMoreThanNOfUnitTypeRequirement<UnitType>(allowedUnitType); req.AddUnitTypeRequirement(unitType1, 2); return req; } - public override RequiresNoMoreThanNOfUnitTypeRequirement GetDifferentObject () + public override RequiresNoMoreThanNOfUnitTypeRequirement<UnitType> GetDifferentObject() { - RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); + 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);
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -213,7 +213,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); AddUnitOfTypeToArmy(unitType2, army); @@ -226,7 +226,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.GetValidationMessage(army), Is.Empty); } @@ -236,7 +236,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " (have 0).")); } @@ -246,7 +246,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " (have 0).")); } @@ -256,7 +256,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + 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).")); @@ -267,7 +267,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); Assert.That(req.GetAllowsAddingMessage(unitType1, army), Is.Empty); } @@ -275,7 +275,7 @@ public void TestAllowsAddingMessageIsCorrectForFailWithTwoOfOneUnitRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + 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).")); } @@ -284,7 +284,7 @@ public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + 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).")); @@ -294,7 +294,7 @@ public void TestAllowsAddingMessageIsCorrectForFailWithTwoUnitsRequiredOtherUnit() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + 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).")); @@ -305,7 +305,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + 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).")); @@ -316,7 +316,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType3, army); - RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + 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)."));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Wed Feb 22 20:48:40 2012 +0000 @@ -0,0 +1,294 @@ +// This file (UnitRequiresNUnitsForMUnitsRequirementTest.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; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + [TestFixture()] + public class UnitRequiresNUnitsForMUnitsRequirementTests + { + private MockRace mockRace; + private UnitType unitType1; + private UnitType unitType2; + private UnitType unitType3; + + [TestFixtureSetUp()] + public void SetupRace() + { + mockRace = new MockRace(); + 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); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); + } + + [Test()] + public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + 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); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + } + + [Test()] + public void TestAddingUnitTriggersFailure() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + 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 TestAddingUnitTypeDefaultsToNoMoreThanZero() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + 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 TestRequirementNotApplicableWhenLimitedUnitNotIncluded() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable)); + Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable)); + } + + [Test] + public void TestRequirementBecomesInvalidWhenProhibitedUnitsChange() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(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); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); + } + + [Test] + public void TestValidationMessageIsBlankForPass() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.GetValidationMessage(army), Is.Empty); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithOneUnitProhibited() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (have 3).")); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType3, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType3.Name + " (have 1).")); + } + + [Test] + public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndBothUnitsInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1).")); + } + + [Test] + public void TestAllowsAddMessageIsBlankForPass() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty); + } + + [Test] + public void TestAllowsAddMessageIsCorrectForFailWithOneUnitProhibited() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); + } + + [Test] + public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (would have 3).")); + } + + [Test] + public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); + } + + [Test] + public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).")); + } + + [Test] + public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType3, army); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.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)); + } + } +} +
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -33,7 +33,7 @@ { Army army = new Army(mockRace, "Test", 1000); Unit unit = CreateUnitOfType(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); } @@ -44,7 +44,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); Unit unit = CreateUnitOfType(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); } @@ -53,7 +53,7 @@ public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -63,7 +63,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } @@ -73,7 +73,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -84,7 +84,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } @@ -94,7 +94,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); AddUnitOfTypeToArmy(unitType2, army); @@ -105,7 +105,7 @@ public void TestAddingUnitTypeDefaultsToNoMoreThanZero() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); AddUnitOfTypeToArmy(unitType2, army); @@ -116,7 +116,7 @@ public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable)); Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable)); @@ -127,7 +127,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); AddUnitOfTypeToArmy(unitType2, army); @@ -139,7 +139,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); } @@ -148,7 +148,7 @@ public void TestValidationMessageIsBlankForPass() { Army army = new Army(mockRace, "Test", 1000); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.GetValidationMessage(army), Is.Empty); } @@ -159,7 +159,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); } @@ -172,7 +172,7 @@ AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (have 3).")); } @@ -183,7 +183,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); @@ -195,7 +195,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType3, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType3.Name + " (have 1).")); @@ -208,7 +208,7 @@ AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType3, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1).")); @@ -219,7 +219,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.Empty); } @@ -228,7 +228,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); } @@ -240,7 +240,7 @@ AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (would have 3).")); } @@ -250,7 +250,7 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); @@ -262,7 +262,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).")); @@ -274,7 +274,7 @@ Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType3, army); - RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1)."));
--- a/API/Objects/UnitTypeTest.cs Tue Jan 31 20:59:15 2012 +0000 +++ b/API/Objects/UnitTypeTest.cs Wed Feb 22 20:48:40 2012 +0000 @@ -65,26 +65,27 @@ UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace()); unitType.MinNumber = 1; unitType.MaxNumber = 2; - Assert.That(unitType.GetRequirements(), Has.Length(2)); - RequiresNoMoreThanNOfUnitTypeRequirement maxLimit = new RequiresNoMoreThanNOfUnitTypeRequirement(); - maxLimit.AddUnitTypeRequirement(unitType, 2); - Assert.That(unitType.GetRequirements(), Has.Member(maxLimit)); - RequiresAtLeastNUnitsRequirement minLimit = new RequiresAtLeastNUnitsRequirement(); - minLimit.AddUnitTypeRequirement(unitType, 1); - Assert.That(unitType.GetRequirements(), Has.Member(minLimit)); + Assert.Fail("Needs fixing after changes"); + //Assert.That(unitType.GetRequirements(), Has.Length(2)); + //RequiresNoMoreThanNOfUnitTypeRequirement<OBJECT_TYPE> maxLimit = new RequiresNoMoreThanNOfUnitTypeRequirement<OBJECT_TYPE>(); + //maxLimit.AddUnitTypeRequirement(unitType, 2); + //Assert.That(unitType.GetRequirements(), Has.Member(maxLimit)); + //RequiresAtLeastNUnitsRequirement minLimit = new RequiresAtLeastNUnitsRequirement(); + //minLimit.AddUnitTypeRequirement(unitType, 1); + //Assert.That(unitType.GetRequirements(), Has.Member(minLimit)); } - public override UnitType GetObject () + public override UnitType GetObject() { return new UnitType("id1", "Type 1", new MockRace()); } - public override UnitType GetSameObject () + public override UnitType GetSameObject() { return new UnitType("id1", "Type 1", new MockRace()); } - public override UnitType GetDifferentObject () + public override UnitType GetDifferentObject() { DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); GameSystem gameSystem = new GameSystem("system", "system", factory);
--- a/IBBoard.WarFoundry.API.Tests.csproj Tue Jan 31 20:59:15 2012 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Wed Feb 22 20:48:40 2012 +0000 @@ -113,10 +113,12 @@ <Compile Include="API\Objects\UnitEquipmentRatioSelectionTests.cs" /> <Compile Include="API\Objects\UnitEquipmentNumericSelectionTests.cs" /> <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs" /> - <Compile Include="API\Objects\Requirement\RequiresNUnitsForMUnitsRequirementTest.cs" /> <Compile Include="API\Factories\Requirement\UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs" /> <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" /> </ItemGroup> <ItemGroup> <None Include="app.config" />