annotate API/Objects/RaceTests.cs @ 227:d8cd6b259a9f

Re #359: Add "only contained" attribute to unit types * Test to make sure sub-units are removed from the army
author IBBoard <dev@ibboard.co.uk>
date Mon, 16 Apr 2012 20:45:45 +0100
parents 49480e1a8f90
children e173c5512067
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
1 // This file (RaceTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
126
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
6571b6483d2d * Set target framework to v2.0...AGAIN
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.
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
5 using NUnit.Framework;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
6 using IBBoard.WarFoundry.API.Objects.Mock;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
7 using NUnit.Framework.SyntaxHelpers;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
8 using IBBoard.WarFoundry.API.Objects.Requirement;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
9 using System.Collections.Generic;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
10 using IBBoard.NUnit;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
11 using System.Reflection;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
12 using IBBoard.WarFoundry.API.Factories;
126
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 namespace IBBoard.WarFoundry.API.Objects
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 [TestFixture()]
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
17 public class RaceTests : AbstractEqualityTest<Race>
126
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 [Test()]
127
779ad76c2644 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 126
diff changeset
20 public void TestRaceWithNoUnitTypesHasNoRequirements()
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
21 {
127
779ad76c2644 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 126
diff changeset
22 Assert.That(new MockRace().GetRequirements(), Has.Count(0));
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
23 }
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
24
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
25 [Test()]
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
26 public void TestRaceWithOneUnitTypeHasNoRequirements()
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
27 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
28 MockRace race = new MockRace();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
29 race.AddUnitType(new MockUnitType());
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
30 Assert.That(race.GetRequirements(), Has.Count(0));
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
31 }
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
32
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
33 [Test()]
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
34 public void TestRaceWithOneUnitTypeWithOneRequirementHasOneRequirement()
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
35 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
36 MockRace race = new MockRace();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
37 MockUnitType unitType = new MockUnitType();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
38 UnitRequiresAtLeastNUnitsRequirement unitRequirement = new UnitRequiresAtLeastNUnitsRequirement(unitType);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
39 unitType.AddRequirement(unitRequirement);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
40 race.AddUnitType(unitType);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
41 ICollection<IRequirement> raceRequirements = race.GetRequirements();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
42 Assert.That(raceRequirements, Has.Count(1));
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
43 Assert.That(raceRequirements, Has.All.EqualTo(unitRequirement));
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
44 }
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
45
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
46 [Test()]
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
47 public void TestRaceWithTwoUnitTypesWithMultipleRequirementsHasMultipleRequirements()
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
48 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
49 MockRace race = new MockRace();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
50 MockUnitType unitType1 = new MockUnitType("type1", "Type 1");
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
51 UnitRequiresAtLeastNUnitsRequirement unitRequirement1 = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
52 unitType1.AddRequirement(unitRequirement1);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
53 UnitRequiresNoMoreThanNOfUnitTypeRequirement unitRequirement2 = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
54 unitType1.AddRequirement(unitRequirement2);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
55 race.AddUnitType(unitType1);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
56 MockUnitType unitType2 = new MockUnitType("type2", "Type 2");
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
57 UnitRequiresAtLeastNUnitsRequirement unitRequirement3 = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
58 unitType2.AddRequirement(unitRequirement3);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
59 race.AddUnitType(unitType2);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
60 ICollection<IRequirement> raceRequirements = race.GetRequirements();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
61 Assert.That(raceRequirements, Has.Count(3));
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
62 Assert.That(raceRequirements, Has.Member(unitRequirement1));
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
63 Assert.That(raceRequirements, Has.Member(unitRequirement2));
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
64 Assert.That(raceRequirements, Has.Member(unitRequirement3));
224
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
65 }
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
66
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
67 [Test()]
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
68 public void TestContainedOnlyUnitsAreNotReturned()
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
69 {
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
70 MockRace race = new MockRace();
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
71 MockUnitType unitType1 = new MockUnitType("type1", "Type 1");
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
72 race.AddUnitType(unitType1);
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
73 MockContainedUnitType unitType2 = new MockContainedUnitType("type2", "Type 2");
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
74 race.AddUnitType(unitType2);
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
75 unitType1.AddContainedUnitType(unitType2);
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
76 Assert.That(race.GetUnitTypes(MockCategory.GetCategory()), Has.Length(1));
49480e1a8f90 Re #359: Add "only contained" attribute to unit types
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
77 Assert.That(race.GetUnitTypes(MockCategory.GetCategory()), Has.Member(unitType1));
129
95dac00e9330 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 127
diff changeset
78 }
95dac00e9330 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 127
diff changeset
79
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
80 public override Race GetObject ()
129
95dac00e9330 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 127
diff changeset
81 {
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
82 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
83 GameSystem gameSystem = new GameSystem("system", "system", factory);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
84 return new Race("race", "race", gameSystem, factory);
129
95dac00e9330 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 127
diff changeset
85 }
95dac00e9330 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 127
diff changeset
86
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
87 public override Race GetSameObject ()
129
95dac00e9330 Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 127
diff changeset
88 {
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
89 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
90 GameSystem gameSystem = new GameSystem("system", "system", factory);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
91 return new Race("race", "race", gameSystem, factory);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
92 }
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
93
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
94 public override Race GetDifferentObject ()
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
95 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
96 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
97 GameSystem gameSystem = new GameSystem("system2", "another system", factory);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 129
diff changeset
98 return new Race("race2", "other race", gameSystem, factory);
126
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 }
139
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
100
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
101 public Race GetOtherDifferentObjectWithSubID()
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
102 {
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
103 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
104 GameSystem gameSystem = new GameSystem("system", "system", factory);
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
105 return new Race("race", "subid", "race", gameSystem, factory);
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
106 }
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
107
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
108 public Race GetOtherDifferentObjectWithGameSystem()
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
109 {
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
110 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
111 GameSystem gameSystem = new GameSystem("system2", "system", factory);
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
112 return new Race("race", "race", gameSystem, factory);
3e4864e206ea Re #140: Equality methods
IBBoard <dev@ibboard.co.uk>
parents: 137
diff changeset
113 }
126
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 }
6571b6483d2d * Set target framework to v2.0...AGAIN
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116