annotate API/Objects/ArmyTests.cs @ 205:d39682a98adf

Re #379: Fix validation of requirements to check for unit * Add unit tests for army object * Update tests that check the message
author IBBoard <dev@ibboard.co.uk>
date Sun, 29 Jan 2012 19:40:19 +0000
parents
children e173c5512067
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
205
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (ArmyTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // 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.
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using NUnit.Framework;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Objects.Requirement.Mock;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using NUnit.Framework.SyntaxHelpers;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Collections.Generic;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.WarFoundry.API.Objects.Requirement;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.WarFoundry.API.Objects.Mock;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 namespace IBBoard.WarFoundry.API.Objects
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 [TestFixture()]
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 public class ArmyTests
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private MockRace mockRace;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private UnitType unitType1;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private IRequirement unitType1Requirement;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private UnitType unitType2;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 private IRequirement unitType2Requirement;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 private UnitType unitType3;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 private IRequirement unitType3Requirement;
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 [TestFixtureSetUp()]
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 public void SetupRace()
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 {
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 mockRace = new MockRace();
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 unitType1 = new MockUnitType("type1", "Unit Type 1");
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 mockRace.AddUnitType(unitType1);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 unitType1Requirement = new PassingRequirement();
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 unitType1.AddRequirement(unitType1Requirement);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 unitType2 = new MockUnitType("type2", "Unit Type 2");
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 mockRace.AddUnitType(unitType2);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 unitType2Requirement = new FailingRequirement();
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 unitType2.AddRequirement(unitType2Requirement);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 unitType3 = new MockUnitType("type3", "Unit Type 3");
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 mockRace.AddUnitType(unitType3);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 unitType3Requirement = new NotApplicableRequirement();
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 unitType3.AddRequirement(unitType3Requirement);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 [Test()]
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 public void TestGetRequirementsGetsAllRaceRequirements()
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 {
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 Army army = new Army(mockRace, "Test", 1000);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 ICollection<IRequirement> requirements = army.GetRequirements();
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 Assert.That(requirements, Has.Count(3));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 Assert.That(requirements, Has.Member(unitType1Requirement));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 Assert.That(requirements, Has.Member(unitType2Requirement));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 Assert.That(requirements, Has.Member(unitType3Requirement));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 [Test()]
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 public void TestGetRequirementsGetsJustAddedUnitRequirementsWithEmptyArmy()
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 {
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 Army army = new Army(mockRace, "Test", 1000);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 ICollection<IRequirement> requirements = army.GetAddingUnitRequirements(unitType1);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 Assert.That(requirements, Has.Count(1));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 Assert.That(requirements, Has.Member(unitType1Requirement));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 }
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 [Test()]
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 public void TestGetRequirementsGetsAddedUnitRequirementsAndExistingUnitRequirements()
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 {
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 Army army = new Army(mockRace, "Test", 1000);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 army.AddUnit(new Unit(unitType1, army.GetCategory(unitType1.MainCategory)));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 ICollection<IRequirement> requirements = army.GetAddingUnitRequirements(unitType2);
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 Assert.That(requirements, Has.Count(2));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 Assert.That(requirements, Has.Member(unitType1Requirement));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 Assert.That(requirements, Has.Member(unitType2Requirement));
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 }
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }
d39682a98adf Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75