Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Factories/Xml/WarFoundryXmlFactoryTests.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
using System; using NUnit.Framework; using System.IO; using System.Collections.Generic; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Loading; namespace IBBoard.WarFoundry.API.Factories.Xml { [TestFixture()] public class WarFoundryXmlFactoryTests { [Test()] public void TestFactoryHandlesMultipleFilesWithOldNamesInOneSystemZip() { EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); WarFoundryLoader.SetDefault(loader); WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); try { loader.RegisterFactory(factory); ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.system")); Assert.That(objs, Has.Count.EqualTo(2)); int raceCount = 0; int systemCount = 0; foreach (IWarFoundryObject obj in objs) { if (obj is Race) { raceCount++; } else if (obj is GameSystem) { systemCount++; } } Assert.That(raceCount, Is.EqualTo(1)); Assert.That(systemCount, Is.EqualTo(1)); } finally { loader.UnregisterFactory(factory); } } [Test()] public void TestFactoryHandlesMultipleFilesWithOldNamesInOneRaceZip() { EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); WarFoundryLoader.SetDefault(loader); WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); loader.RegisterFactory(factory); try { ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Test.race")); Assert.That(objs, Has.Count.EqualTo(2)); int raceCount = 0; int systemCount = 0; foreach (IWarFoundryObject obj in objs) { if (obj is Race) { raceCount++; } else if (obj is GameSystem) { systemCount++; } } Assert.That(raceCount, Is.EqualTo(1)); Assert.That(systemCount, Is.EqualTo(1)); } finally { loader.UnregisterFactory(factory); } } [Test()] public void TestFactoryHandlesMultipleFilesWithMultipleNewNamesInOneSystemZip() { EventListeningWarFoundryLoader loader = new EventListeningWarFoundryLoader(); WarFoundryLoader.SetDefault(loader); WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); loader.RegisterFactory(factory); try { ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableFileObject("testdata/multifile-zips/Multipack.system")); Assert.That(objs, Has.Count.EqualTo(4)); int raceCount = 0; int systemCount = 0; foreach (IWarFoundryObject obj in objs) { if (obj is Race) { raceCount++; } else if (obj is GameSystem) { systemCount++; } } Assert.That(raceCount, Is.EqualTo(2)); Assert.That(systemCount, Is.EqualTo(2)); } finally { loader.UnregisterFactory(factory); } } [Test()] public void TestLoadingRaceFromResource() { WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); GameSystem system = new GameSystem("sample", "Sample System", factory); FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system); WarFoundryLoader.SetDefault(fixedLoader); ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableResourceObject(typeof(WarFoundryLoader).Assembly, "IBBoard.WarFoundry.data.Empire.race")); Assert.That(objs, Has.Count.EqualTo(1)); IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.TypeOf(typeof(Race))); } [Test()] public void TestLoadingSystemFromResource() { WarFoundryXmlFactory factory = WarFoundryXmlFactory.GetFactory(); ICollection<IWarFoundryObject> objs = factory.CreateObjectsFromFile(new LoadableResourceObject(typeof(WarFoundryLoader).Assembly, "IBBoard.WarFoundry.data.SampleSystem.system")); Assert.That(objs, Has.Count.EqualTo(1)); IEnumerator<IWarFoundryObject> enumerator = objs.GetEnumerator(); enumerator.MoveNext(); Assert.That(enumerator.Current, Is.TypeOf(typeof(GameSystem))); } } }