private bool CheckSetUpTearDownMethods(TestFixture fixture, MethodInfo[] methods) { foreach (MethodInfo method in methods) if (method.IsAbstract || !method.IsPublic && !method.IsFamily || method.GetParameters().Length > 0 || !method.ReturnType.Equals(typeof(void))) { SetNotRunnable(fixture, string.Format("Invalid signature for Setup or TearDown method: {0}", method.Name)); return false; } return true; }
private void CheckTestFixtureIsValid(TestFixture fixture) { Type fixtureType = fixture.FixtureType; #if CLR_2_0 || CLR_4_0 if (fixtureType.ContainsGenericParameters) { SetNotRunnable(fixture, NO_TYPE_ARGS_MSG); return; } #endif if( !IsStaticClass(fixtureType) && !HasValidConstructor(fixtureType, fixture.arguments) ) { SetNotRunnable(fixture, "No suitable constructor was found"); return; } if (!CheckSetUpTearDownMethods(fixture, fixture.SetUpMethods)) return; if (!CheckSetUpTearDownMethods(fixture, fixture.TearDownMethods)) return; if (!CheckSetUpTearDownMethods(fixture, Reflect.GetMethodsWithAttribute(fixture.FixtureType, typeof(TestFixtureSetUpAttribute), true))) return; CheckSetUpTearDownMethods(fixture, Reflect.GetMethodsWithAttribute(fixture.FixtureType, typeof(TestFixtureTearDownAttribute), true)); }
private void SetNotRunnable(TestFixture fixture, string reason) { fixture.RunState = RunState.NotRunnable; fixture.Properties.Set(PropertyNames.SkipReason, reason); }
private Test BuildSingleFixture(Type type, TestFixtureAttribute attr) { object[] arguments = null; if (attr != null) { arguments = (object[])attr.Arguments; #if CLR_2_0 || CLR_4_0 if (type.ContainsGenericParameters) { Type[] typeArgs = (Type[])attr.TypeArgs; if( typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new TestFixture(type, arguments); CheckTestFixtureIsValid(fixture); fixture.ApplyAttributesToTest(type); if (fixture.RunState == RunState.Runnable && attr != null) { if (attr.Ignore) { fixture.RunState = RunState.Ignored; fixture.Properties.Set(PropertyNames.SkipReason, attr.IgnoreReason); } } AddTestCases(type); return this.fixture; }