changeset 12:a4e7e938d065

Re #195: Setting max equipment without min may not function correctly * Initial commit of tests for limits (percentage and numeric) Also: * Reshuffle and refactoring of existing tests * Additional mocks required by the new tests
author IBBoard <dev@ibboard.co.uk>
date Mon, 12 Oct 2009 19:42:30 +0000
parents 8d9d49332d44
children ca5d7c2c7493
files API/Factories/Mock/MockSystemFactory.cs API/Objects/Mock/MockEquipmentItem.cs API/Objects/Mock/MockGameSystem.cs API/Objects/Mock/MockRace.cs API/Objects/Mock/MockUnitType.cs API/Objects/UnitEquipmentItemTest.cs API/WarFoundryLoaderTest.cs IBBoard.WarFoundry.API.Tests.csproj MockObjects/MockSystemFactory.cs WarFoundryFactoryTest.cs WarFoundryLoaderTest.cs
diffstat 11 files changed, 359 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Factories/Mock/MockSystemFactory.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,76 @@
+// This file (MockSystemFactory.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard.
+//
+// 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 System.IO;
+using IBBoard.WarFoundry.API.Factories;
+using IBBoard.WarFoundry.API.Objects;
+using ICSharpCode.SharpZipLib.Zip;
+
+namespace IBBoard.WarFoundry.API.Factories.Mock
+{
+	public class MockSystemFactory : AbstractNativeWarFoundryFactory
+	{
+		private static MockSystemFactory mock;
+		
+		public static MockSystemFactory GetMockFactory()
+		{
+			if (mock == null)
+			{
+				mock = new MockSystemFactory();
+			}
+			
+			return mock;
+		}
+		
+		public MockSystemFactory()
+		{
+		}
+		
+		protected override bool CheckCanFindArmyFileContent(ZipFile file)
+		{
+			return false;
+		}
+		
+		protected override bool CheckCanFindRaceFileContent(ZipFile file)
+		{
+			return false;
+		}
+		
+		protected override bool CheckCanFindSystemFileContent(ZipFile file)
+		{
+			return true;
+		}
+		
+		protected override Army CreateArmyFromStream (ZipFile file, Stream dataStream)
+		{
+			throw new NotImplementedException ();
+		}
+		
+		protected override GameSystem CreateGameSystemFromStream (ZipFile file, Stream dataStream)
+		{
+			return new GameSystem("test", "Test System", this);
+		}
+		
+		protected override Race CreateRaceFromStream (ZipFile file, Stream dataStream)
+		{
+			throw new NotImplementedException ();
+		}
+		
+		protected override Stream GetArmyDataStream (ZipFile file)
+		{
+			throw new NotImplementedException ();
+		}
+		
+		protected override Stream GetGameSystemDataStream (ZipFile file)
+		{
+			return new MemoryStream();
+		}
+
+		protected override Stream GetRaceDataStream (ZipFile file)
+		{
+			throw new NotImplementedException ();
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockEquipmentItem.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,16 @@
+// This file (MockEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
+// 
+// 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 MockEquipmentItem : EquipmentItem
+	{
+		public MockEquipmentItem () : base("mockequip",  "Mock Equipment Item", new MockRace())
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockGameSystem.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,29 @@
+// This file (MockGameSystem.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
+// 
+// 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.Factories.Mock;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Objects.Mock
+{
+	public class MockGameSystem : GameSystem
+	{
+		private static MockGameSystem mock;
+		
+		public static MockGameSystem GetMockSystem()
+		{
+			if (mock == null)
+			{
+				mock = new MockGameSystem();	
+			}
+			
+			return mock;
+		}
+		
+		public MockGameSystem () : base("mocksystem", "Mock Game System", MockSystemFactory.GetMockFactory())
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockRace.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,29 @@
+// This file (MockRace.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
+// 
+// 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.Factories.Mock;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Objects.Mock
+{
+	public class MockRace: Race
+	{
+		private static MockRace mock;
+		
+		public static MockRace GetMockRace()
+		{
+			if (mock == null)	
+			{
+				mock = new MockRace();
+			}
+			
+			return mock;
+		}
+		
+		public MockRace () : base("mockrace", "Mock Race", MockGameSystem.GetMockSystem(), MockSystemFactory.GetMockFactory())
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockUnitType.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,16 @@
+// This file (MockUnitType.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
+// 
+// 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 MockUnitType : UnitType
+	{
+		public MockUnitType () : base("mockunittype", "Mock Unit Type", MockRace.GetMockRace())
+		{
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/UnitEquipmentItemTest.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,122 @@
+// This file (UnitEquipmentItemTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
+// 
+// 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 NUnit.Framework;
+using IBBoard.WarFoundry.API.Objects.Mock;
+
+namespace IBBoard.WarFoundry.API.Objects
+{
+	[TestFixture()]
+	public class UnitEquipmentItemTest
+	{
+		[Test()]
+		public void DefaultMinMaxNumberLimitsAreZero()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			Assert.AreEqual(0, item.MinNumber);
+			Assert.AreEqual(0, item.MaxNumber);
+		}
+		
+		[Test()]
+		public void MinNumberLimitEqualsMaxLimitWhenOnlyMaxLimitSet()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MaxNumber = 1;
+			Assert.AreEqual(1, item.MinNumber);
+		}
+		
+		[Test()]
+		public void MinNumberLimitUntouchedWhenSetFirst()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MinNumber = 1;
+			item.MaxNumber = 10;
+			Assert.AreEqual(1, item.MinNumber);
+		}
+		
+		[Test()]
+		public void MinNumberLimitSetToMaxWhenMaxLessThanMin()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MinNumber = 10;
+			item.MaxNumber = 1;
+			Assert.AreEqual(1, item.MinNumber);
+		}
+		
+		[Test()]
+		public void MaxNumberLimitSetToMinWhenMinGreaterThanMax()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MaxNumber = 1;
+			item.MinNumber = 10;
+			Assert.AreEqual(10, item.MaxNumber);
+		}
+		
+		[Test()]
+		public void EqualNumberLimitsDoesntFail()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MaxNumber = 10;
+			item.MinNumber = 10;
+			item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MinNumber = 10;
+			item.MaxNumber = 10;
+		}
+		
+		[Test()]
+		public void DefaultMinMaxPercentageLimitsAreZero()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			Assert.AreEqual(0, item.MinPercentage);
+			Assert.AreEqual(0, item.MaxPercentage);
+		}
+		
+		[Test()]
+		public void MinPercentLimitEqualsMaxLimitWhenOnlyMaxLimitSet()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MaxPercentage = 50;
+			Assert.AreEqual(50, item.MinPercentage);
+		}
+		
+		[Test()]
+		public void MinPercentLimitUntouchedWhenSetFirst()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MinPercentage = 25;
+			item.MaxPercentage = 50;
+			Assert.AreEqual(25, item.MinPercentage);
+		}
+		
+		[Test()]
+		public void MinPercentLimitSetToMaxWhenMaxLessThanMin()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MinNumber = 50;
+			item.MaxPercentage = 25;
+			Assert.AreEqual(25, item.MinPercentage);
+		}
+		
+		[Test()]
+		public void MaxPercentLimitSetToMinWhenMinGreaterThanMax()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MaxPercentage = 25;
+			item.MinPercentage = 50;
+			Assert.AreEqual(50, item.MaxPercentage);
+		}
+		
+		[Test()]
+		public void EqualPercentLimitsDoesntFail()
+		{
+			UnitEquipmentItem item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MaxPercentage = 50;
+			item.MinPercentage = 50;
+			item = new UnitEquipmentItem(new MockEquipmentItem(), new MockUnitType());
+			item.MinPercentage = 50;
+			item.MaxPercentage = 50;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/WarFoundryLoaderTest.cs	Mon Oct 12 19:42:30 2009 +0000
@@ -0,0 +1,47 @@
+// This file (WarFoundryLoaderTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard.
+//
+// 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 System.IO;
+using NUnit.Framework;
+using IBBoard.WarFoundry.API.Factories.Mock;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Factories
+{
+	[TestFixture()]
+	public class WarFoundryLoaderTest
+	{
+		private AbstractNativeWarFoundryFactory sysFactory;
+				
+		[Test()]
+		public void TestLoadWithoutFactoriesCompletesWithoutError()
+		{
+			WarFoundryLoader.GetDefault().LoadFiles();
+		}
+		
+		[Test()]
+		public void TestLoadingSystemCompletesWithoutError()
+		{
+			WarFoundryLoader loader = WarFoundryLoader.GetDefault();
+			DirectoryInfo dir = new DirectoryInfo("testdata");
+			loader.RegisterFactory(GetSystemFactory());
+			loader.AddLoadDirectory(dir);
+			loader.LoadFiles();
+			Assert.Greater(loader.GetGameSystems().Length, 0);
+			loader.RemoveLoadDirectory(dir);
+			loader.UnregisterFactory(GetSystemFactory());
+		}
+				
+		private AbstractNativeWarFoundryFactory GetSystemFactory()
+		{
+			if (sysFactory == null)
+			{
+				sysFactory = new MockSystemFactory();
+			}
+			
+			return sysFactory;
+		}
+	}
+}
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Aug 15 10:39:26 2009 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Oct 12 19:42:30 2009 +0000
@@ -8,7 +8,7 @@
     <ProjectGuid>{B20E808D-878E-4F6D-B1E3-84A9A49905CB}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>IBBoard.WarFoundry.API.Tests</RootNamespace>
+    <RootNamespace>IBBoard.WarFoundry</RootNamespace>
     <AssemblyName>IBBoard.WarFoundry.API.Tests</AssemblyName>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -40,11 +40,15 @@
     <Content Include="libs\ICSharpCode.SharpZipLib.dll" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="MockObjects\MockSystemFactory.cs" />
     <Compile Include="MockObjects\MockRaceZipFile.cs" />
     <Compile Include="MockObjects\MockSystemZipFile.cs" />
-    <Compile Include="WarFoundryFactoryTest.cs" />
-    <Compile Include="WarFoundryLoaderTest.cs" />
+    <Compile Include="API\WarFoundryLoaderTest.cs" />
+    <Compile Include="API\Objects\UnitEquipmentItemTest.cs" />
+    <Compile Include="API\Objects\Mock\MockUnitType.cs" />
+    <Compile Include="API\Objects\Mock\MockEquipmentItem.cs" />
+    <Compile Include="API\Objects\Mock\MockRace.cs" />
+    <Compile Include="API\Factories\Mock\MockSystemFactory.cs" />
+    <Compile Include="API\Objects\Mock\MockGameSystem.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="testdata\Test.race">
@@ -68,4 +72,20 @@
       <Name>IBBoard.WarFoundry.API</Name>
     </ProjectReference>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="API\" />
+    <Folder Include="API\Objects\" />
+    <Folder Include="API\Objects\Mock\" />
+    <Folder Include="API\Factories\" />
+    <Folder Include="API\Factories\Mock\" />
+  </ItemGroup>
+  <ProjectExtensions>
+    <MonoDevelop>
+      <Properties>
+        <Policies>
+          <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="FileFormatDefault" />
+        </Policies>
+      </Properties>
+    </MonoDevelop>
+  </ProjectExtensions>
 </Project>
\ No newline at end of file
--- a/MockObjects/MockSystemFactory.cs	Sat Aug 15 10:39:26 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-// This file (MockSystemFactory.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard.
-//
-// 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 System.IO;
-using IBBoard.WarFoundry.API.Objects;
-using ICSharpCode.SharpZipLib.Zip;
-
-namespace IBBoard.WarFoundry.API.Factories
-{
-	public class MockSystemFactory : AbstractNativeWarFoundryFactory
-	{		
-		public MockSystemFactory()
-		{
-		}
-		
-		protected override bool CheckCanFindArmyFileContent(ZipFile file)
-		{
-			return false;
-		}
-		
-		protected override bool CheckCanFindRaceFileContent(ZipFile file)
-		{
-			return false;
-		}
-		
-		protected override bool CheckCanFindSystemFileContent(ZipFile file)
-		{
-			return true;
-		}
-		
-		protected override Army CreateArmyFromStream (ZipFile file, Stream dataStream)
-		{
-			throw new NotImplementedException ();
-		}
-		
-		protected override GameSystem CreateGameSystemFromStream (ZipFile file, Stream dataStream)
-		{
-			return new GameSystem("test", "Test System", this);
-		}
-		
-		protected override Race CreateRaceFromStream (ZipFile file, Stream dataStream)
-		{
-			throw new NotImplementedException ();
-		}
-		
-		protected override Stream GetArmyDataStream (ZipFile file)
-		{
-			throw new NotImplementedException ();
-		}
-		
-		protected override Stream GetGameSystemDataStream (ZipFile file)
-		{
-			return new MemoryStream();
-		}
-
-		protected override Stream GetRaceDataStream (ZipFile file)
-		{
-			throw new NotImplementedException ();
-		}
-	}
-}
--- a/WarFoundryFactoryTest.cs	Sat Aug 15 10:39:26 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-// This file (WarFoundryFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard.
-//
-// 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 NUnit.Framework;
-
-namespace IBBoard.WarFoundry.API
-{
-	[TestFixture()]
-	public class AbstractNativeWarFoundryFactoryTest
-	{
-	}
-}
--- a/WarFoundryLoaderTest.cs	Sat Aug 15 10:39:26 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-// This file (WarFoundryLoaderTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2008, 2009 IBBoard.
-//
-// 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 System.IO;
-using NUnit.Framework;
-using IBBoard.WarFoundry.API.Objects;
-using IBBoard.WarFoundry.API.Factories.Xml;
-
-namespace IBBoard.WarFoundry.API.Factories
-{
-	[TestFixture()]
-	public class WarFoundryLoaderTest
-	{
-		private AbstractNativeWarFoundryFactory sysFactory;
-				
-		[Test()]
-		public void TestLoadWithoutFactoriesCompletesWithoutError()
-		{
-			WarFoundryLoader.GetDefault().LoadFiles();
-		}
-		
-		[Test()]
-		public void TestLoadingSystemCompletesWithoutError()
-		{
-			WarFoundryLoader loader = WarFoundryLoader.GetDefault();
-			DirectoryInfo dir = new DirectoryInfo("testdata");
-			loader.RegisterFactory(GetSystemFactory());
-			loader.AddLoadDirectory(dir);
-			loader.LoadFiles();
-			Assert.Greater(loader.GetGameSystems().Length, 0);
-			loader.RemoveLoadDirectory(dir);
-			loader.UnregisterFactory(GetSystemFactory());
-		}
-				
-		private AbstractNativeWarFoundryFactory GetSystemFactory()
-		{
-			if (sysFactory == null)
-			{
-				sysFactory = new MockSystemFactory();
-			}
-			
-			return sysFactory;
-		}
-	}
-}