/// <summary> /// Sets up the parameter data for the <paramref name="method"/> on the <paramref name="type"/>. /// </summary> /// <param name="type">The <see cref="Type"/> the method belongs to.</param> /// <param name="method">The method.</param> /// <returns>The parameter data for the <paramref name="method"/> on the <paramref name="type"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> or <paramref name="method"/> parameters /// are <see langword="null"/>.</exception> private IEnumerable <MethodData> SetupParameterData(Type type, MethodBase method) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (method == null) { throw new ArgumentNullException(nameof(method)); } ParameterInfo[] parameterInfos = method.GetParameters(); var data = new List <MethodData>(parameterInfos.Length); for (int parameterIndex = 0; parameterIndex < parameterInfos.Length; ++parameterIndex) { ParameterInfo parameterInfo = parameterInfos[parameterIndex]; // Apply the filters against the parameter. if (ParameterFilters.Any(filter => filter.ApplyFilter(type, method, parameterInfo))) { continue; } try { object[] parameters = SpecimenProvider.GetParameterSpecimens(parameterInfos, parameterIndex); object instanceUnderTest = null; if (!method.IsStatic) { instanceUnderTest = SpecimenProvider.CreateInstance(type); } data.Add( new MethodData( classUnderTest: type, instanceUnderTest: instanceUnderTest, methodUnderTest: method, parameters: parameters, nullParameter: parameterInfo.Name, nullIndex: parameterIndex, executionSetup: new DefaultExecutionSetup())); } catch (Exception ex) { var compositionEx = new CompositionException(type, method, parameterInfo.Name, ex); data.Add( new MethodData( classUnderTest: type, instanceUnderTest: null, methodUnderTest: method, parameters: new object[] { }, nullParameter: parameterInfo.Name, nullIndex: parameterIndex, executionSetup: new ErroredExecutionSetup(compositionEx))); } } return(data); }
public OpenApiCompilerConfiguration(OpenApiConfiguration configuration) { foreach (var documentFilterFactory in configuration.DocumentFilterFactories) { DocumentFilters.Add(documentFilterFactory()); } foreach (var reDocDocumentFilterFactory in configuration.ReDocDocumentFilterFactories) { ReDocDocumentFilters.Add(reDocDocumentFilterFactory()); } foreach (var injectedExtensions in configuration.InjectedExtensions) { DocumentFilters.Add(new OpenApiExtensionInjectingDocumentFilter(injectedExtensions.resourceAssembly, injectedExtensions.resourceName, injectedExtensions.documentRoute)); } foreach (var reDocInjectedExtensions in configuration.ReDocInjectedExtensions) { ReDocDocumentFilters.Add(new OpenApiExtensionInjectingDocumentFilter(reDocInjectedExtensions.resourceAssembly, reDocInjectedExtensions.resourceName, reDocInjectedExtensions.documentRoute)); } foreach (var injectedTags in configuration.InjectedTags) { DocumentFilters.Add(new OpenApiTagInjectingDocumentFilter(injectedTags.resourceAssembly, injectedTags.resourceName, injectedTags.documentRoute)); } foreach (var reDocInjectedTags in configuration.ReDocInjectedTags) { ReDocDocumentFilters.Add(new OpenApiTagInjectingDocumentFilter(reDocInjectedTags.resourceAssembly, reDocInjectedTags.resourceName, reDocInjectedTags.documentRoute)); } foreach (var operationFilterFactory in configuration.OperationFilterFactories) { OperationFilters.Add(operationFilterFactory()); } foreach (var parameterFilterFactory in configuration.ParameterFilterFactories) { ParameterFilters.Add(parameterFilterFactory()); } foreach (var schemaFilterFactory in configuration.SchemaFilterFactories) { SchemaFilters.Add(schemaFilterFactory()); } foreach (var xmlDocFactory in configuration.XmlDocFactories) { SchemaFilters.Add(new OpenApiXmlCommentsSchemaFilter(xmlDocFactory())); } SchemaIdSelector = configuration.SchemaIdSelector; if (SchemaIdSelector == null) { SchemaIdSelector = type => { var typeName = type.GetAttributeValue((DataContractAttribute attribute) => attribute.Name) ?? type.FriendlyId(); return(typeName.SanitizeClassName()); }; } }