/// <summary> /// Internal helper to check a single setup or teardown method /// </summary> /// <param name="fixtureType">The type to be checked</param> /// <param name="attributeName">The short name of the attribute to be checked</param> /// <returns>True if the method is present no more than once and has a valid signature</returns> private bool CheckSetUpTearDownMethod(Type fixtureType, string name, string attributeName, ref string reason) { int count = Reflect.CountMethodsWithAttribute( fixtureType, attributeName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly, true); if (count == 0) { return(true); } if (count > 1) { reason = string.Format("More than one {0} method", name); return(false); } MethodInfo theMethod = Reflect.GetMethodWithAttribute( fixtureType, attributeName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly, true); if (theMethod != null) { if (theMethod.IsStatic || theMethod.IsAbstract || !theMethod.IsPublic && !theMethod.IsFamily || theMethod.GetParameters().Length != 0 || !theMethod.ReturnType.Equals(typeof(void))) { reason = string.Format("Invalid {0} method signature", name); return(false); } } return(true); }
public void CountMethodsWithAttribute() { Assert.AreEqual(1, Reflect.CountMethodsWithAttribute(myType, "Colors.BlueAttribute", BF, false)); }