public void LocalizedArgumentAttributeMustFindStringResourceNamed() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.ResourceType = typeof(Gallio.Tests.Properties.Resources); attribute.Description = "#CommandLineArgumentAttributeTests_NotAStringResource"; var desc = attribute.LocalizedDescription; }
public void LocalizedArgumentAttributeLongName() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.LongName = "#CommandLineArgumentAttributeTests_LongName"; attribute.ResourceType = typeof(Gallio.Tests.Properties.Resources); Assert.AreEqual("#CommandLineArgumentAttributeTests_LongName", attribute.LongName); Assert.AreEqual("Long name", attribute.LocalizedLongName); }
private static CommandLineArgumentFlags GetFlags(CommandLineArgumentAttribute attribute, FieldInfo field) { if (attribute != null) { return(attribute.Flags); } else if (IsCollectionType(field.FieldType)) { return(CommandLineArgumentFlags.MultipleUnique); } else { return(CommandLineArgumentFlags.AtMostOnce); } }
private void PopulateArgumentMap() { arguments = new List <Argument>(); argumentMap = new Dictionary <string, Argument>(); foreach (FieldInfo field in argumentSpecification.GetFields()) { if (!field.IsStatic && !field.IsInitOnly && !field.IsLiteral) { CommandLineArgumentAttribute attribute = GetAttribute(field); var defaultAttribute = attribute as DefaultCommandLineArgumentAttribute; if (defaultAttribute != null) { if (defaultArgument != null) { ThrowError(Resources.CommandLineArgumentParser_MoreThanOneDefaultCommandLineArgumentDefined); } defaultArgument = new Argument(attribute, field); defaultArgumentConsumesUnrecognizedSwitches = defaultAttribute.ConsumeUnrecognizedSwitches; } else { arguments.Add(new Argument(attribute, field)); } } } // add explicit names to map foreach (Argument argument in arguments) { AddArgumentToMap(argument.LongName, argument); if (!string.IsNullOrEmpty(argument.ShortName)) { AddArgumentToMap(argument.ShortName, argument); } foreach (string synonym in argument.Synonyms) { AddArgumentToMap(synonym, argument); } } }
public Argument(CommandLineArgumentAttribute attribute, FieldInfo field) { this.field = field; longName = GetLongName(attribute, field); shortName = GetShortName(attribute, field); valueType = GetValueType(field); flags = GetFlags(attribute, field); if (attribute != null) { isDefault = attribute is DefaultCommandLineArgumentAttribute; description = attribute.Description; valueLabel = attribute.ValueLabel; synonyms = attribute.Synonyms; } else { synonyms = EmptyArray <string> .Instance; } if (IsCollection && !AllowMultiple) { ThrowError(Resources.CommandLineArgumentParser_Argument_CollectionArgumentsMustAllowMultipleValues); } if (string.IsNullOrEmpty(longName)) { ThrowError(Resources.CommandLineArgumentParser_Argument_MissingLongName); } if (Unique && !IsCollection) { ThrowError(Resources.CommandLineArgumentParser_Argument_InvalidUsageOfUniqueFlag); } if (!IsValidElementType(valueType)) { ThrowError(Resources.CommandLineArgumentParser_Argument_UnsupportedValueType); } }
public void LocalizedArgumentAttributeMustSupplyResourceType() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.Description = "#Description"; var desc = attribute.LocalizedDescription; }
public void UnLocalizedNullArgumentAttributeReturnsNull() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.Description = null; Assert.AreEqual(null, attribute.Description); }
public void UnLocalizedArgumentAttributeDoesNotNeedResource() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.LongName = "no-logo"; Assert.AreEqual("no-logo", attribute.LongName); }
public void LocalizedArgumentAttributeMultipleSynonyms() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.Synonyms = new[] { "#CommandLineArgumentAttributeTests_Synonym1", "#CommandLineArgumentAttributeTests_Synonym2" }; attribute.ResourceType = typeof(Gallio.Tests.Properties.Resources); Assert.AreEqual("#CommandLineArgumentAttributeTests_Synonym1", attribute.Synonyms[0]); Assert.AreEqual("Synonym1", attribute.LocalizedSynonyms[0]); Assert.AreEqual("#CommandLineArgumentAttributeTests_Synonym2", attribute.Synonyms[1]); Assert.AreEqual("Synonym2", attribute.LocalizedSynonyms[1]); }
public void LocalizedArgumentAttributeValueLabel() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.ValueLabel = "#CommandLineArgumentAttributeTests_ValueLabel"; attribute.ResourceType = typeof(Gallio.Tests.Properties.Resources); Assert.AreEqual("#CommandLineArgumentAttributeTests_ValueLabel", attribute.ValueLabel); Assert.AreEqual("Value label", attribute.LocalizedValueLabel); }
private static CommandLineArgumentFlags GetFlags(CommandLineArgumentAttribute attribute, FieldInfo field) { if (attribute != null) return attribute.Flags; else if (IsCollectionType(field.FieldType)) return CommandLineArgumentFlags.MultipleUnique; else return CommandLineArgumentFlags.AtMostOnce; }
private static string GetShortName(CommandLineArgumentAttribute attribute, FieldInfo field) { return(attribute == null || attribute.IsDefaultShortName ? GetLongName(attribute, field).Substring(0, 1) : attribute.ShortName); }
private static string GetLongName(CommandLineArgumentAttribute attribute, FieldInfo field) { return(attribute == null || attribute.IsDefaultLongName ? field.Name : attribute.LongName); }
private static string GetShortName(CommandLineArgumentAttribute attribute, FieldInfo field) { return attribute == null || attribute.IsDefaultShortName ? GetLongName(attribute, field).Substring(0, 1) : attribute.ShortName; }
private static string GetLongName(CommandLineArgumentAttribute attribute, FieldInfo field) { return attribute == null || attribute.IsDefaultLongName ? field.Name : attribute.LongName; }
public void LocalizedArgumentAttributeDescription() { var attribute = new CommandLineArgumentAttribute(CommandLineArgumentFlags.AtMostOnce); attribute.Description = "#CommandLineArgumentAttributeTests_Description"; attribute.ResourceType = typeof(Gallio.Tests.Properties.Resources); Assert.AreEqual("#CommandLineArgumentAttributeTests_Description", attribute.Description); Assert.AreEqual("Description", attribute.LocalizedDescription); }
public Argument(CommandLineArgumentAttribute attribute, FieldInfo field) { this.field = field; longName = GetLongName(attribute, field); shortName = GetShortName(attribute, field); valueType = GetValueType(field); flags = GetFlags(attribute, field); if (attribute != null) { isDefault = attribute is DefaultCommandLineArgumentAttribute; description = attribute.Description; valueLabel = attribute.ValueLabel; synonyms = attribute.Synonyms; } else { synonyms = EmptyArray<string>.Instance; } if (IsCollection && !AllowMultiple) ThrowError(Resources.CommandLineArgumentParser_Argument_CollectionArgumentsMustAllowMultipleValues); if (string.IsNullOrEmpty(longName)) ThrowError(Resources.CommandLineArgumentParser_Argument_MissingLongName); if (Unique && ! IsCollection) ThrowError(Resources.CommandLineArgumentParser_Argument_InvalidUsageOfUniqueFlag); if (! IsValidElementType(valueType)) ThrowError(Resources.CommandLineArgumentParser_Argument_UnsupportedValueType); }