HasAttribute() public static method

Returns a value indicating whether a method has the attribute.
public static HasAttribute ( ITestMethod method, Type decoratingAttribute ) : bool
method ITestMethod ITestMethod instance.
decoratingAttribute System.Type Attribute of interest.
return bool
Beispiel #1
0
 /// <summary>
 /// Check whether [Exclusive] attribute is present on any classes.
 /// </summary>
 /// <param name="classes">Collection of class metadata objects.</param>
 /// <returns>Returns a value indicating whether any of the classes
 /// include an [Exclusive] attribute.</returns>
 public static bool HasExclusiveClasses(IList <ITestClass> classes)
 {
     foreach (var cl in classes)
     {
         if (ReflectionUtility.HasAttribute(cl.Type, typeof(ExclusiveAttribute)))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #2
0
 /// <summary>
 /// Check whether [Exclusive] is present on >= 1 of the methods.
 /// </summary>
 /// <param name="methods">The methods to search through.</param>
 /// <returns>True if at least one of the methods has Exclusive.</returns>
 public static bool HasExclusiveMethods(ICollection <ITestMethod> methods)
 {
     foreach (var m in methods)
     {
         if (ReflectionUtility.HasAttribute(m, typeof(ExclusiveAttribute)))
         {
             return(true);
         }
     }
     return(false);
 }
 /// <summary>
 /// Check a MethodInfo for the advanced async attribute.
 /// </summary>
 /// <returns>True if the work item queue is supported.</returns>
 private bool SupportsWorkItemQueue()
 {
     if (_testMethod != null)
     {
         return(ReflectionUtility.HasAttribute(_testMethod, typeof(AsynchronousAttribute)));
     }
     else if (MethodInfo != null)
     {
         return(ReflectionUtility.HasAttribute(MethodInfo, typeof(AsynchronousAttribute)));
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Look through the methods for the [Exclusive] attribute. If found,
        /// remove any methods where the attribute is not present.
        /// </summary>
        /// <param name="methods">The methods to filter.</param>
        /// <param name="logWriter">The log writer object.</param>
        public static void FilterExclusiveMethods(IList <ITestMethod> methods, LogMessageWriter logWriter)
        {
            if (HasExclusiveMethods(methods) == false)
            {
                return;
            }
            if (logWriter != null && !_hasWarned)
            {
                logWriter.Warning(Properties.UnitTestMessage.TestMethodHelper_ExclusiveMethodsInUse);
                _hasWarned = true;
            }
            List <ITestMethod> filtered = new List <ITestMethod>();

            foreach (var m in methods)
            {
                if (ReflectionUtility.HasAttribute(m, typeof(ExclusiveAttribute)))
                {
                    filtered.Add(m);
                }
            }
            methods.Replace(filtered);
        }
        /// <summary>
        /// Look through the classes for the [Exclusive] attribute. If found,
        /// remove any classes where the attribute is not present.
        /// </summary>
        /// <param name="classes">The input list of classes.</param>
        /// <param name="logWriter">The log writer object.</param>
        public static void FilterExclusiveClasses(IList <ITestClass> classes, LogMessageWriter logWriter)
        {
            if (!TestAssemblyHelper.HasExclusiveClasses(classes))
            {
                return;
            }
            if (logWriter != null && !_hasWarned)
            {
                logWriter.Warning(Properties.UnitTestMessage.TestClassHelper_ExclusiveClassesInUse);
                _hasWarned = true;
            }
            List <ITestClass> filtered = new List <ITestClass>();

            foreach (ITestClass cl in classes)
            {
                if (ReflectionUtility.HasAttribute(cl.Type, typeof(ExclusiveAttribute)))
                {
                    filtered.Add(cl);
                }
            }
            classes.Replace(filtered);
        }