# HG changeset patch # User IBBoard # Date 1316861180 -3600 # Node ID c026c02583cab526c6e9b16e7d8a9ff22348aa74 # Parent 14d0450f295d7bb62b38fecd97747cd28d4733c0 * Remove MockArmy.GetMockArmy as it only causes problems in unit tests * Remove MockArmyCategory as MockArmy change would make it do nothing special * Close streams as well as files to fix Windows unit test errors diff -r 14d0450f295d -r c026c02583ca API/Exporters/XmlSaveTest.cs --- a/API/Exporters/XmlSaveTest.cs Tue Sep 13 20:49:06 2011 +0100 +++ b/API/Exporters/XmlSaveTest.cs Sat Sep 24 11:46:20 2011 +0100 @@ -26,10 +26,10 @@ [TestFixtureSetUp()] public void XmlTestSetup() { - mockArmy = MockArmy.GetMockArmy(); + mockArmy = new MockArmy(); UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(mockArmy, unitType.MainCategory)); mockArmy.AddUnit(unit); WarFoundryXmlWithXslExporter.GetDefault().ExportArmy(mockArmy, outputFile); diff -r 14d0450f295d -r c026c02583ca API/Objects/Mock/MockArmy.cs --- a/API/Objects/Mock/MockArmy.cs Tue Sep 13 20:49:06 2011 +0100 +++ b/API/Objects/Mock/MockArmy.cs Sat Sep 24 11:46:20 2011 +0100 @@ -8,19 +8,7 @@ { public class MockArmy : Army { - private static MockArmy mockArmy; - - public static MockArmy GetMockArmy () - { - if (mockArmy == null) - { - mockArmy = new MockArmy (); - } - - return mockArmy; - } - - private MockArmy () : base(MockRace.GetMockRace (), "Mock Army", 2000) + public MockArmy() : base(MockRace.GetMockRace(), "Mock Army", 2000) { ID = "MockArmy"; } diff -r 14d0450f295d -r c026c02583ca API/Objects/UnitTest.cs --- a/API/Objects/UnitTest.cs Tue Sep 13 20:49:06 2011 +0100 +++ b/API/Objects/UnitTest.cs Sat Sep 24 11:46:20 2011 +0100 @@ -19,7 +19,7 @@ UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); Assert.IsTrue(equip.MaxLimit is Limits.NumericSizeConstrainedLimit); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentAmount(equip, 5); Assert.AreEqual(5, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); Assert.IsFalse(UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip)); @@ -30,7 +30,7 @@ { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentAmount(equip, 5); unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); @@ -41,7 +41,7 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); Assert.AreEqual(50, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); Assert.IsTrue(UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip)); @@ -52,7 +52,7 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); unit.SetEquipmentRatio(equip, 0); Assert.AreEqual(0, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); @@ -63,7 +63,7 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 5, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.Size = 5; unit.SetEquipmentAmount(equip, 2); Assert.AreEqual(2, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); @@ -75,7 +75,7 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 5, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentAmount(equip, 2); unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); @@ -85,7 +85,7 @@ public void TestAmountInSlotWithNoItems() { UnitType unitType = new MockUnitType(); - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); Assert.AreEqual(0, unit.GetEquipmentAmountInSlot("")); } @@ -96,7 +96,7 @@ string slotName = "TestSlot"; equip.SlotName = slotName; UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 5, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.Size = 5; unit.SetEquipmentRatio(equip, 50); Assert.AreEqual(2, unit.GetEquipmentAmountInSlot(slotName)); @@ -109,7 +109,7 @@ string slotName = "TestSlot"; equip1.SlotName = slotName; UnitType unitType = equip1.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip1, 50); UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); equip2.SlotName = slotName; @@ -129,7 +129,7 @@ string slotName = "TestSlot"; equip.SlotName = slotName; UnitType unitType = equip.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 5, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); unit.SetEquipmentRatio(equip, 0); Assert.AreEqual(0, unit.GetEquipmentAmountInSlot(slotName)); @@ -142,7 +142,7 @@ string slotName = "TestSlot"; equip1.SlotName = slotName; UnitType unitType = equip1.EquipmentForUnit; - Unit unit = new Unit("unit", "Test Unit", 10, unitType, new MockArmyCategory(unitType.MainCategory)); + Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip1, 50); UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); equip2.SlotName = slotName; diff -r 14d0450f295d -r c026c02583ca API/Savers/IWarFoundryFileSaverTests.cs --- a/API/Savers/IWarFoundryFileSaverTests.cs Tue Sep 13 20:49:06 2011 +0100 +++ b/API/Savers/IWarFoundryFileSaverTests.cs Sat Sep 24 11:46:20 2011 +0100 @@ -128,12 +128,13 @@ string tempFile = Path.GetTempFileName(); try { - MockArmy obj = MockArmy.GetMockArmy(); + MockArmy obj = new MockArmy(); GetSaver().Save(tempFile, obj); ZipFile file = new ZipFile(tempFile); ZipEntry zipEntry = file.GetEntry(GetEntryName(obj)); Stream stream = file.GetInputStream(zipEntry); - Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); + Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); + stream.Close(); file.Close(); } finally @@ -151,7 +152,7 @@ string tempFile = Path.GetTempFileName(); try { - GetSaver().Save(tempFile, new MockGameSystem(), MockArmy.GetMockArmy()); + GetSaver().Save(tempFile, new MockGameSystem(), new MockArmy()); ZipFile file = new ZipFile(tempFile); Assert.That(file.Count, Is.EqualTo(2)); file.Close(); @@ -173,7 +174,7 @@ try { MockGameSystem system = new MockGameSystem(); - MockArmy army = MockArmy.GetMockArmy(); + MockArmy army = new MockArmy(); GetSaver().Save(tempFile, system, army); ZipFile file = new ZipFile(tempFile); ZipEntry zipEntry = file.GetEntry(GetEntryName(system)); @@ -181,7 +182,8 @@ Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetGameSystemContentBytes())); zipEntry = file.GetEntry(GetEntryName(army)); stream = file.GetInputStream(zipEntry); - Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); + Assert.That(StreamUtil.ToBytes(stream), Is.EqualTo(GetArmyContentBytes())); + stream.Close(); file.Close(); } finally @@ -243,7 +245,7 @@ [Test()] public void TestFileExtensionsAreCorrectForType() { - Assert.That(GetSaver().GetFileExtension(MockArmy.GetMockArmy()), Is.EqualTo(GetArmyExtension())); + Assert.That(GetSaver().GetFileExtension(new MockArmy()), Is.EqualTo(GetArmyExtension())); Assert.That(GetSaver().GetFileExtension(new MockRace()), Is.EqualTo(GetRaceExtension())); Assert.That(GetSaver().GetFileExtension(new MockGameSystem()), Is.EqualTo(GetGameSystemExtension())); } diff -r 14d0450f295d -r c026c02583ca API/Util/UnitEquipmentUtilTest.cs --- a/API/Util/UnitEquipmentUtilTest.cs Tue Sep 13 20:49:06 2011 +0100 +++ b/API/Util/UnitEquipmentUtilTest.cs Sat Sep 24 11:46:20 2011 +0100 @@ -430,7 +430,7 @@ private Unit GetUnit (UnitType unitType) { - return new Unit ("unit", "Test Unit", 15, unitType, new MockArmyCategory (unitType.MainCategory)); + return new Unit ("unit", "Test Unit", 15, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); } } } diff -r 14d0450f295d -r c026c02583ca IBBoard.WarFoundry.API.Tests.csproj --- a/IBBoard.WarFoundry.API.Tests.csproj Tue Sep 13 20:49:06 2011 +0100 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sat Sep 24 11:46:20 2011 +0100 @@ -69,7 +69,6 @@ -