annotate API/Objects/UnitTypeTest.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (UnitTypeTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2010 IBBoard
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
73308371f9d8 Re #270: Add multiple categories to API
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.
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using IBBoard.WarFoundry.API.Objects.Mock;
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using NUnit.Framework;
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using NUnit.Framework.Constraints;
128
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
7 using IBBoard.WarFoundry.API.Objects.Requirement;
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
8 using System.Reflection;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
9 using IBBoard.NUnit;
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
10 using IBBoard.WarFoundry.API.Factories;
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 namespace IBBoard.WarFoundry.API.Objects
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 [TestFixture()]
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
15 public class UnitTypeTest : AbstractEqualityTest<UnitType>
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 [Test()]
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 public void TestSettingMainCategorySetsCategoriesCollection()
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
21 MockCategory mockCategory = MockCategory.GetCategory();
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 unitType.MainCategory = mockCategory;
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 Assert.That(unitType.Categories, Has.Member(mockCategory));
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 }
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 [Test()]
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 public void TestAddingFirstCategorySetsMainCategory()
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
30 MockCategory mockCategory = MockCategory.GetCategory();
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 unitType.AddCategory(mockCategory);
49
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
32 Assert.That(unitType.Categories.Length, Is.EqualTo(1));
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 Assert.That(unitType.Categories, Has.Member(mockCategory));
49
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
34 Assert.That(unitType.MainCategory, Is.EqualTo(mockCategory));
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
35 }
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
36
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
37 [Test()]
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
38 public void TestAddingMultipleCategoriesSetsMainCategory()
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
39 {
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
40 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
41 MockCategory mockCategory = MockCategory.GetCategory();
49
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
42 unitType.AddCategory(mockCategory);
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
43 Category mockCategory2 = new Category("id1", "CatName");
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
44 unitType.AddCategory(mockCategory2);
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
45 Assert.That(unitType.Categories.Length, Is.EqualTo(2));
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
46 Assert.That(unitType.Categories, Has.Member(mockCategory));
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
47 Assert.That(unitType.Categories, Has.Member(mockCategory2));
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 Assert.That(unitType.MainCategory, Is.EqualTo(mockCategory));
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 }
128
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
50
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
51 [Test]
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
52 public void TestAddingRequirementsToUnitType()
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
53 {
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
54 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
55 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType);
238
e173c5512067 * Update to v2.6 of NUnit and new syntax/API changes
IBBoard <dev@ibboard.co.uk>
parents: 218
diff changeset
56 Assert.That(unitType.GetRequirements(), Has.Length.EqualTo(0));
128
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
57 unitType.AddRequirement(req);
238
e173c5512067 * Update to v2.6 of NUnit and new syntax/API changes
IBBoard <dev@ibboard.co.uk>
parents: 218
diff changeset
58 Assert.That(unitType.GetRequirements(), Has.Length.EqualTo(1));
128
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
59 }
136
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
60
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
61 [Test]
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
62 public void TestGetRequirementsGetsUnitCountRequirements()
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
63 {
216
442bcf7306b9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
64 MockRace mockRace = new MockRace();
442bcf7306b9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
65 UnitType unitType = new UnitType("unittype1", "Swordsmen", mockRace);
136
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
66 unitType.MinNumber = 1;
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
67 unitType.MaxNumber = 2;
238
e173c5512067 * Update to v2.6 of NUnit and new syntax/API changes
IBBoard <dev@ibboard.co.uk>
parents: 218
diff changeset
68 Assert.That(unitType.GetRequirements(), Has.Length.EqualTo(2));
218
d60d93b787dc Re #379: Fix requirements
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
69 RaceRequiresNoMoreThanNUnitsRequirement maxLimit = new RaceRequiresNoMoreThanNUnitsRequirement(mockRace);
216
442bcf7306b9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
70 maxLimit.AddUnitTypeRequirement(unitType, 2);
442bcf7306b9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
71 Assert.That(unitType.GetRequirements(), Has.Member(maxLimit));
218
d60d93b787dc Re #379: Fix requirements
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
72 RaceRequiresAtLeastNUnitsRequirement minLimit = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
216
442bcf7306b9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
73 minLimit.AddUnitTypeRequirement(unitType, 1);
442bcf7306b9 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 208
diff changeset
74 Assert.That(unitType.GetRequirements(), Has.Member(minLimit));
136
d28c3c1ec1ec Re #27: Unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 128
diff changeset
75 }
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
76
208
c323770e61c2 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
77 public override UnitType GetObject()
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
78 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
79 return new UnitType("id1", "Type 1", new MockRace());
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
80 }
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
81
208
c323770e61c2 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
82 public override UnitType GetSameObject()
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
83 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
84 return new UnitType("id1", "Type 1", new MockRace());
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
85 }
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
86
208
c323770e61c2 Re #379: Fix validation of requirements to check for unit
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
87 public override UnitType GetDifferentObject()
137
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
88 {
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
89 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
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: 136
diff changeset
91 Race race = new Race("race", "race", gameSystem, factory);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
92 return new UnitType("id2", "Type 2", race);
081b48413f6d Re #140: Add equality methods to WarFoundry objects
IBBoard <dev@ibboard.co.uk>
parents: 136
diff changeset
93 }
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 }
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 }
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96