/// <summary> /// Check that the fixture type is valid. This method ensures that /// the type is not abstract and that there is no more than one of /// each setup or teardown method and that their signatures are correct. /// </summary> /// <param name="fixtureType">The type of the fixture to check</param> /// <param name="reason">A message indicating why the fixture is invalid</param> /// <returns>True if the fixture is valid, false if not</returns> private bool IsValidFixtureType(Type fixtureType, ref string reason) { //if (fixtureType.IsAbstract && !fixtureType.IsSealed) //{ // reason = string.Format("{0} is an abstract class", fixtureType.FullName); // return false; //} #if CLR_2_0 || CLR_4_0 if (fixtureType.ContainsGenericParameters) { reason = "Fixture type contains generic parameters. You must either provide " + "Type arguments or specify constructor arguments that allow NUnit " + "to deduce the Type arguments."; return(false); } #endif return(NUnitFramework.CheckSetUpTearDownMethods(fixtureType, NUnitFramework.SetUpAttribute, ref reason) && NUnitFramework.CheckSetUpTearDownMethods(fixtureType, NUnitFramework.TearDownAttribute, ref reason) && NUnitFramework.CheckSetUpTearDownMethods(fixtureType, NUnitFramework.TestFixtureSetUpAttribute, ref reason) && NUnitFramework.CheckSetUpTearDownMethods(fixtureType, NUnitFramework.OneTimeSetUpAttribute, ref reason) && NUnitFramework.CheckSetUpTearDownMethods(fixtureType, NUnitFramework.TestFixtureTearDownAttribute, ref reason) && NUnitFramework.CheckSetUpTearDownMethods(fixtureType, NUnitFramework.OneTimeTearDownAttribute, ref reason)); }
private bool IsValidFixtureType(Type type, ref string reason) { if (type.IsAbstract) { reason = string.Format("{0} is an abstract class", type.FullName); return(false); } if (Reflect.GetConstructor(type) == null) { reason = string.Format("{0} does not have a valid constructor", type.FullName); return(false); } if (!NUnitFramework.CheckSetUpTearDownMethods(type, NUnitFramework.SetUpAttribute, ref reason) || !NUnitFramework.CheckSetUpTearDownMethods(type, NUnitFramework.TearDownAttribute, ref reason)) { return(false); } if (Reflect.HasMethodWithAttribute(type, NUnitFramework.FixtureSetUpAttribute, true)) { reason = "TestFixtureSetUp method not allowed on a SetUpFixture"; return(false); } if (Reflect.HasMethodWithAttribute(type, NUnitFramework.FixtureTearDownAttribute, true)) { reason = "TestFixtureTearDown method not allowed on a SetUpFixture"; return(false); } return(true); }