Ejemplo n.º 1
0
        private static Func <object> GetFromMethod(MemberDataAttribute memberDataAttribute, Type type)
        {
            var methodInfo = GetMemberInfoByName(type, t => t.GetRuntimeMethods(),
                                                 m => m.Name.Equals(memberDataAttribute.MemberName, StringComparison.InvariantCultureIgnoreCase));

            if (methodInfo == null || !methodInfo.IsStatic)
            {
                return(null);
            }

            return(() => methodInfo.Invoke(null, null));
        }
Ejemplo n.º 2
0
        private static Func <object> GetFromField(MemberDataAttribute memberDataAttribute, Type type)
        {
            var fieldInfo = GetMemberInfoByName(type, t => t.GetRuntimeFields(),
                                                f => f.Name.Equals(memberDataAttribute.MemberName, StringComparison.InvariantCultureIgnoreCase));

            if (fieldInfo == null || !fieldInfo.IsStatic)
            {
                return(null);
            }

            return(() => fieldInfo.GetValue(null));
        }
Ejemplo n.º 3
0
        private static Func <object> GetFromProperty(MemberDataAttribute memberDataAttribute, Type type)
        {
            var propInfo = GetMemberInfoByName(type, t => t.GetRuntimeProperties(),
                                               p => p.Name.Equals(memberDataAttribute.MemberName, StringComparison.InvariantCultureIgnoreCase));

            if (propInfo?.GetMethod == null || !propInfo.GetMethod.IsStatic)
            {
                return(null);
            }

            return(() => propInfo.GetValue(null, null));
        }
Ejemplo n.º 4
0
        private static IEnumerable <object[]> GetSingleAttributeData(MethodInfo methodInfo, MemberDataAttribute attribute)
        {
            var targetType = attribute.Type ?? methodInfo.DeclaringType;

            if (targetType == null)
            {
                throw new ArgumentException($"No type found for MemberDataAttribute on method {methodInfo.Name} with attribute value {attribute.MemberName}.");
            }

            var memberDataAccessor = GetFromProperty(attribute, targetType)
                                     ?? GetFromField(attribute, targetType)
                                     ?? GetFromMethod(attribute, targetType);

            if (memberDataAccessor == null)
            {
                throw new ArgumentException($"Cannot locate a field, property or parameterless method with name {attribute.MemberName} on type {targetType.Name}. Did you forget to make it static?");
            }

            var data = memberDataAccessor() as IEnumerable <object[]>;

            if (data == null)
            {
                throw new ArgumentException($"The member data was not of a type convertible to IEnumerable<object[]> for member name {attribute.MemberName} on type {targetType.Name}.");
            }

            return(data);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Used by Fixie to provide test data to the engine.
 /// </summary>
 /// <param name="method">The test method currently running.</param>
 /// <returns>The data to provide to the test method.</returns>
 public IEnumerable <object[]> GetParameters(MethodInfo method)
 {
     return(MemberDataAttribute.GetData(method));
 }