changeset 33:03a8ab5e90d6

Re #236: Race loading should fail cleanly if system doesn't exist * Add tests for race factory * Add test data that references non-existstent system * Make game system names for existing test data more distinct Re #228: Crash with missing abilityID * Initial failing test
author IBBoard <dev@ibboard.co.uk>
date Thu, 24 Dec 2009 14:53:18 +0000
parents 9bf542b76de2
children bdaeadafe130
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/Test.race testdata/Test.system testdata/race-with-non-existant-game-system.race
diffstat 5 files changed, 56 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Thu Dec 24 14:53:18 2009 +0000
     1.3 @@ -0,0 +1,46 @@
     1.4 +// This file (WarFoundryXmlRaceFactoryTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +
     1.8 +using System;
     1.9 +using System.Collections.Generic;
    1.10 +using System.IO;
    1.11 +using System.Xml;
    1.12 +using NUnit.Framework;
    1.13 +using IBBoard.WarFoundry.API.Objects;
    1.14 +using IBBoard.IO;
    1.15 +
    1.16 +namespace IBBoard.WarFoundry.API.Factories.Xml
    1.17 +{
    1.18 +
    1.19 +
    1.20 +	[TestFixture()]
    1.21 +	public class WarFoundryXmlRaceFactoryTest
    1.22 +	{
    1.23 +		[Test()]
    1.24 +		[ExpectedException(typeof(FileLoadException))]
    1.25 +		public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors ()
    1.26 +		{
    1.27 +			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-ability.race"));
    1.28 +			Assert.AreEqual(1, objs.Count);
    1.29 +			IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator();
    1.30 +			enumerator.Reset();
    1.31 +			enumerator.MoveNext();
    1.32 +			Race race = (Race)enumerator.Current;
    1.33 +			Category[] cats = race.Categories;
    1.34 +		}
    1.35 +		
    1.36 +		[Test()]
    1.37 +		[ExpectedException(typeof(InvalidFileException))]
    1.38 +		public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors ()
    1.39 +		{
    1.40 +			ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race"));
    1.41 +			Assert.AreEqual(1, objs.Count);
    1.42 +			IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator();
    1.43 +			enumerator.Reset();
    1.44 +			enumerator.MoveNext();
    1.45 +			Race race = (Race)enumerator.Current;
    1.46 +			Category[] cats = race.Categories;
    1.47 +		}
    1.48 +	}
    1.49 +}
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Fri Nov 13 11:24:55 2009 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Thu Dec 24 14:53:18 2009 +0000
     2.3 @@ -56,6 +56,7 @@
     2.4      <Compile Include="API\Objects\Mock\MockNumericAmountUnitEquipmentItem.cs" />
     2.5      <Compile Include="API\Objects\Mock\MockPercentageAmountUnitEquipmentItem.cs" />
     2.6      <Compile Include="API\Util\UnitEquipmentUtilTest.cs" />
     2.7 +    <Compile Include="API\Factories\Xml\WarFoundryXmlRaceFactoryTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="testdata\Test.race">
    2.11 @@ -65,6 +66,13 @@
    2.12        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.13      </None>
    2.14      <None Include="COPYING" />
    2.15 +    <None Include="testdata\race-with-non-existant-ability.race">
    2.16 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.17 +    </None>
    2.18 +    <None Include="testdata\race-with-non-existant-ability.system" />
    2.19 +    <None Include="testdata\race-with-non-existant-game-system.race">
    2.20 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.21 +    </None>
    2.22    </ItemGroup>
    2.23    <ItemGroup>
    2.24      <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
    2.25 @@ -72,6 +80,7 @@
    2.26        <HintPath>libs\ICSharpCode.SharpZipLib.dll</HintPath>
    2.27      </Reference>
    2.28      <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
    2.29 +    <Reference Include="System.Xml" />
    2.30    </ItemGroup>
    2.31    <ItemGroup>
    2.32      <ProjectReference Include="..\IBBoard.WarFoundry.API\IBBoard.WarFoundry.API.csproj">
    2.33 @@ -90,6 +99,7 @@
    2.34      <Folder Include="API\Factories\" />
    2.35      <Folder Include="API\Factories\Mock\" />
    2.36      <Folder Include="API\Util\" />
    2.37 +    <Folder Include="API\Factories\Xml\" />
    2.38    </ItemGroup>
    2.39    <ProjectExtensions>
    2.40      <MonoDevelop>
     3.1 Binary file testdata/Test.race has changed
     4.1 Binary file testdata/Test.system has changed
     5.1 Binary file testdata/race-with-non-existant-game-system.race has changed