private TestParameterInfo CreateLoggingTestParameterInfo(Type type) { var tpi = new TestParameterInfo() { ParameterCategory = "Logging", ParameterName = "LogLevel" + type.Name, DefaultValue = this.logLevelResolver.GetLogLevelForType(type).ToString(), HelpText = "Log level for " + type.Name + " and derived classes", PossibleValues = new IndexedKeyValuePairCollection(this.GetLogLevelsWithDescription()), }; tpi.CurrentValue = tpi.DefaultValue; tpi.PossibleValues.SelectedIndex = tpi.PossibleValues.Select(p => p.Key).ToList().IndexOf(tpi.CurrentValue); return(tpi); }
private TestParameterInfo CreateLoggingTestParameterInfo(Type type) { var tpi = new TestParameterInfo() { ParameterCategory = "Logging", ParameterName = "LogLevel" + type.Name, DefaultValue = this.logLevelResolver.GetLogLevelForType(type).ToString(), HelpText = "Log level for " + type.Name + " and derived classes", PossibleValues = new IndexedKeyValuePairCollection(this.GetLogLevelsWithDescription()), }; tpi.CurrentValue = tpi.DefaultValue; tpi.PossibleValues.SelectedIndex = tpi.PossibleValues.Select(p => p.Key).ToList().IndexOf(tpi.CurrentValue); return tpi; }
private void BuildDependenciesHelpText(IEnumerable<Type> types, StringBuilder sb, List<TestParameterInfo> parameterInfos) { var selectors = new Dictionary<Type, Dictionary<string, Type>>(); var selectorArguments = new Dictionary<Type, ImplementationSelectorAttribute>(); this.CalculateAttributeMap(types, selectors, selectorArguments); sb.AppendLine("The following parameters can be used to specify which components should be used:"); sb.AppendLine(); foreach (var k in selectors.OrderBy(t => selectorArguments[t.Key].TestArgumentName)) { var contractType = k.Key; var isa = selectorArguments[contractType]; var possibleOptions = k.Value; string testArgumentName = isa.TestArgumentName; if (possibleOptions.Count > 1 || (!isa.IsRequired && isa.DefaultImplementation == null)) { sb.AppendFormat( CultureInfo.InvariantCulture, "{0}: {1}{2}{3} {4}. Possible values:", testArgumentName, isa.IsRequired ? " (required)" : string.Empty, isa.IsGlobal ? " (global)" : string.Empty, isa.IsTransient ? " (transient)" : string.Empty, isa.HelpText).AppendLine(); var possibleValuesList = new List<KeyValuePair<string, string>>(); foreach (var option in possibleOptions.OrderBy(c => c.Key)) { string helpText = null; var ina = PlatformHelper.GetCustomAttribute<ImplementationNameAttribute>(option.Value); if (ina != null) { helpText = ina.HelpText; } sb.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}", option.Key.PadRight(20), (isa.DefaultImplementation == option.Key) ? "[*DEFAULT*] " : string.Empty, helpText); sb.AppendLine(); possibleValuesList.Add(new KeyValuePair<string, string>(option.Key, helpText)); } if (isa.DefaultImplementation == null) { sb.Append(" (the default is to use none)").AppendLine(); } var tpi = new TestParameterInfo { ParameterName = testArgumentName, ParameterCategory = "Dependencies", HelpText = isa.HelpText, DefaultValue = isa.DefaultImplementation, CurrentValue = isa.DefaultImplementation, PossibleValues = new IndexedKeyValuePairCollection(possibleValuesList.ToList()), }; tpi.PossibleValues.SelectedIndex = possibleValuesList.Select(p => p.Key).ToList().IndexOf(tpi.CurrentValue); parameterInfos.Add(tpi); } } }
private void BuildDependenciesHelpText(IEnumerable <Type> types, StringBuilder sb, List <TestParameterInfo> parameterInfos) { var selectors = new Dictionary <Type, Dictionary <string, Type> >(); var selectorArguments = new Dictionary <Type, ImplementationSelectorAttribute>(); this.CalculateAttributeMap(types, selectors, selectorArguments); sb.AppendLine("The following parameters can be used to specify which components should be used:"); sb.AppendLine(); foreach (var k in selectors.OrderBy(t => selectorArguments[t.Key].TestArgumentName)) { var contractType = k.Key; var isa = selectorArguments[contractType]; var possibleOptions = k.Value; string testArgumentName = isa.TestArgumentName; if (possibleOptions.Count > 1 || (!isa.IsRequired && isa.DefaultImplementation == null)) { sb.AppendFormat( CultureInfo.InvariantCulture, "{0}: {1}{2}{3} {4}. Possible values:", testArgumentName, isa.IsRequired ? " (required)" : string.Empty, isa.IsGlobal ? " (global)" : string.Empty, isa.IsTransient ? " (transient)" : string.Empty, isa.HelpText).AppendLine(); var possibleValuesList = new List <KeyValuePair <string, string> >(); foreach (var option in possibleOptions.OrderBy(c => c.Key)) { string helpText = null; var ina = PlatformHelper.GetCustomAttribute <ImplementationNameAttribute>(option.Value); if (ina != null) { helpText = ina.HelpText; } sb.AppendFormat(CultureInfo.InvariantCulture, " {0}{1}{2}", option.Key.PadRight(20), (isa.DefaultImplementation == option.Key) ? "[*DEFAULT*] " : string.Empty, helpText); sb.AppendLine(); possibleValuesList.Add(new KeyValuePair <string, string>(option.Key, helpText)); } if (isa.DefaultImplementation == null) { sb.Append(" (the default is to use none)").AppendLine(); } var tpi = new TestParameterInfo { ParameterName = testArgumentName, ParameterCategory = "Dependencies", HelpText = isa.HelpText, DefaultValue = isa.DefaultImplementation, CurrentValue = isa.DefaultImplementation, PossibleValues = new IndexedKeyValuePairCollection(possibleValuesList.ToList()), }; tpi.PossibleValues.SelectedIndex = possibleValuesList.Select(p => p.Key).ToList().IndexOf(tpi.CurrentValue); parameterInfos.Add(tpi); } } }