using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; namespace Chernobyl.Reflection { /// /// Tests the class of the Chernobyl.Reflection namespace. /// [TestFixture] public class UtilityTests { [Test] [Description("Tests the Utility.GetBaseTypes() to ensure it returns " + "a Type of 'typeof(object)' when the type 'Object' is passed to it.")] public void GetObjectBaseTypesContainsObject() { IEnumerable baseTypes = Utility.GetBaseTypes(); Assert.True(baseTypes.Count() == 1, "Utility.GetBaseTypes() " + "returned more than one Type, there should only be one: typeof(object)."); Assert.AreEqual(typeof(object), baseTypes.First(), "Utility.GetBaseTypes() " + "returned a Type that is not equal to typeof(object)"); } [Test] [Description("Tests the Utility.GetBaseTypes() to ensure it returns " + "the proper Types for a Type whose inheritance hieararchy is more complex " + "than an 'Object' type.")] public void GetBaseTypesReturnsProperTypes() { List baseTypes = new List(Utility.GetBaseTypes()); Assert.AreEqual(baseTypes.Count, FreshmanBaseTypeCount, "Utility.GetBaseTypes() returned an IEnumerable " + "that contained an expected number of Types."); Assert.Contains(typeof(Object), baseTypes, "List of base types did " + "not contain the Object type."); Assert.Contains(typeof(IJock), baseTypes, "List of base types did " + "not contain the IJock type."); Assert.Contains(typeof(Person), baseTypes, "List of base types did " + "not contain the Person type."); Assert.Contains(typeof(Student), baseTypes, "List of base types did " + "not contain the Student type."); } interface IJock { } class Person { } class Student : Person, IJock { } class Freshman : Student { } const int FreshmanBaseTypeCount = 4; } }