Esempio n. 1
0
        /// <inheritdoc/>
        public TAttributeType[] GetAttributes <TAttributeType>(bool inherit)
            where TAttributeType : Attribute
        {
            Attribute[] attributeArray = ReflectHelper.GetCustomAttributes(this.TestMethod, typeof(TAttributeType), inherit);

            TAttributeType[] tAttributeArray = attributeArray as TAttributeType[];
            if (tAttributeArray != null)
            {
                return(tAttributeArray);
            }

            List <TAttributeType> tAttributeList = new List <TAttributeType>();

            if (attributeArray != null)
            {
                foreach (Attribute attribute in attributeArray)
                {
                    TAttributeType tAttribute = attribute as TAttributeType;
                    if (tAttribute != null)
                    {
                        tAttributeList.Add(tAttribute);
                    }
                }
            }

            return(tAttributeList.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Checks whether test method has correct Timeout attribute.
        /// </summary>
        /// <param name="method">The method to verify.</param>
        /// <returns>True if the method has the right test timeout signature.</returns>
        internal static bool HasCorrectTimeout(this MethodInfo method)
        {
            Debug.Assert(method != null, "method should not be null.");

            // There should be one and only one TimeoutAttribute.
            var attributes = ReflectHelper.GetCustomAttributes(method, typeof(TimeoutAttribute), false);

            if (attributes?.Length != 1)
            {
                return(false);
            }

            // Timeout cannot be less than 0.
            var attribute = attributes[0] as TimeoutAttribute;

            return(!(attribute?.Timeout < 0));
        }
Esempio n. 3
0
 /// <inheritdoc/>
 public Attribute[] GetAllAttributes(bool inherit)
 {
     return(ReflectHelper.GetCustomAttributes(this.TestMethod, inherit) as Attribute[]);
 }
Esempio n. 4
0
        /// <summary>
        /// For async methods compiler generates different type and method.
        /// Gets the compiler generated type name for given async test method.
        /// </summary>
        /// <param name="method">The method to verify.</param>
        /// <returns>Compiler generated type name for given async test method..</returns>
        internal static string GetAsyncTypeName(this MethodInfo method)
        {
            var asyncStateMachineAttribute = ReflectHelper.GetCustomAttributes(method, typeof(AsyncStateMachineAttribute), false).FirstOrDefault() as AsyncStateMachineAttribute;

            return(asyncStateMachineAttribute?.StateMachineType?.FullName);
        }