Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Objects/Requirement/AbstractUnitRequirementTest.cs @ 239:370bec16a364 default tip
Add initial testing for equipment with type (incomplete)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 16 Oct 2016 20:29:35 +0100 |
parents | e173c5512067 |
children |
line wrap: on
line source
// This file (AbstractUnitRequirementTest.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; using NUnit.Framework; using IBBoard.NUnit; using System.Collections.Generic; namespace IBBoard.WarFoundry.API.Objects.Requirement { /// <summary> /// Base class of helper methods for checking unit requirements /// </summary> public abstract class AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractEqualityTest<TEST_CLASS> where OBJECT_TYPE : IWarFoundryObject where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE> { protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army) { Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Passed)); Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty); Unit unit = CreateUnitOfType(unitType, army); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty); } protected static void Assert_That__AddingNotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army) { Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.NotApplicable)); Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.Empty); Unit unit = CreateUnitOfType(unitType, army); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); Assert.That(req.GetAllowsAddingMessage(unit, army), Is.Empty); } protected static void Assert_That__FailsAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army, string message) { Assert.That(req.AllowsAdding(unitType, army), Is.EqualTo(Validation.Failed)); Assert.That(req.GetAllowsAddingMessage(unitType, army), Is.EqualTo(message)); Unit unit = CreateUnitOfType(unitType, army); Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); Assert.That(req.GetAllowsAddingMessage(unit, army), Is.EqualTo(message)); } protected static void Assert_That__ValidationPasses(AbstractUnitRequirement<OBJECT_TYPE> req, Army army) { Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); Assert.That(req.GetValidationMessage(army), Is.Empty); } protected static void Assert_That__NotApplicable(AbstractUnitRequirement<OBJECT_TYPE> req, Army army) { Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); Assert.That(req.GetValidationMessage(army), Is.Empty); } protected static void Assert_That__ValidationFails(AbstractUnitRequirement<OBJECT_TYPE> req, Army army, string message) { Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); Assert.That(req.GetValidationMessage(army), Is.EqualTo(message)); } protected static ICollection<Unit> AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army) { ICollection<Unit> units = new List<Unit>(); for (int i = 0; i < count; i++) { units.Add(AddUnitOfTypeToArmy(unitType, army)); } return units; } protected static Unit AddUnitOfTypeToArmy(UnitType unitType, Army army) { Unit unit = CreateUnitOfType(unitType, army); army.AddUnit(unit); return unit; } protected static Unit AddUnitOfTypeToArmy(UnitType unitType, Army army, string name) { Unit unit = AddUnitOfTypeToArmy(unitType, army); unit.Name = name; return unit; } protected static Unit CreateUnitOfType(UnitType unitType, Army army) { return new Unit(unitType, army.GetCategory(unitType.MainCategory)); } } }