annotate API/Objects/UnitTypeTest.cs @ 129:95dac00e9330

Re #27: Unit requirements * Test getting all unit requirements for race
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Apr 2011 19:13:42 +0000
parents 7ca536ccd27a
children d28c3c1ec1ec
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;
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using NUnit.Framework.SyntaxHelpers;
128
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
8 using IBBoard.WarFoundry.API.Objects.Requirement;
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 namespace IBBoard.WarFoundry.API.Objects
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 [TestFixture()]
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 public class UnitTypeTest
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 [Test()]
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public void TestSettingMainCategorySetsCategoriesCollection()
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
19 MockCategory mockCategory = MockCategory.GetCategory();
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 unitType.MainCategory = mockCategory;
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 Assert.That(unitType.Categories, Has.Member(mockCategory));
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 [Test()]
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 public void TestAddingFirstCategorySetsMainCategory()
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 {
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
28 MockCategory mockCategory = MockCategory.GetCategory();
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 unitType.AddCategory(mockCategory);
49
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
30 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
31 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
32 Assert.That(unitType.MainCategory, Is.EqualTo(mockCategory));
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
33 }
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
34
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
35 [Test()]
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
36 public void TestAddingMultipleCategoriesSetsMainCategory()
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
37 {
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
38 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
102
a3bc8174299f Re #27: Define unit requirements
IBBoard <dev@ibboard.co.uk>
parents: 49
diff changeset
39 MockCategory mockCategory = MockCategory.GetCategory();
49
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
40 unitType.AddCategory(mockCategory);
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
41 Category mockCategory2 = new Category("id1", "CatName");
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
42 unitType.AddCategory(mockCategory2);
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
43 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
44 Assert.That(unitType.Categories, Has.Member(mockCategory));
24a40c49b6ae Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
45 Assert.That(unitType.Categories, Has.Member(mockCategory2));
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 Assert.That(unitType.MainCategory, Is.EqualTo(mockCategory));
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 }
128
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
48
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
49 [Test]
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
50 public void TestAddingRequirementsToUnitType()
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
51 {
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
52 UnitType unitType = new UnitType("unittype1", "Swordsmen", new MockRace());
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
53 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType);
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
54 Assert.That(unitType.GetRequirements(), Has.Length(0));
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
55 unitType.AddRequirement(req);
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
56 Assert.That(unitType.GetRequirements(), Has.Length(1));
7ca536ccd27a Re #27:
IBBoard <dev@ibboard.co.uk>
parents: 102
diff changeset
57 }
46
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
73308371f9d8 Re #270: Add multiple categories to API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60