Mercurial > repos > IBBoard.WarFoundry.API.Tests
view API/Objects/Requirement/RequirementHandlerTests.cs @ 146:8c519a44e699
Re #345: Add failure message to requirements
* Add testing of failure messages for "allows adding"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 01 May 2011 19:17:11 +0000 |
parents | 0d40d80226b8 |
children |
line wrap: on
line source
// 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; using System.Collections.Generic; 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)); } [Test()] public void TestArmyWithMixedRequirementsWithFailFails() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new PassingRequirement()); 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 TestArmyWithMixedRequirementsWithFailInOtherOrderFails() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new FailingRequirement()); mockUnitType.AddRequirement(new PassingRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Failed)); } [Test()] public void TestArmyWithMixedRequirementsWithNoFailsPasses() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new PassingRequirement()); mockUnitType.AddRequirement(new NotApplicableRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); Assert.That(RequirementHandler.ValidateArmy(army), Is.EqualTo(Validation.Passed)); } [Test()] public void TestCanAddToArmyWithNoRequirementsValidates() { MockRace race = new MockRace(); Army army = new Army(race, "test", 1000); Assert.That(RequirementHandler.AllowsAdding(new MockUnitType(), army), Is.EqualTo(Validation.Passed)); } [Test()] public void TestCanAddToArmyWithFailingRequirementFails() { 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.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed)); } [Test()] public void TestCanAddToArmyWithPassingRequirementPasses() { 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.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed)); } [Test()] public void TestCanAddToArmyWithNotApplicableRequirementPasses() { 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.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed)); } [Test()] public void TestCanAddToArmyWithMixedRequirementsWithFailFails() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new PassingRequirement()); mockUnitType.AddRequirement(new FailingRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed)); } [Test()] public void TestCanAddToArmyWithMixedRequirementsWithFailInOtherOrderFails() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new FailingRequirement()); mockUnitType.AddRequirement(new PassingRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Failed)); } [Test()] public void TestCanAddToArmyWithMixedRequirementsWithNoFailsPasses() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new PassingRequirement()); mockUnitType.AddRequirement(new NotApplicableRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); Assert.That(RequirementHandler.AllowsAdding(mockUnitType, army), Is.EqualTo(Validation.Passed)); } [Test()] public void TestArmyWithMixedRequirementsGetsExpectedFailureMessageCount() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new PassingRequirement()); mockUnitType.AddRequirement(new NotApplicableRequirement()); mockUnitType.AddRequirement(new FailingRequirement()); mockUnitType.AddRequirement(new FailingRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); ICollection<string> failureMessages; RequirementHandler.ValidateArmy(army, out failureMessages); Assert.That(failureMessages, Has.Count(2)); } [Test()] public void TestAddingToArmyWithMixedRequirementsGetsExpectedFailureMessageCount() { MockRace race = new MockRace(); MockUnitType mockUnitType = new MockUnitType(); mockUnitType.AddRequirement(new PassingRequirement()); mockUnitType.AddRequirement(new NotApplicableRequirement()); mockUnitType.AddRequirement(new FailingRequirement()); mockUnitType.AddRequirement(new FailingRequirement()); race.AddUnitType(mockUnitType); Army army = new Army(race, "test", 1000); ICollection<string> failureMessages; RequirementHandler.AllowsAdding(mockUnitType, army, out failureMessages); Assert.That(failureMessages, Has.Count(2)); } } }