changeset 172:c026c02583ca

* 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
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Sep 2011 11:46:20 +0100
parents 14d0450f295d
children f31b364f9b04
files API/Exporters/XmlSaveTest.cs API/Objects/Mock/MockArmy.cs API/Objects/UnitTest.cs API/Savers/IWarFoundryFileSaverTests.cs API/Util/UnitEquipmentUtilTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 6 files changed, 23 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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";
 		}
--- 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;
--- 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()));
 		}
--- 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));
 		}
 	}
 }
--- 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 @@
     <Compile Include="API\Factories\Mock\MockSystemFactory.cs" />
     <Compile Include="API\Objects\Mock\MockGameSystem.cs" />
     <Compile Include="API\Objects\UnitTest.cs" />
-    <Compile Include="API\Objects\Mock\MockArmyCategory.cs" />
     <Compile Include="API\Objects\Mock\MockArmy.cs" />
     <Compile Include="API\Objects\Mock\MockCategory.cs" />
     <Compile Include="API\Objects\Mock\MockNumericAmountUnitEquipmentItem.cs" />