Mercurial > repos > IBBoard.WarFoundry.API.Tests
view WarFoundryFactoryFactoryTest.cs @ 8:69bf7972c9fd
Re #44 - Fix API tests
* Remove unused method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 14 Mar 2009 17:11:13 +0000 |
parents | 4222cfa99c78 |
children |
line wrap: on
line source
// This file (WarFoundryFactoryFactoryTest.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 under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. using System; using NUnit.Framework; using IBBoard; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Factories.Xml; namespace IBBoard.WarFoundry.API.Factories { [TestFixture()] public class AbstractNativeWarFoundryFactoryTest { [Test()] public void TestFactoryReturnsCorrectClassForDefault() { WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetDefaultFactoryClass(); Assert.AreEqual(GetDefaultFactoryClass(), WarFoundryFactoryFactory.GetFactoryFactory().GetFactory().GetType(), "AbstractNativeWarFoundryFactory returned incorrect default factory type"); } [Test()] [Ignore("Only one class of factory exists in current implementation")] public void TestFactoryReturnsCorrectClassForAlteredDefault() { WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetDefaultFactoryClass(); WarFoundryFactoryFactory.GetFactoryFactory().DefaultType = GetOtherFactoryClass(); Assert.AreEqual(GetOtherFactoryClass(), WarFoundryFactoryFactory.GetFactoryFactory().GetFactory().GetType(), "AbstractNativeWarFoundryFactory returned incorrect default factory type for updated factory"); } [Test()] public void TestFactoryReturnsCorrectClassForXmlFactory() { Assert.AreEqual(WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()).GetType(), GetFactoryClass(), "AbstractNativeWarFoundryFactory failed to return correct type when passed a valid type"); } [Test()] public void TestFactoryReturnsEqualFactoryForMatchingClasses() { IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()); IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()); Assert.AreEqual(first, second, "AbstractNativeWarFoundryFactory failed to return equal factory for matching string"); } [Test()] public void TestFactoryReturnsSameFactoryForMatchingClasses() { IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()); IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()); Assert.IsTrue(first == second, "AbstractNativeWarFoundryFactory failed to return cached factory"); } [Test()] //[ExpectedException(typeof(ArgumentException), ExpectedMessage="was not a subtype", MatchType=MessageMatch.Contains )] [ExpectedException(typeof(ArgumentException))] public void TestFactoryThrowsArgumentExceptionForInvalidClass() { WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetInvalidFactoryClass()); Assert.Fail("Exceptect exception was not thrown"); } [Test()] //[ExpectedException(typeof(ArgumentException), ExpectedMessage="was not a subtype", MatchType=MessageMatch.Contains )] [ExpectedException(typeof(ArgumentException))] public void TestFactoryThrowsArgumentExceptionForAbstractClass() { WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(typeof(AbstractNativeWarFoundryFactory)); Assert.Fail("Exceptect exception was not thrown"); } [Test()] [Ignore("Only one class of factory exists in current implementation")] public void TestFactoryReturnsEqualFactoriesForSameClassAfterDifferentClasses() { IWarFoundryFactory first = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()); WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetOtherFactoryClass()); IWarFoundryFactory second = WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(GetFactoryClass()); Assert.AreEqual(first, second, "AbstractNativeWarFoundryFactory did not return the same factory after creating a new factory of a different class"); } private Type GetDefaultFactoryClass() { return typeof(WarFoundryXmlFactory); } private Type GetInvalidFactoryClass() { return typeof(String); } private Type GetFactoryClass() { return typeof(WarFoundryXmlFactory); } private Type GetOtherFactoryClass() { //TODO: Fill in when we have a second class return null; } } }