Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
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 wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs Thu Dec 24 14:53:18 2009 +0000 @@ -0,0 +1,46 @@ +// This file (WarFoundryXmlRaceFactoryTest.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 System.Collections.Generic; +using System.IO; +using System.Xml; +using NUnit.Framework; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.IO; + +namespace IBBoard.WarFoundry.API.Factories.Xml +{ + + + [TestFixture()] + public class WarFoundryXmlRaceFactoryTest + { + [Test()] + [ExpectedException(typeof(FileLoadException))] + public void TestCompleteLoadingOnRaceWithMissingAbilityIdErrors () + { + ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-ability.race")); + Assert.AreEqual(1, objs.Count); + IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); + enumerator.Reset(); + enumerator.MoveNext(); + Race race = (Race)enumerator.Current; + Category[] cats = race.Categories; + } + + [Test()] + [ExpectedException(typeof(InvalidFileException))] + public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors () + { + ICollection<IWarFoundryObject> objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race")); + Assert.AreEqual(1, objs.Count); + IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); + enumerator.Reset(); + enumerator.MoveNext(); + Race race = (Race)enumerator.Current; + Category[] cats = race.Categories; + } + } +}
--- a/IBBoard.WarFoundry.API.Tests.csproj Fri Nov 13 11:24:55 2009 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Thu Dec 24 14:53:18 2009 +0000 @@ -56,6 +56,7 @@ <Compile Include="API\Objects\Mock\MockNumericAmountUnitEquipmentItem.cs" /> <Compile Include="API\Objects\Mock\MockPercentageAmountUnitEquipmentItem.cs" /> <Compile Include="API\Util\UnitEquipmentUtilTest.cs" /> + <Compile Include="API\Factories\Xml\WarFoundryXmlRaceFactoryTest.cs" /> </ItemGroup> <ItemGroup> <None Include="testdata\Test.race"> @@ -65,6 +66,13 @@ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="COPYING" /> + <None Include="testdata\race-with-non-existant-ability.race"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="testdata\race-with-non-existant-ability.system" /> + <None Include="testdata\race-with-non-existant-game-system.race"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73"> @@ -72,6 +80,7 @@ <HintPath>libs\ICSharpCode.SharpZipLib.dll</HintPath> </Reference> <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" /> + <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\IBBoard.WarFoundry.API\IBBoard.WarFoundry.API.csproj"> @@ -90,6 +99,7 @@ <Folder Include="API\Factories\" /> <Folder Include="API\Factories\Mock\" /> <Folder Include="API\Util\" /> + <Folder Include="API\Factories\Xml\" /> </ItemGroup> <ProjectExtensions> <MonoDevelop>