# HG changeset patch # User IBBoard # Date 1255376550 0 # Node ID a4e7e938d0657350da8b1a8a3ee771404b73ce04 # Parent 8d9d49332d44ae02c026846c4eba9dc8ab5ba410 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 diff -r 8d9d49332d44 -r a4e7e938d065 API/Factories/Mock/MockSystemFactory.cs --- /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 (); + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 API/Objects/Mock/MockEquipmentItem.cs --- /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()) + { + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 API/Objects/Mock/MockGameSystem.cs --- /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()) + { + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 API/Objects/Mock/MockRace.cs --- /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()) + { + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 API/Objects/Mock/MockUnitType.cs --- /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()) + { + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 API/Objects/UnitEquipmentItemTest.cs --- /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; + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 API/WarFoundryLoaderTest.cs --- /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; + } + } +} diff -r 8d9d49332d44 -r a4e7e938d065 IBBoard.WarFoundry.API.Tests.csproj --- 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 @@ {B20E808D-878E-4F6D-B1E3-84A9A49905CB} Library Properties - IBBoard.WarFoundry.API.Tests + IBBoard.WarFoundry IBBoard.WarFoundry.API.Tests @@ -40,11 +40,15 @@ - - - + + + + + + + @@ -68,4 +72,20 @@ IBBoard.WarFoundry.API + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 8d9d49332d44 -r a4e7e938d065 MockObjects/MockSystemFactory.cs --- 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 (); - } - } -} diff -r 8d9d49332d44 -r a4e7e938d065 WarFoundryFactoryTest.cs --- 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 - { - } -} diff -r 8d9d49332d44 -r a4e7e938d065 WarFoundryLoaderTest.cs --- 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; - } - } -}