# HG changeset patch # User IBBoard # Date 1261666398 0 # Node ID 03a8ab5e90d6dc52dfbd38b3139b751c3f2b2410 # Parent 9bf542b76de2270fdb23a0cfd32abb7b7a36165d 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 diff -r 9bf542b76de2 -r 03a8ab5e90d6 API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs --- /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 objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-ability.race")); + Assert.AreEqual(1, objs.Count); + IEnumerator enumerator = objs.GetEnumerator(); + enumerator.Reset(); + enumerator.MoveNext(); + Race race = (Race)enumerator.Current; + Category[] cats = race.Categories; + } + + [Test()] + [ExpectedException(typeof(InvalidFileException))] + public void TestCompleteLoadingOnRaceWithMissingGameSystemErrors () + { + ICollection objs = WarFoundryXmlFactory.GetFactory().CreateObjectsFromFile(new FileInfo("testdata/race-with-non-existant-game-system.race")); + Assert.AreEqual(1, objs.Count); + IEnumerator enumerator = objs.GetEnumerator(); + enumerator.Reset(); + enumerator.MoveNext(); + Race race = (Race)enumerator.Current; + Category[] cats = race.Categories; + } + } +} diff -r 9bf542b76de2 -r 03a8ab5e90d6 IBBoard.WarFoundry.API.Tests.csproj --- 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 @@ + @@ -65,6 +66,13 @@ PreserveNewest + + PreserveNewest + + + + PreserveNewest + @@ -72,6 +80,7 @@ libs\ICSharpCode.SharpZipLib.dll + @@ -90,6 +99,7 @@ + diff -r 9bf542b76de2 -r 03a8ab5e90d6 testdata/Test.race Binary file testdata/Test.race has changed diff -r 9bf542b76de2 -r 03a8ab5e90d6 testdata/Test.system Binary file testdata/Test.system has changed diff -r 9bf542b76de2 -r 03a8ab5e90d6 testdata/race-with-non-existant-game-system.race Binary file testdata/race-with-non-existant-game-system.race has changed