view API/Objects/Requirement/RequiresNUnitsForMObjectsRequirementTest.cs @ 210:649759343da5

Re #379: Fix validation of requirements to check for unit * Tidy up tests to reduce replication and fix copy-and-paste inconsistencies
author IBBoard <dev@ibboard.co.uk>
date Sat, 25 Feb 2012 16:36:20 +0000
parents c323770e61c2
children
line wrap: on
line source

// 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);
	}
}