changeset 77:4211c818ef96

Fixes #238: subfolders datafolder * Add unit test and mock object to test loading from sub-folders. We use any old file because it will fail to load it and report a failure without relying on loading logic.
author IBBoard <dev@ibboard.co.uk>
date Tue, 25 Jan 2011 21:04:25 +0000
parents fb60ff2002fd
children 8d3827de003d
files API/AbstractWarFoundryLoaderTests.cs IBBoard.WarFoundry.API.Tests.csproj MockObjects/MockWarFoundryLoader.cs testdata/subdir-loading-test/emptyfile.txt testdata/subdir-loading-test/subdir/subdirfile.txt
diffstat 5 files changed, 102 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/AbstractWarFoundryLoaderTests.cs	Tue Jan 25 21:04:25 2011 +0000
@@ -0,0 +1,23 @@
+using System;
+using NUnit.Framework;
+using IBBoard.WarFoundry.MockObjects;
+using System.Collections.Generic;
+using NUnit.Framework.SyntaxHelpers;
+using System.IO;
+
+namespace IBBoard.WarFoundry.API
+{
+	[TestFixture()]
+	public class AbstractWarFoundryLoaderTests
+	{
+		[Test()]
+		public void TestTriesToLoadFromSubdir()
+		{
+			MockWarFoundryLoader loader = new MockWarFoundryLoader();
+			loader.AddLoadDirectory(new DirectoryInfo("testdata/subdir-loading-test"));
+			List<FileLoadFailure> failures = loader.LoadFiles ();
+			Assert.That(failures.Count, Is.EqualTo(2));
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Oct 30 14:46:06 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Tue Jan 25 21:04:25 2011 +0000
@@ -1,5 +1,5 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -15,7 +15,6 @@
     <UpgradeBackupLocation>
     </UpgradeBackupLocation>
     <OldToolsVersion>2.0</OldToolsVersion>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
     <TargetFrameworkSubset>
     </TargetFrameworkSubset>
   </PropertyGroup>
@@ -70,6 +69,8 @@
     <Compile Include="API\FixedObjectWarFoundryLoader.cs" />
     <Compile Include="API\Factories\Xml\WarFoundryXmlLimitParserTest.cs" />
     <Compile Include="API\Factories\Xml\WarFoundryXmlSystemFactoryTest.cs" />
+    <Compile Include="MockObjects\MockWarFoundryLoader.cs" />
+    <Compile Include="API\AbstractWarFoundryLoaderTests.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -122,7 +123,9 @@
     <None Include="testdata\single-unit-two-categories.racex">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
-    <None Include="testdata\unit-in-non-main-category.armyx" />
+    <None Include="testdata\unit-in-non-main-category.armyx">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Include="testdata\unit-in-default-category.armyx">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
@@ -234,6 +237,12 @@
     <None Include="testdata\zip-format\Repack.system">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\subdir-loading-test\emptyfile.txt">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\subdir-loading-test\subdir\subdirfile.txt">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
@@ -263,4 +272,8 @@
     </MonoDevelop>
     <VisualStudio />
   </ProjectExtensions>
+  <ItemGroup>
+    <Folder Include="testdata\subdir-loading-test\" />
+    <Folder Include="testdata\subdir-loading-test\subdir\" />
+  </ItemGroup>
 </Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MockObjects/MockWarFoundryLoader.cs	Tue Jan 25 21:04:25 2011 +0000
@@ -0,0 +1,60 @@
+using System;
+using IBBoard.WarFoundry.API;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.MockObjects
+{
+	public class MockWarFoundryLoader : AbstractWarFoundryLoader
+	{
+		protected override GameSystem GetExistingSystemForSystem(GameSystem system)
+		{
+			return system;
+		}
+
+		protected override void DoStoreGameSystem(GameSystem system)
+		{
+			//Do nothing
+		}
+
+		protected override void DoStoreRace(Race race)
+		{
+			//Do nothing
+		}
+
+		public override GameSystem[] GetGameSystems()
+		{
+			return new GameSystem[0];
+		}
+
+		public override GameSystem GetGameSystem(string systemID)
+		{
+			return null;
+		}
+
+		protected override void RemoveGameSystem(GameSystem system)
+		{
+			//Do nothing
+		}
+
+		public override Race[] GetRaces(GameSystem system)
+		{
+			return new Race[0];
+		}
+
+		public override Race GetRace(GameSystem system, string raceID)
+		{
+			return null;
+		}
+
+		public override Race GetRace(GameSystem system, string raceID, string raceSubID)
+		{
+			return null;
+		}
+
+		protected override void RemoveRace(Race race)
+		{
+			//Do nothing
+		}
+	}
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/subdir-loading-test/emptyfile.txt	Tue Jan 25 21:04:25 2011 +0000
@@ -0,0 +1,1 @@
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/subdir-loading-test/subdir/subdirfile.txt	Tue Jan 25 21:04:25 2011 +0000
@@ -0,0 +1,1 @@
+