public void Parse_Valid_UInt16_Long_Option() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-ui16 65535"); Assert.AreEqual((ushort)65535, oConfig.UInt16ValueOption); }
public void Valid_Char_Option_With_Uppercase_Value_Should_be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, "-c A"); Assert.AreEqual('A', oConfig.CharValueOption); }
public void Valid_UInt64_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-ui64 131072"); Assert.AreEqual((ulong)131072, oConfig.UInt64ValueOption); }
public void Valid_Char_Option_With_Single_Numeric_Value_Should_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, "-c 1"); Assert.AreEqual('1', oConfig.CharValueOption); }
public void Valid_Directory_Info_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-dir ""C:\Windows"""); Assert.IsNotNull(oConfig.DirInfoValueOption); }
public void Valid_UInt32_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-ui32 65536"); Assert.AreEqual((uint)65536, oConfig.UInt32ValueOption); }
public void Valid_String_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-s:""Example Name"""); Assert.AreEqual("Example Name", oConfig.StringValueOption); }
public void Valid_DateTime_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"--date ""1970-04-01 10:43:28"""); Assert.AreEqual(DateTime.Parse("1970-04-01 10:43:28"), oConfig.DateValueOption); }
public void Valid_Int64_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-l 1234567890"); Assert.AreEqual(1234567890, oConfig.Int64ValueOption); }
public void Valid_Int16_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-i16 32767"); Assert.AreEqual(32767, oConfig.Int16ValueOption); }
public void Valid_Bool_Option_With_AlternativeName_And_Alternative_Value_Should_be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, "/? false"); Assert.AreEqual(false, oConfig.ShowHelpOption); }
public void Valid_FileInfo_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"-file ""C:\Windows\explorer.exe"""); Assert.IsNotNull(oConfig.FileInfoValueOption); }
public void Invalid_UInt64_Option_Shoud_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); ParseResult actual = oParser.ParseArguments(oConfig, @"-ui64 -1"); Assert.AreEqual(ResultStatus.Failure, actual.Status); Assert.AreEqual(ParseErrorType.InvalidOptionValue, actual.Errors.First().ErrorType); }
public void Valid_Parameters_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"""First Parameter Value"" ""Second Parameter Value"""); Assert.AreEqual("First Parameter Value", oConfig.TextValueParameter1); Assert.AreEqual("Second Parameter Value", oConfig.TextValueParameter2); }
public void Invalid_Uri_Option_Shoud_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); ParseResult oResult = oParser.ParseArguments(oConfig, $@"/uri ""C:\\Root\\Folder"""); Assert.AreEqual(ResultStatus.Failure, oResult.Status); Assert.AreEqual(ParseErrorType.InvalidOptionValue, oResult.Errors.First().ErrorType); }
public void Valid_Bool_Options_Should_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, "--help -v:yes"); Assert.AreEqual(true, oConfig.ShowHelpOption); Assert.AreEqual(true, oConfig.VerboseMessagesOption); }
public void Invalid_Char_Option_With_Long_Numeric_Value_Should_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); ParseResult actual = oParser.ParseArguments(oConfig, "-c 123"); Assert.AreEqual(ResultStatus.Failure, actual.Status); Assert.AreEqual(ParseErrorType.InvalidOptionValue, actual.Errors.First().ErrorType); }
public void Valid_SecureString_Option_Should_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); string value = "this is my secret"; oParser.ParseArguments(oConfig, $@"-secure-string ""{value}"""); Assert.AreEqual(value, oConfig.SecureStringOption.GetString()); }
public void Invalid_Single_Option_With_Exceeding_Value_Shoud_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); ParseResult actual = oParser.ParseArguments(oConfig, $@"--single {3.402823E+39}"); Assert.AreEqual(ResultStatus.Failure, actual.Status); Assert.AreEqual(ParseErrorType.InvalidOptionValue, actual.Errors.First().ErrorType); }
public void Invalid_Bool_Option_With_AlternativeName_Should_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); ParseResult actual = oParser.ParseArguments(oConfig, "/? Nein"); Assert.AreEqual(ResultStatus.Failure, actual.Status); Assert.AreEqual(ParseErrorType.InvalidOptionValue, actual.Errors.First().ErrorType); Assert.AreEqual($@"Value ""Nein"" is invalid for option ""?""", actual.Errors.First().Message); }
public void Valid_Uri_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); string expected = "http://example.com/root/"; ParseResult oResult = oParser.ParseArguments(oConfig, $@"/uri ""{expected}"""); Assert.AreEqual(ResultStatus.Success, oResult.Status); Assert.AreEqual(expected, oConfig.UriOptionValue.ToString()); }
public void Valid_Mixed_Arguments_With_Correct_Sequence_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); oParser.ParseArguments(oConfig, @"""First Parameter Value"" ""Second Parameter Value"" --verbose:yes -i:123"); Assert.AreEqual("First Parameter Value", oConfig.TextValueParameter1); Assert.AreEqual("Second Parameter Value", oConfig.TextValueParameter2); Assert.AreEqual(true, oConfig.VerboseMessagesOption); Assert.AreEqual(123, oConfig.Int32ValueOption); }
public void Invalid_Mixed_Arguments_With_Alternative_Incorrect_Sequence_Shoud_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); ParseResult actual; ParseError oActualError; actual = oParser.ParseArguments(oConfig, @"""First Parameter Value"" /i:123 --verbose ""Second Parameter Value"""); Assert.AreEqual(ResultStatus.Failure, actual.Status); Assert.AreEqual(1, actual.Errors.Count()); oActualError = actual.Errors.First(); Assert.AreEqual(ParseErrorType.InvalidOptionValue, oActualError.ErrorType); Assert.AreEqual("verbose", oActualError.ItemName); Assert.AreEqual("Second Parameter Value", oActualError.ItemValue); }
public void Invalid_FileInfo_Option_Shoud_Be_Parsed_With_Error() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); ParseResult actual; actual = oParser.ParseArguments(oConfig, @"-file ""?;"""); Assert.AreEqual(ResultStatus.Failure, actual.Status); Assert.AreEqual(1, actual.Errors.Count()); ParseError oActualError = actual.Errors.First(); Assert.AreEqual(ParseErrorType.InvalidOptionValue, oActualError.ErrorType); Assert.AreEqual("file", oActualError.ItemName); Assert.AreEqual("?;", oActualError.ItemValue); }
public void Valid_Double_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); // set / restore current thread's culture due to culture-depending notation CultureInfo oCurrentCulture = Thread.CurrentThread.CurrentCulture; try { oParser.ParseArguments(oConfig, $@"--double {3.14159265358979}"); Assert.AreEqual((double)3.14159265358979, oConfig.DoubleValueOption); } finally { Thread.CurrentThread.CurrentCulture = oCurrentCulture; } }
public void Valid_Single_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); // set / restore current thread's culture due to culture-depending notation CultureInfo oCurrentCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); oParser.ParseArguments(oConfig, $@"--single {3.402823E+38}"); Assert.AreEqual((float)3.402823E+38, oConfig.SingleValueOption); } finally { Thread.CurrentThread.CurrentCulture = oCurrentCulture; } }
public void Complex_String_Option_Shoud_Be_Parsed() { SimpleValidConfig oConfig = new SimpleValidConfig(); ConsoleCommandLineParser oParser = new ConsoleCommandLineParser(); string expected = "http://192.168.1.2/root-path/"; oConfig.StringValueOption = null; oParser.ParseArguments(oConfig, $@"-s ""{expected}"""); Assert.AreEqual(expected, oConfig.StringValueOption); oConfig.StringValueOption = null; oParser.ParseArguments(oConfig, $@"-s:""{expected}"""); Assert.AreEqual(expected, oConfig.StringValueOption); oConfig.StringValueOption = null; oParser.ParseArguments(oConfig, $@"/s ""{expected}"""); Assert.AreEqual(expected, oConfig.StringValueOption); oConfig.StringValueOption = null; oParser.ParseArguments(oConfig, $@"/s:""{expected}"""); Assert.AreEqual(expected, oConfig.StringValueOption); }