Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 16:74346d5c17fe
Re #198: Add slots with counts to units
* Add tests for equipment slot amount storage and retrieval
* Add extra constructors to some mocks for constructing other objects of same type
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Oct 2009 14:02:50 +0000 |
parents | 1119b6f48e8e |
children | 4480d7151d35 |
files | API/Objects/Mock/MockEquipmentItem.cs API/Objects/Mock/MockPercentageAmountUnitEquipmentItem.cs API/Objects/UnitTest.cs |
diffstat | 3 files changed, 53 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Mock/MockEquipmentItem.cs Sat Oct 24 13:26:37 2009 +0000 +++ b/API/Objects/Mock/MockEquipmentItem.cs Sat Oct 24 14:02:50 2009 +0000 @@ -9,7 +9,11 @@ { public class MockEquipmentItem : EquipmentItem { - public MockEquipmentItem () : base("mockequip", "Mock Equipment Item", new MockRace()) + public MockEquipmentItem () : this("mockequip") + { + } + + public MockEquipmentItem(string id) : base(id, "Mock Equipment Item"+id, MockRace.GetMockRace()) { } }
--- a/API/Objects/Mock/MockPercentageAmountUnitEquipmentItem.cs Sat Oct 24 13:26:37 2009 +0000 +++ b/API/Objects/Mock/MockPercentageAmountUnitEquipmentItem.cs Sat Oct 24 14:02:50 2009 +0000 @@ -3,13 +3,17 @@ // 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 IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Objects.Mock { public class MockPercentageAmountUnitEquipmentItem : UnitEquipmentItem { - - public MockPercentageAmountUnitEquipmentItem () : base(new MockEquipmentItem(), new MockUnitType()) + public MockPercentageAmountUnitEquipmentItem () : this(new MockEquipmentItem(), new MockUnitType()) + { + } + + public MockPercentageAmountUnitEquipmentItem(EquipmentItem item, UnitType type) : base(item, type) { MaxPercentage = 50; }
--- a/API/Objects/UnitTest.cs Sat Oct 24 13:26:37 2009 +0000 +++ b/API/Objects/UnitTest.cs Sat Oct 24 14:02:50 2009 +0000 @@ -78,5 +78,47 @@ unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, unit.GetEquipmentAmount(equip)); } + + [Test()] + public void TestAmountInSlotWithNoItems() + { + UnitType unitType = new MockUnitType(); + Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory)); + Assert.AreEqual(0, unit.GetEquipmentAmountInSlot("")); + } + + [Test()] + public void TestAmountInSlotWithOneItem() + { + UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); + string slotName = "TestSlot"; + equip.SlotName = slotName; + UnitType unitType = equip.EquipmentForUnit; + Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory)); + unit.Size = 5; + unit.SetEquipmentRatio(equip, 50); + Assert.AreEqual(2, unit.GetEquipmentAmountInSlot(slotName)); + } + + [Test()] + public void TestAmountInSlotWithMultipleItems() + { + UnitEquipmentItem equip1 = new MockPercentageAmountUnitEquipmentItem(); + string slotName = "TestSlot"; + equip1.SlotName = slotName; + UnitType unitType = equip1.EquipmentForUnit; + Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory)); + unit.Size = 10; + unit.SetEquipmentRatio(equip1, 50); + UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); + equip2.SlotName = slotName; + equip2.MinPercentage = 0; + UnitEquipmentItem equip3 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip3"), unitType); + equip3.SlotName = slotName; + equip3.MinPercentage = 0; + unit.SetEquipmentRatio(equip2, 25); + unit.SetEquipmentRatio(equip3, 10); + Assert.AreEqual(8, unit.GetEquipmentAmountInSlot(slotName)); + } } }