using Glass.Testbed; using Glass.Testbed.TestCases.Alpha; using Glass.Testbed.TestCases.Fake; using Glass.Testbed.TestCases.Fake.Nested; using Glass.Testbed.TestCases.Text; using System; using System.Collections.Generic; using UnitTestSharp; namespace Glass.Testbed.TestCases.Alpha { public class FirstTestCase : TestCase { protected override void Populate() { } } } namespace Glass.Testbed.TestCases.Fake { public class PlainTestCase : TestCase { protected override void Populate() { } } public class NeedsWorldTestCase : TestCase { public NeedsWorldTestCase(World world) { } protected override void Populate() { } } public abstract class AbstractTestCase : TestCase { } public class NoUsableConstructorTestCase : TestCase { public NoUsableConstructorTestCase(int unusable) { } protected override void Populate() { } } public class ThrowingTestCase : TestCase { public ThrowingTestCase() { throw new NotSupportedException(); } protected override void Populate() { } } public class Unsuffixed : TestCase { protected override void Populate() { } } } namespace Glass.Testbed.TestCases.Fake.Nested { public class DeepTestCase : TestCase { protected override void Populate() { } } } namespace Glass.Blacklight.UnitTests { public class StrayTestCase : TestCase { protected override void Populate() { } } public class TestCaseCatalogTests : TestFixture { public class FindTests : TestFixture { public void OrdersEntriesByCategoryThenName() { List entries = TestCaseCatalog.Find(new[] { typeof(PlainTestCase), typeof(FirstTestCase), typeof(NeedsWorldTestCase), }); CheckEqual(3, entries.Count); CheckEqual(typeof(FirstTestCase), entries[0].Type); CheckEqual(typeof(NeedsWorldTestCase), entries[1].Type); CheckEqual(typeof(PlainTestCase), entries[2].Type); } public void TakesTheCategoryFromTheNamespaceAndTheNameFromTheType() { TestCaseCatalog.Entry entry = TestCaseCatalog.Find(new[] { typeof(NeedsWorldTestCase) })[0]; CheckEqual("Fake", entry.Category); CheckEqual("Needs world", entry.Name); } public void SkipsAbstractTypesAndTypesThatAreNotTestCases() { List entries = TestCaseCatalog.Find(new[] { typeof(AbstractTestCase), typeof(string), typeof(PlainTestCase), }); CheckEqual(1, entries.Count); CheckEqual(typeof(PlainTestCase), entries[0].Type); } public void ThrowsForACaseOutsideTheRootNamespace() { CheckThrow(typeof(InvalidOperationException)); TestCaseCatalog.Find(new[] { typeof(StrayTestCase) }); } public void ThrowsForACaseNestedBelowItsCategory() { CheckThrow(typeof(InvalidOperationException)); TestCaseCatalog.Find(new[] { typeof(DeepTestCase) }); } public void ThrowsForACaseWithNoUsableConstructor() { CheckThrow(typeof(InvalidOperationException)); TestCaseCatalog.Find(new[] { typeof(NoUsableConstructorTestCase) }); } public void PlacesEveryCaseInTheTestbedAssembly() { List entries = TestCaseCatalog.Find(typeof(World).Assembly); CheckTrue(entries.Exists(entry => entry.Type == typeof(FontsTestCase))); } } public class CreateTests : TestFixture { public void BuildsACaseWithAParameterlessConstructor() { var entry = new TestCaseCatalog.Entry("Fake", "Plain", typeof(PlainTestCase)); CheckEqual(typeof(PlainTestCase), TestCaseCatalog.Create(entry, world: null).GetType()); } public void BuildsACaseThatTakesTheWorld() { var entry = new TestCaseCatalog.Entry("Fake", "Needs world", typeof(NeedsWorldTestCase)); CheckEqual(typeof(NeedsWorldTestCase), TestCaseCatalog.Create(entry, world: null).GetType()); } public void ThrowsWhatTheConstructorThrowsNotAWrapper() { var entry = new TestCaseCatalog.Entry("Fake", "Throwing", typeof(ThrowingTestCase)); CheckThrow(typeof(NotSupportedException)); TestCaseCatalog.Create(entry, world: null); } } } }