Exemple #1
0
 public IEnumerable <IEnumerable <object> > GetTypeParameters(ITypeInfo type)
 {
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     return(GetParameters(_attributeAccessor.GetAttributes(type, _attributeMap.GetDescriptor(Wellknown.Attributes.CaseSource)), _attributeAccessor.GetAttributes(type, _attributeMap.GetDescriptor(Wellknown.Attributes.Case))));
 }
Exemple #2
0
        public IEnumerable <IEnumerable <Type> > GetGenericArgs(IMemberInfo memberInfo)
        {
            if (memberInfo == null)
            {
                throw new ArgumentNullException(nameof(memberInfo));
            }
            var genericArgsFromSources =
                from genericArgsSourceAttribute in _attributeAccessor.GetAttributes(memberInfo, _attributeMap.GetDescriptor(Wellknown.Attributes.GenericArgsSource))
                from genericArgsSourceType in genericArgsSourceAttribute.GetValue <IEnumerable <Type> >(_attributeMap.GetDescriptor(Wellknown.Properties.Types))
                let genericArgsSourceInstance = _reflection.CreateType(genericArgsSourceType).CreateInstance(Enumerable.Empty <object>()) as IEnumerable
                                                from genericArgsItem in GetGenericArgs(genericArgsSourceInstance)
                                                select genericArgsItem;

            var genericArgs =
                from genericArgsAtr in _attributeAccessor.GetAttributes(memberInfo, _attributeMap.GetDescriptor(Wellknown.Attributes.GenericArgs))
                select genericArgsAtr.GetValue <IEnumerable <Type> >(_attributeMap.GetDescriptor(Wellknown.Properties.Types));

            return(genericArgsFromSources.Concat(genericArgs));
        }
Exemple #3
0
        private IEnumerable <NamedGraphType> GetPropertyArguments(PropertyInfo property)
        {
            var argumentAttributes = _attributeAccessor.GetAttributes <ArgumentAttribute>(property, false);

            foreach (var attribute in argumentAttributes)
            {
                if (string.IsNullOrWhiteSpace(attribute.Name))
                {
                    throw new GraphException("Does not specifiy the Name property of the ArgumentAttribute annotated with property member.");
                }

                if (attribute.Type == null)
                {
                    throw new GraphException("Does not specifiy the Type property of the ArgumentAttribute annotated with property member.");
                }

                var isEnumerableArgument = attribute.Type.IsEnumerable(out var argumentType);
                argumentType = argumentType ?? attribute.Type;
                var argumentGraphType = GetGraphType(argumentType, attribute.IsRequired, attribute.GetIsEnumerable() ?? isEnumerableArgument);
                yield return(new NamedGraphType(attribute.Name, argumentGraphType));
            }
        }
Exemple #4
0
        public IEnumerable <ITestInfo> Discover(string source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            var assembly = _reflection.LoadAssembly(source);

            return
                (from type in assembly.DefinedTypes
                 from typeGenericArgs in _genericArgsProvider.GetGenericArgs(type).DefaultIfEmpty(Enumerable.Empty <Type>())
                 let typeGenericArgsArray = typeGenericArgs.ToArray()
                                            let caseType = DefineType(type, typeGenericArgsArray)
                                                           from typeArgs in _argsProvider.GetTypeParameters(type).DefaultIfEmpty(Enumerable.Empty <object>())
                                                           from method in caseType.Methods
                                                           from methodGenericArgs in _genericArgsProvider.GetGenericArgs(method).DefaultIfEmpty(Enumerable.Empty <Type>())
                                                           let methodGenericArgsArray = methodGenericArgs.ToArray()
                                                                                        let caseMethod = DefineMethod(method, methodGenericArgsArray)
                                                                                                         where _attributeAccessor.GetAttributes(caseMethod, _attributeMap.GetDescriptor(Wellknown.Attributes.Test)).Any()
                                                                                                         from methodArgs in _argsProvider.GetMethodParameters(caseMethod).DefaultIfEmpty(Enumerable.Empty <object>())
                                                                                                         from testCase in CreateTestInfo(source, assembly, caseType, typeGenericArgsArray, typeArgs, caseMethod, methodGenericArgsArray, methodArgs)
                                                                                                         select testCase);
        }
 public static TAttribute GetAttribute <TAttribute>(this IAttributeAccessor accessor, ParameterInfo parameter)
     where TAttribute : Attribute
 => accessor.GetAttributes <TAttribute>(parameter).FirstOrDefault();
 public static TAttribute GetAttribute <TAttribute>(this IAttributeAccessor accessor, MemberInfo member, bool inherit)
     where TAttribute : Attribute
 => accessor.GetAttributes <TAttribute>(member, inherit).FirstOrDefault();