Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 187:cd2aeab2357f
Re #356: Add factory for UnitRequiresNoMoreThanNOfUnitTypeRequirement
* Rename factory
* Update unit tests from basic copy/paste/find&replace
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 13 Nov 2011 20:53:55 +0000 |
parents | 3263691443be |
children | 0762766bd3f2 |
files | API/Factories/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs API/Factories/Requirement/UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 3 files changed, 131 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Factories/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs Sun Nov 13 20:53:55 2011 +0000 @@ -0,0 +1,130 @@ +// This file (UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.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 IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.API.Objects.Requirement; +using IBBoard.WarFoundry.API.Factories.Mock; + +namespace IBBoard.WarFoundry.API.Factories.Requirement +{ + [TestFixture()] + public class UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest + { + private static Race race; + private static string typeID1 = "unit1"; + private static string typeID2 = "unit2"; + private static UnitType unitType1; + private static UnitType unitType2; + private static MockRaceFactory raceFactory = new MockRaceFactory(); + + [TestFixtureSetUp()] + public void Setup() + { + race = new MockRace(); + unitType1 = new UnitType(typeID1, "Unit 1", race); + race.AddUnitType(unitType1); + unitType2 = new UnitType(typeID2, "Unit 2", race); + race.AddUnitType(unitType2); + } + + [Test()] + public void TestCreatesRequirement() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null); + } + + [Test()] + public void TestCreatesCorrectRequirement() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1); + IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForTwoIDs() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1); + expectedReq.AddUnitTypeRequirement(unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementWithNumber() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, 2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, 2); + expectedReq.AddUnitTypeRequirement(unitType2, 3); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, 2); + expectedReq.AddUnitTypeRequirement(unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1); + expectedReq.AddUnitTypeRequirement(unitType2, 3); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires no more than N of unit type' requirement")] + public void TestExceptionsForInvalidID() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, "fibble", raceFactory); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid amount 'a' for unit type 'unit1' for 'Requires no more than N of unit type' requirement")] + public void TestExceptionsForInvalidNumber() + { + UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory factory = new UnitRequiresNoMoreThanNOfUnitTypeRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, typeID1+":a", raceFactory); + } + } +} +
--- a/API/Factories/Requirement/UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.cs Sun Nov 13 20:49:37 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -// This file (UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.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 IBBoard.WarFoundry.API.Objects; -using IBBoard.WarFoundry.API.Objects.Requirement; -using IBBoard.WarFoundry.API.Factories.Mock; - -namespace IBBoard.WarFoundry.API.Factories.Requirement -{ - [TestFixture()] - public class UnitRequiresNoMoreThanNUnitsRequirementFactoryTest - { - private static Race race; - private static string typeID1 = "unit1"; - private static string typeID2 = "unit2"; - private static UnitType unitType1; - private static UnitType unitType2; - private static MockRaceFactory raceFactory = new MockRaceFactory(); - - [TestFixtureSetUp()] - public void Setup() - { - race = new MockRace(); - unitType1 = new UnitType(typeID1, "Unit 1", race); - race.AddUnitType(unitType1); - unitType2 = new UnitType(typeID2, "Unit 2", race); - race.AddUnitType(unitType2); - } - - [Test()] - public void TestCreatesRequirement() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null); - } - - [Test()] - public void TestCreatesCorrectRequirement() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); - expectedReq.AddUnitTypeRequirement(unitType1); - IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory); - Assert.That(req, Is.EqualTo(expectedReq)); - } - - [Test()] - public void TestCreatesCorrectRequirementForTwoIDs() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); - expectedReq.AddUnitTypeRequirement(unitType1); - expectedReq.AddUnitTypeRequirement(unitType2); - IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); - Assert.That(req, Is.EqualTo(expectedReq)); - } - - [Test()] - public void TestCreatesCorrectRequirementWithNumber() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); - expectedReq.AddUnitTypeRequirement(unitType1, 2); - IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory); - Assert.That(req, Is.EqualTo(expectedReq)); - } - - [Test()] - public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); - expectedReq.AddUnitTypeRequirement(unitType1, 2); - expectedReq.AddUnitTypeRequirement(unitType2, 3); - IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory); - Assert.That(req, Is.EqualTo(expectedReq)); - } - - [Test()] - public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); - expectedReq.AddUnitTypeRequirement(unitType1, 2); - expectedReq.AddUnitTypeRequirement(unitType2); - IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory); - Assert.That(req, Is.EqualTo(expectedReq)); - } - - [Test()] - public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - UnitRequiresNoMoreThanNOfUnitTypeRequirement expectedReq = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType); - expectedReq.AddUnitTypeRequirement(unitType1); - expectedReq.AddUnitTypeRequirement(unitType2, 3); - IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory); - Assert.That(req, Is.EqualTo(expectedReq)); - } - - [Test()] - [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires at least N units' requirement")] - public void TestExceptionsForInvalidID() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - factory.CreateRequirement(unitType, "fibble", raceFactory); - } - - [Test()] - [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid amount 'a' for unit type 'unit1' for 'Requires at least N units' requirement")] - public void TestExceptionsForInvalidNumber() - { - UnitRequiresNoMoreThanNUnitsRequirementFactory factory = new UnitRequiresNoMoreThanNUnitsRequirementFactory(); - UnitType unitType = new UnitType("testUnit", "Test Unit", race); - factory.CreateRequirement(unitType, typeID1+":a", raceFactory); - } - } -} -
--- a/IBBoard.WarFoundry.API.Tests.csproj Sun Nov 13 20:49:37 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sun Nov 13 20:53:55 2011 +0000 @@ -112,7 +112,7 @@ <Compile Include="API\Objects\UnitEquipmentLimitTests.cs" /> <Compile Include="API\Objects\UnitEquipmentRatioSelectionTests.cs" /> <Compile Include="API\Objects\UnitEquipmentNumericSelectionTests.cs" /> - <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNUnitsRequirementFactoryTest.cs" /> + <Compile Include="API\Factories\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementFactoryTest.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />