private void BuildTestParametersHelpText(IEnumerable <Type> types, StringBuilder sb, List <TestParameterInfo> parameterInfos) { sb.AppendLine("The following scalar parameters can modify the behavior of existing components:"); sb.AppendLine(); var parameterUsages = new Dictionary <string, TestParameterUsage>(); foreach (Type type in types.OrderBy(t => t.Name)) { foreach (PropertyInfo pi in type.GetProperties().Where(c => c.IsDefined(typeof(InjectTestParameterAttribute), false))) { var nonObsoleteAttributes = pi.GetCustomAttributes(typeof(InjectTestParameterAttribute), false) .Cast <InjectTestParameterAttribute>() .Where(a => !a.IsObsolete) .ToList(); ExceptionUtilities.Assert(nonObsoleteAttributes.Count <= 1, "At most 1 non-obsolete InjectTestParameterAttribute expected"); InjectTestParameterAttribute itpa = nonObsoleteAttributes.SingleOrDefault(); if (itpa != null) { TestParameterUsage parameterUsage; if (parameterInfos.Any(pinfo => pinfo.ParameterName.Equals(itpa.ParameterName))) { continue; } if (!parameterUsages.TryGetValue(itpa.ParameterName, out parameterUsage)) { parameterUsage = new TestParameterUsage() { Attribute = itpa, PropertyType = pi.PropertyType }; parameterUsages.Add(itpa.ParameterName, parameterUsage); } parameterUsage.Usages.Add(type); } } } foreach (var kvp in parameterUsages.OrderBy(c => c.Key)) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0}: {1}", kvp.Value.Attribute.ParameterName, kvp.Value.Attribute.HelpText); sb.AppendLine(); sb.AppendFormat(CultureInfo.InvariantCulture, " Default value: {0}", kvp.Value.Attribute.DefaultValueDescription); sb.AppendLine(); sb.AppendFormat(CultureInfo.InvariantCulture, " Used by: {0}", string.Join(", ", kvp.Value.Usages.Select(c => c.Name).ToArray())); sb.AppendLine(); parameterInfos.Add(new TestParameterInfo() { ParameterCategory = "Test Parameters", ParameterName = kvp.Value.Attribute.ParameterName, HelpText = kvp.Value.Attribute.HelpText, PossibleValues = GetPossibleValues(kvp.Value.PropertyType) }); } }
private void BuildTestParametersHelpText(IEnumerable<Type> types, StringBuilder sb, List<TestParameterInfo> parameterInfos) { sb.AppendLine("The following scalar parameters can modify the behavior of existing components:"); sb.AppendLine(); var parameterUsages = new Dictionary<string, TestParameterUsage>(); foreach (Type type in types.OrderBy(t => t.Name)) { foreach (PropertyInfo pi in type.GetProperties().Where(c => c.IsDefined(typeof(InjectTestParameterAttribute), false))) { var nonObsoleteAttributes = pi.GetCustomAttributes(typeof(InjectTestParameterAttribute), false) .Cast<InjectTestParameterAttribute>() .Where(a => !a.IsObsolete) .ToList(); ExceptionUtilities.Assert(nonObsoleteAttributes.Count <= 1, "At most 1 non-obsolete InjectTestParameterAttribute expected"); InjectTestParameterAttribute itpa = nonObsoleteAttributes.SingleOrDefault(); if (itpa != null) { TestParameterUsage parameterUsage; if (parameterInfos.Any(pinfo => pinfo.ParameterName.Equals(itpa.ParameterName))) { continue; } if (!parameterUsages.TryGetValue(itpa.ParameterName, out parameterUsage)) { parameterUsage = new TestParameterUsage() { Attribute = itpa, PropertyType = pi.PropertyType }; parameterUsages.Add(itpa.ParameterName, parameterUsage); } parameterUsage.Usages.Add(type); } } } foreach (var kvp in parameterUsages.OrderBy(c => c.Key)) { sb.AppendFormat(CultureInfo.InvariantCulture, "{0}: {1}", kvp.Value.Attribute.ParameterName, kvp.Value.Attribute.HelpText); sb.AppendLine(); sb.AppendFormat(CultureInfo.InvariantCulture, " Default value: {0}", kvp.Value.Attribute.DefaultValueDescription); sb.AppendLine(); sb.AppendFormat(CultureInfo.InvariantCulture, " Used by: {0}", string.Join(", ", kvp.Value.Usages.Select(c => c.Name).ToArray())); sb.AppendLine(); parameterInfos.Add(new TestParameterInfo() { ParameterCategory = "Test Parameters", ParameterName = kvp.Value.Attribute.ParameterName, HelpText = kvp.Value.Attribute.HelpText, PossibleValues = GetPossibleValues(kvp.Value.PropertyType) }); } }