Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/WarFoundryLoaderTest.cs @ 239:370bec16a364 default tip
Add initial testing for equipment with type (incomplete)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 16 Oct 2016 20:29:35 +0100 |
parents | e173c5512067 |
children |
line wrap: on
line source
// 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; using System.Collections.Generic; using IBBoard.WarFoundry.API.Factories.Xml; using IBBoard.WarFoundry.API.Factories.Requirement; using IBBoard.WarFoundry.API.Objects.Requirement; using IBBoard.WarFoundry.API.Loading; namespace IBBoard.WarFoundry.API.Factories { [TestFixture()] public class WarFoundryLoaderTest { private AbstractNativeWarFoundryFactory sysFactory; [Test()] public void TestLoadWithoutFactoriesCompletesWithoutError() { WarFoundryLoader.GetDefault().LoadFiles(); } [Test()] public void TestLoadingSystemCompletesWithoutError() { AbstractWarFoundryLoader loader = WarFoundryLoader.GetDefault(); DirectoryInfo dir = new DirectoryInfo("testdata"); loader.RegisterFactory(GetSystemFactory()); ILoadableObjectSource loadSource = new LoadableObjectSourceDirectory(dir); loader.AddLoadSource(loadSource); loader.LoadFiles(); Assert.Greater(loader.GetGameSystems().Length, 0); loader.RemoveLoadSource(loadSource); loader.UnregisterFactory(GetSystemFactory()); } [Test()] public void TestBug318LoadingSingleFileShouldNotNullRef() { DefaultWarFoundryLoader loader = new DefaultWarFoundryLoader(); loader.RegisterFactory(WarFoundryXmlFactory.GetFactory()); ICollection<IWarFoundryObject> objs = loader.LoadFile(new FileInfo("testdata/Test.system")); Assert.That(objs, Has.Count.EqualTo(1)); } [Test()] public void TestRegisterRequirementFactoryAddsFactory() { string factoryID = "SomeID"; MockRequirementFactory mockFactory = new MockRequirementFactory(factoryID); WarFoundryLoader.RegisterRequirementFactory(mockFactory); Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory)); Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null); } [Test()] public void TestRegisterRequirementFactoryAddsFactories() { string factoryID1 = "SomeID"; MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID1); WarFoundryLoader.RegisterRequirementFactory(mockFactory1); string factoryID2 = "SomeOtherID"; MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID2); WarFoundryLoader.RegisterRequirementFactory(mockFactory2); Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID1), Is.EqualTo(mockFactory1)); Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID2), Is.EqualTo(mockFactory2)); Assert.That(WarFoundryLoader.GetRequirementFactory("fibble"), Is.Null); } [Test()] public void TestRegisterRequirementFactoryOverridesWithSecondFactory() { string factoryID = "SomeID"; MockRequirementFactory mockFactory1 = new MockRequirementFactory(factoryID); WarFoundryLoader.RegisterRequirementFactory(mockFactory1); Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory1)); MockRequirementFactory mockFactory2 = new MockRequirementFactory(factoryID); WarFoundryLoader.RegisterRequirementFactory(mockFactory2); Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.Not.EqualTo(mockFactory1)); Assert.That(WarFoundryLoader.GetRequirementFactory(factoryID), Is.EqualTo(mockFactory2)); } [Test()] public void TestRegisteringResourceFiles() { AbstractWarFoundryLoader loader = WarFoundryLoader.GetDefault(); loader.RegisterFactory(new MockRaceAndSystemFactory()); ILoadableObjectSource loadSource = new LoadableObjectSourceResourceSet(typeof(WarFoundryLoader).Assembly, "IBBoard.WarFoundry.data.Empire.race", "IBBoard.WarFoundry.data.SampleSystem.system"); loader.AddLoadSource(loadSource); loader.LoadFiles(); try { Assert.That(loader.GetGameSystems(), Has.Length.EqualTo(1)); GameSystem gameSystem = loader.GetGameSystems()[0]; Assert.That(loader.GetRaces(gameSystem), Has.Length.EqualTo(1)); } finally { loader.RemoveLoadSource(loadSource); loader.UnregisterFactory(GetSystemFactory()); } } private AbstractNativeWarFoundryFactory GetSystemFactory() { if (sysFactory == null) { sysFactory = new MockSystemFactory(); } return sysFactory; } } }