# HG changeset patch # User IBBoard # Date 1303070877 0 # Node ID f64742dde5f90a94794552849e00ed9fafe2b16a # Parent 8f1af48e120ce1364d80f67d847b284474511863 Re #27: Unit requirements * Start writing tests for requirement handler * Add mocks to support tests Note: NA test currently fails (expect pass but get fail) diff -r 8f1af48e120c -r f64742dde5f9 API/Objects/Requirement/Mock/AbstractFixedRequirement.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Mock/AbstractFixedRequirement.cs Sun Apr 17 20:07:57 2011 +0000 @@ -0,0 +1,28 @@ +// This file (AbstractFixedRequirement.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; + +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock +{ + public class AbstractFixedRequirement : IRequirement + { + private Validation result; + + public AbstractFixedRequirement(Validation fixedResult) + { + result = fixedResult; + } + + public Validation AllowsAdding (WarFoundryObject wfObject, Army toArmy) + { + return result; + } + + public Validation ValidatesArmy (Army army) + { + return result; + } + } +} + diff -r 8f1af48e120c -r f64742dde5f9 API/Objects/Requirement/Mock/FailingRequirement.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Mock/FailingRequirement.cs Sun Apr 17 20:07:57 2011 +0000 @@ -0,0 +1,16 @@ +// This file (FailingRequirement.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; + +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock +{ + public class FailingRequirement : AbstractFixedRequirement + { + public FailingRequirement() : base(Validation.Failed) + { + //Do nothing special + } + } +} + diff -r 8f1af48e120c -r f64742dde5f9 API/Objects/Requirement/Mock/NotApplicableRequirement.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Mock/NotApplicableRequirement.cs Sun Apr 17 20:07:57 2011 +0000 @@ -0,0 +1,15 @@ +// This file (NotApplicableRequirement.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; + +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock +{ + public class NotApplicableRequirement : AbstractFixedRequirement + { + public NotApplicableRequirement() : base(Validation.NotApplicable) + { + } + } +} + diff -r 8f1af48e120c -r f64742dde5f9 API/Objects/Requirement/Mock/PassingRequirement.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Mock/PassingRequirement.cs Sun Apr 17 20:07:57 2011 +0000 @@ -0,0 +1,15 @@ +// This file (PassingRequirement.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; + +namespace IBBoard.WarFoundry.API.Objects.Requirement.Mock +{ + public class PassingRequirement : AbstractFixedRequirement + { + public PassingRequirement() : base(Validation.Passed) + { + } + } +} + diff -r 8f1af48e120c -r f64742dde5f9 API/Objects/Requirement/RequirementHandlerTests.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/RequirementHandlerTests.cs Sun Apr 17 20:07:57 2011 +0000 @@ -0,0 +1,58 @@ +// This file (RequirementHandlerTests.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 IBBoard.WarFoundry.API.Objects; +using NUnit.Framework.SyntaxHelpers; +using IBBoard.WarFoundry.API.Objects.Requirement.Mock; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + [TestFixture()] + public class RequirementHandlerTests + { + [Test()] + public void TestArmyWithNoRequirementsValidates() + { + MockRace race = new MockRace(); + Army army = new Army(race, "test", 1000); + Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); + } + + [Test()] + public void TestArmyWithFailingRequirementFails() + { + MockRace race = new MockRace(); + MockUnitType mockUnitType = new MockUnitType(); + mockUnitType.AddRequirement(new FailingRequirement()); + race.AddUnitType(mockUnitType); + Army army = new Army(race, "test", 1000); + Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed)); + } + + [Test()] + public void TestArmyWithPassingRequirementPasses() + { + MockRace race = new MockRace(); + MockUnitType mockUnitType = new MockUnitType(); + mockUnitType.AddRequirement(new PassingRequirement()); + race.AddUnitType(mockUnitType); + Army army = new Army(race, "test", 1000); + Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); + } + + [Test()] + public void TestArmyWithNotApplicableRequirementPasses() + { + MockRace race = new MockRace(); + MockUnitType mockUnitType = new MockUnitType(); + mockUnitType.AddRequirement(new NotApplicableRequirement()); + race.AddUnitType(mockUnitType); + Army army = new Army(race, "test", 1000); + Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); + } + } +} + diff -r 8f1af48e120c -r f64742dde5f9 IBBoard.WarFoundry.API.Tests.csproj --- a/IBBoard.WarFoundry.API.Tests.csproj Sun Apr 17 19:34:48 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sun Apr 17 20:07:57 2011 +0000 @@ -1,4 +1,4 @@ - + Debug @@ -97,6 +97,11 @@ + + + + + @@ -345,5 +350,6 @@ + \ No newline at end of file