public void SetValue_Valid() { var sut = new StringArgument(NAME, DESCRIPTION); sut.SetValue(VALUE); Assert.AreEqual(VALUE, sut.Value); }
private void LoadStringArgument(Argument type, StringArgument argument) { if (type == Argument.Destination) { argument.OnValueChanged += (object sender) => { txb_destination.Text = (string)((StringArgument)argument).Value; }; txb_destination.Changed += (object sender, EventArgs e) => { argument.Value = ((Entry)sender).Text; }; } else if (type == Argument.Source) { argument.OnValueChanged += (object sender) => { txb_source.Text = (string)((StringArgument)argument).Value; }; txb_source.Changed += (object sender, EventArgs e) => { argument.Value = ((Entry)sender).Text; }; } }
public void ArgumentTranslator_StringArgumentToString_QuotedStringExpected() { var text = "Lorem Ipsum Lorem"; var result = new StringArgument(text); Assert.Equal($"\"{text}\"", result.ToString()); }
public void GetUsage_LongDescription() { var sut = new StringArgument(NAME, LONG_DESCRIPTION); var usage = sut.GetUsage(); var expected = " /name Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam\n nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam\n erat, sed diam voluptua."; Assert.AreEqual(expected, sut.GetUsage()); }
protected override bool MeetsCriterion(VisualPayload payload) { return (String.Compare(StringArgument.GetFirstValue(payload.Data), StringArgument2.GetFirstValue(payload.Data), StringComparison.CurrentCultureIgnoreCase) == 0); }
public void WithNotStringArgument_ShouldThrowException() { var notStringArgument = new IntegerArgument("4"); var exception = Assert.Throws <ArgumentException>(() => StringArgument.GetValue(notStringArgument)); Assert.Equal(ErrorMessages.IncorrectArgumentTypeError, exception.Message); }
public void WithCorrectArgument_ShouldReturnValue() { var value = "name"; var stringArgument = new StringArgument(value); var result = StringArgument.GetValue(stringArgument); Assert.Equal(value, result); }
public void ArgumentTranslator_StringParse_GenericStringExpected() { var text = "text"; var expected = new StringArgument(text); var result = _translator.Process(new object[] { text }); Assert.Equal(expected.Content, ((StringArgument)result.First()).Content); }
public void ParsedArgumentName_Get_Passes_Through_To_Internal_Argument() { const string expectedArgumentName = "some argument name"; _argument.Expect(a => a.ParsedArgumentName).Return(expectedArgumentName); var testObject = new StringArgument(_argument, _stringParser); var actualArgumentName = testObject.ParsedArgumentName; Assert.That(actualArgumentName, Is.EqualTo(expectedArgumentName)); }
public void Constructor_RequiredTrue() { var sut = new StringArgument(NAME, DESCRIPTION, true); Assert.AreEqual(NAME, sut.Name); Assert.AreEqual(DESCRIPTION, sut.Description); Assert.IsTrue(sut.IsRequired); Assert.IsNull(sut.DefaultValue); Assert.AreEqual("/name <String>", sut.Syntax); Assert.AreEqual(" /name description", sut.GetUsage()); }
public void PossibleArgumentNames_Get_Passes_Through_To_Internal_Argument() { var expectedArgumentNames = MockRepository.GenerateStub <List <string> >(); _argument.Expect(a => a.PossibleArgumentNames).Return(expectedArgumentNames); var testObject = new StringArgument(_argument, _stringParser); var actualArgumentNames = testObject.PossibleArgumentNames; Assert.That(actualArgumentNames, Is.EqualTo(expectedArgumentNames)); }
public void StringArgument_ParseShouldFail_WithTypeQuotable_BecauseUnclosedQuotedString() { // Arrange StringArgument argument = new StringArgument(StringType.QUOTABLE); IStringReader reader = new StringReader("'foo"); // Act ReadResults readResults = argument.Parse(reader, out _); // Assert Assert.IsFalse(readResults.Successful); }
public void StringArgument_ParseShouldFail_WithTypeQuotable_BecauseInvalidEscapeSequence() { // Arrange StringArgument argument = new StringArgument(StringType.QUOTABLE); IStringReader reader = new StringReader("\"foo\\bar\""); // Act ReadResults readResults = argument.Parse(reader, out _); // Assert Assert.IsFalse(readResults.Successful); }
public void Constructor_WithDefault() { var sut = new StringArgument(NAME, DESCRIPTION, true, DEFAULT_VALUE); Assert.AreEqual(NAME, sut.Name); Assert.AreEqual(DESCRIPTION, sut.Description); Assert.IsFalse(sut.IsRequired); Assert.AreEqual(DEFAULT_VALUE, sut.DefaultValue); Assert.AreEqual("[/name <String>]", sut.Syntax); Assert.AreEqual(" /name description (default: default_value)", sut.GetUsage()); Assert.AreEqual(DEFAULT_VALUE, sut.Value); }
public void StringArgument_WithTypeWord_HasTrailingCharacters() { // Arrange StringArgument argument = new StringArgument(StringType.WORD); IStringReader reader = new StringReader("foo!@#"); // Act argument.Parse(reader, out _); // Assert Assert.IsTrue(reader.CanRead(3)); }
public static void Main(string[] args) { var helpArgument = new Argument(new List <string> { "help", "h", "?" }) { IsRequired = false }; var fileTypeArgument = new CharArgument(new List <string> { "fileType", "type" }); var fileNameArgument = new StringArgument(new List <string> { "fileName", "file" }); var refDateArgument = new DateTimeArgument("refdate") { IsRequired = false }; var countArgument = new IntArgument(new List <string> { "argumentCount", "count" }) { IsRequired = false }; var allowDuplicateArgument = new BoolArgument("allowduplicatefile") { ArgumentNameStringComparison = StringComparison.CurrentCulture, //Case-sensitive IsRequired = false, UsageDescription = "Indicates whether or not to allow duplicate files" }; var argumentParser = new ArgumentParser(); IList <IArgument> allowedArguments = new List <IArgument> { helpArgument, fileTypeArgument, fileNameArgument, refDateArgument, countArgument, allowDuplicateArgument }; var allArgumentsParsingResult = argumentParser.Parse(args, allowedArguments); //Solely for testing Console.WriteLine(JsonConvert.SerializeObject(allArgumentsParsingResult, Formatting.Indented)); if (helpArgument.ParsedSuccessfully || !allArgumentsParsingResult.ParsingSuccessful) { var usage = argumentParser.GetUsage(ProgramDescription, allowedArguments); Console.WriteLine(usage); } }
public void ctor() { var name = Guid.NewGuid().ToString(); var arg = new StringArgument(name); Assert.Equal(name, arg.Name); Assert.Contains(name, arg.Identifiers); Assert.False(arg.Present); Assert.Equal(string.Empty, arg.Value); Assert.Equal($"{name}: ''", arg.ToString()); }
public void Setting_Value_Should_Affect_Value() { var name = Guid.NewGuid().ToString(); var value = Guid.NewGuid().ToString(); var arg = new StringArgument(name) { Value = value }; Assert.Equal(value, arg.Value); Assert.True(arg.Present); }
public void StringArgument_ParseShouldSucceed_WhenEmpty_WithTypeWord() { // Arrange StringArgument argument = new StringArgument(StringType.WORD); IStringReader reader = new StringReader(""); // Act ReadResults readResults = argument.Parse(reader, out _); // Assert Assert.IsTrue(readResults.Successful); }
public void StringArgument_ParseShouldSucceed_WithTypeGreedy() { // Arrange StringArgument argument = new StringArgument(StringType.GREEDY); IStringReader reader = new StringReader("Hello world! This is a test."); // Act argument.Parse(reader, out _); // Assert Assert.IsFalse(reader.CanRead()); }
public void StringArgument_WithTypeQuotable_EscapesCorrectly() { // Arrange StringArgument argument = new StringArgument(StringType.QUOTABLE); IStringReader reader = new StringReader("\"\\\"foo bar\\\"\""); // Act argument.Parse(reader, out string result); // Assert Assert.AreEqual(result, "\"foo bar\""); }
public void StringArgument_ParseShouldSucceed_WithTypeQuotable_WithQuote() { // Arrange StringArgument argument = new StringArgument(StringType.QUOTABLE); IStringReader reader = new StringReader("'foo bar'"); // Act ReadResults readResults = argument.Parse(reader, out _); // Assert Assert.IsTrue(readResults.Successful); }
public void WithCorrectArgument_ShouldSetValueField() { var value = "name"; var integerArgument = new StringArgument(value); var field = integerArgument.GetType().GetField("value", BindingFlags.NonPublic | BindingFlags.Instance); var expectedValue = value; var actualValue = (string)field.GetValue(integerArgument); Assert.Equal(expectedValue, actualValue); }
public void TrySetArgument_Returns_InvalidArgumentName_When_Argument_Name_Is_Incorrect() { const string argumentName = "some arg"; _argument.Expect(a => a.TrySetArgumentName(argumentName)).Return(SetArgumentDataResult.InvalidArgumentName); var testObject = new StringArgument(_argument, _stringParser); var actual = testObject.TrySetArgumentName(argumentName); Assert.That(actual, Is.EqualTo(SetArgumentDataResult.InvalidArgumentName)); Assert.That(testObject.ParsedSuccessfully, Is.False); Assert.That(testObject.ParsedArgumentValue, Is.Null); }
public void ArgumentNameStringComparison_Get_And_Set_Pass_Through_To_Internal_Argument() { _argument.Expect(a => a.ArgumentNameStringComparison).SetPropertyWithArgument(StringComparison.CurrentCulture); _argument.Expect(a => a.ArgumentNameStringComparison).Return(StringComparison.InvariantCulture); var testObject = new StringArgument(_argument, _stringParser) { ArgumentNameStringComparison = StringComparison.CurrentCulture }; var returnedStringComparison = testObject.ArgumentNameStringComparison; Assert.That(returnedStringComparison, Is.EqualTo(StringComparison.InvariantCulture)); }
static RpxInterface() { Title = Strings.App_Title + " " + typeof(Program).Assembly.GetName().Version.ToString(); Parser = new ArgumentParser("Rpx", Title + "\n" + Strings.App_AboutText); Parser.AboutTitleText = Title; Parser.AboutText = Strings.App_AboutText; Parser.AboutTextLong = Strings.App_AboutTextLong; Parser.CreditsText = Strings.App_CreditsText; Parser.LegalText = Strings.App_LegalText; Parser.HasApplicationDocument = true; PathString = new StringArgument(Strings.Arg_PathString_Name, Strings.Arg_PathString_ShortHelp, Strings.Arg_PathString_Help); FileList = new StringListArgument(Strings.Arg_FileList_Name, "", Strings.Arg_FileList_Help); Parser.FirstArgument = PathString; Parser.DefaultArgument = FileList; AssemblyInfoPath = new StringArgument(Strings.Arg_AssemblyInfoPath_Name, Strings.Arg_AssemblyInfoPath_ShortHelp, Strings.Arg_AssemblyInfoPath_Help); IconPath = new StringArgument(Strings.Arg_IconPath_Name, Strings.Arg_IconPath_ShortHelp, Strings.Arg_IconPath_Help); OutputPath = new StringArgument(Strings.Arg_OutputPath_Name, Strings.Arg_OutputPath_ShortHelp, Strings.Arg_OutputPath_Help); ConsoleSwitch = new PlusMinusSwitch(Strings.Arg_ConsoleSwitch_ShortHelp, Strings.Arg_ConsoleSwitch_Help, true); PassArgsSwitch = new BoolSwitch(Strings.Arg_PassArgsSwitch_ShortHelp, Strings.Arg_PassArgsSwitch_Help); DecorateSwitch = new BoolSwitch(Strings.Arg_Decorate_ShortHelp, Strings.Arg_Decorate_Help); ProtectZipSwitch = new OptionalStringArgument(Strings.Arg_Hide_Name, Strings.Arg_Hide_ShortHelp, Strings.Arg_Hide_Help); ToolsCsv = new CsvArgument(Strings.Arg_Toolkit_Name, Strings.Arg_Toolkit_ShortHelp, Strings.Arg_Toolkit_Help); Parser.Add(PlusMinusSwitch.KeyPrefix, Strings.Arg_ConsoleSwitch_Symbol, Strings.Arg_ConsoleSwitch_Key, ConsoleSwitch); Parser.Add("/", Strings.Arg_PassArgsSwitch_Symbol, Strings.Arg_PassArgsSwitch_Key, PassArgsSwitch); Parser.Add("/", Strings.Arg_Toolkit_Key, ToolsCsv); Parser.Add("/", Strings.Arg_OutputPath_Symbol, Strings.Arg_OutputPath_Key, OutputPath); Parser.Add("/", Strings.Arg_Decorate_Key, DecorateSwitch); Parser.Add("/", Strings.Arg_IconPath_Symbol, Strings.Arg_IconPath_Key, IconPath); Parser.Add("/", Strings.Arg_AssemblyInfoPath_Symbol, Strings.Arg_AssemblyInfoPath_Key, AssemblyInfoPath); Parser.Add("/", Strings.Arg_Hide_Key, ProtectZipSwitch); BuildSwitch = new BoolSwitch(Strings.Arg_BuildSwitch_ShortHelp, Strings.Arg_BuildSwitch_Help); QuietSwitch = new BoolSwitch(Strings.Arg_QuietSwitch_ShortHelp, Strings.Arg_QuietSwitch_Help); VerboseSwitch = new EnumSwitch(Strings.Arg_Verbose_ShortHelp, Strings.Arg_Verbose_Help, typeof(ConsoleVerbosity)); Parser.Add("/", Strings.Arg_BuildSwitch_Key, BuildSwitch); Parser.Add("/", Strings.Arg_QuietSwitch_Key, QuietSwitch); Parser.Add("/", Strings.Arg_Verbose_Key, VerboseSwitch); WarningsAsErrors = new PlusMinusSwitch(Strings.Arg_WarningsAsErrors_ShortHelp, Strings.Arg_WarningsAsErrors_Help, false); Parser.Add(PlusMinusSwitch.KeyPrefix, Strings.Arg_WarningsAsErrors_Key, WarningsAsErrors); }
public void SetValue_Null() { var sut = new StringArgument(NAME, DESCRIPTION); try { sut.SetValue(null); } catch (Exception ex) { Assert.AreEqual("Argument 'name' is invalid", ex.Message); throw; } }
public ListOrDescribeCommand() { NameArgument = new StringArgument("name", $"The start of the name of the {TypeName}"); SuffixArgument = new StringArgument("suffix", $"The end of the name of the {TypeName}"); SuffixTag = new Tag("-end", "look for items with a specific suffix", new List <Argument> { SuffixArgument }); ContainsArgument = new StringArgument("contained", $"The string contained within the name of the {TypeName}"); ContainsTag = new Tag("-con", "look for items containing a specific string", new List <Argument> { ContainsArgument }); NumberedTag = new Tag("-n", "number the items listed"); SeparatedTag = new Tag("-s", "list items of the same name separately"); }
public static CommandBuilder WithStandardListAction <TGame, TItem>(this CommandBuilder commandBuilder, Func <TGame, Command, List <TItem> > source, Action <List <TItem>, TGame, Command> followup, params Func <TItem, bool>[] filters) where TGame : Game where TItem : VText { var prefixArgument = new StringArgument("Prefix", Text("the prefix of your search")); var suffixArgument = new StringArgument("suffix", Text("the suffix of your search")); var suffixTag = new Tag("-suffix", Text("Allows you to search with a suffix"), new List <Argument> { suffixArgument }); var infixArgument = new StringArgument("infix", Text("the infix of your search")); var infixTag = new Tag("-infix", Text("Allows you to search with an infix"), new List <Argument> { infixArgument }); var lengthArgument = new IntegerArgument("Length", Text("the length of your search")); var lengthTag = new Tag("-length", Text("Allows your to search with a set length"), new List <Argument> { lengthArgument }); var minLengthArgument = new IntegerArgument("Minimum Length", Text("the minimum length of your search")); var minLengthTag = new Tag("-min", Text("Allows your to search with a minimum length"), new List <Argument> { minLengthArgument }); var maxLengthArgument = new IntegerArgument("Maximum Length", Text("the maximum length of your search")); var maxLengthTag = new Tag("-max", Text("Allows your to search with a maximum length"), new List <Argument> { maxLengthArgument }); commandBuilder.WithOptionalArguments(prefixArgument); commandBuilder.WithTags(suffixTag, infixTag, lengthTag, minLengthTag, maxLengthTag); bool Filter(TItem item) { var matchCriteria = new StringMatching.MatchCriteria( prefixArgument.IsFilled() ? prefixArgument.Content : null, suffixArgument.IsFilled() ? suffixArgument.Content : null, infixArgument.IsFilled() ? infixArgument.Content : null, lengthArgument.IsFilled() ? lengthArgument.Content : -1, minLengthArgument.IsFilled() ? minLengthArgument.Content : -1, maxLengthArgument.IsFilled() ? maxLengthArgument.Content : -1, true); return(matchCriteria.IsMatch(item.GetContentRaw())); } var completeFilters = filters.ToList(); completeFilters.Add(Filter); return(WithListAction(commandBuilder, source, followup, completeFilters.ToArray())); }
static int Main(string[] args) { StringArgument ss = new StringArgument("ss", "Screenshot", "Path to destination image file"); StringArgument hw = new StringArgument("hw", "Hide Window", "Process name to hide main process window"); StringArgument cs = new StringArgument("cs", "Send Close Signal", "Process name to send a close signal"); ArgumentParser parser = new ArgumentParser("ViniSandboxTools", "This application is able to take screenshots, hide main window from a process and send close signal to a process."); parser.Add("\\", "ss", ss); parser.Add("\\", "hw", hw); parser.Add("\\", "cs", cs); if (parser.HelpMode) { parser.WriteLongArgumentsUsage(); return(0); } try { parser.Parse(args); } catch (Exception ex) { parser.WriteShortArgumentsUsage(); return(-1); } try { if (hw.Defined) { HideWindow(hw.Value); } if (cs.Defined) { SendCloseSignal(cs.Value); } if (ss.Defined) { takeScreenshot(ss.Value); } return(0); } catch (Exception ex) { Console.WriteLine(ex.Message); return(-1); } }
/// <summary> /// Gets the value for a <see cref="StringArgument"/>. /// </summary> /// <param name="argument">The argument.</param> /// <returns>The value.</returns> public override string GetValue(StringArgument argument) { string value; GetCommandLineArgumentValueAsString(argument.Id, _subArgs, out value); return value; }
/// <summary> /// Gets the value for a <see cref="StringArgument"/>. /// </summary> /// <param name="argument">The argument.</param> /// <returns>The value.</returns> /// <exception cref="InvalidOperationArgumentException"> /// May be thrown if the value for the argument cannot be converted to the appropriate type. /// </exception> public abstract string GetValue(StringArgument argument);