public void NameIsCaseInsensitive() { var dict = new ArgumentDictionary(new[] { "-" }, "-flag", "-name1", "value1"); Assert.True(dict.HasFlag("Flag")); Assert.Equal("value1", dict["Name1"]); }
public void ClearTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value target.Clear(); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public override void Command(ArgumentDictionary args) { var inputLine = ""; System.Console.WriteLine("Going into command mode. This mode allows you to interpret all of your \n" + "command arguments in the program without having to restart it.\n" + "Enter Q to quit.\n"); while ((inputLine = System.Console.ReadLine()).ToLower() != "q" && inputLine.ToLower() != "quit") { var intputLineArgs = ConsoleMethods.SplitArgs(inputLine); var lst = ConsoleMethods.GetArguments(); var parser = new Parser(lst); try { var rtn = parser.Parse(intputLineArgs); if (rtn.UnknownArguments.Length > 0) { System.Console.WriteLine($"Unknown argument(s) received: {String.Join(",", rtn.UnknownArguments)}"); } else { rtn.CommandArgument?.ProcessCommand(rtn); } } catch (DefaultArgumentException ex) { System.Console.WriteLine("Pardon?\n"); } } }
public void CreateWithDefaultNameCharsAndArray() { var args = new[] { "--flag", "-name1", "value1", "-name2", "/value2" }; var dict = new ArgumentDictionary(args); Assert.True(dict.HasFlag("flag")); }
protected override void OnStartup(StartupEventArgs e) { _argumentDictionary = new ArgumentDictionary(e.Args); Directory.CreateDirectory(Globals.AppDataFolder); var config = new LoggingConfiguration(); config.AddTarget(new ColoredConsoleTarget("ConsoleTarget") { Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}", DetectConsoleAvailable = true }); config.AddTarget(new FileTarget("FileTarget") { ArchiveNumbering = ArchiveNumberingMode.DateAndSequence, ArchiveOldFileOnStartup = true, MaxArchiveFiles = 10, FileName = Path.Combine(Globals.AppDataFolder, "Micser.App.log"), FileNameKind = FilePathKind.Absolute }); config.AddTarget(new DebuggerTarget("DebuggerTarget")); config.AddRuleForAllLevels("ConsoleTarget"); config.AddRuleForAllLevels("FileTarget"); config.AddRuleForAllLevels("DebuggerTarget"); LogManager.Configuration = config; Logger.Info("Starting..."); base.OnStartup(e); }
public void ArgumentDictionaryConstructorTest() { IEnumerable <Argument> arguments = null; // TODO: Initialize to an appropriate value ArgumentDictionary target = new ArgumentDictionary(arguments); Assert.Inconclusive("TODO: Implement code to verify target"); }
public void AddRangeTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value IEnumerable <Argument> arguments = null; // TODO: Initialize to an appropriate value target.AddRange(arguments); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void CountTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value int actual; actual = target.Count; Assert.Inconclusive("Verify the correctness of this test method."); }
public void RemoveAtTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value int index = 0; // TODO: Initialize to an appropriate value target.RemoveAt(index); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public override void Command(ArgumentDictionary args) { Console.WriteLine("Press any key to test. Press 'Q' to quit."); while (Console.ReadKey().Key != ConsoleKey.Q) { Console.WriteLine("Didn't hit Q!"); } }
public void GetEnumeratorTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value IEnumerator <Argument> expected = null; // TODO: Initialize to an appropriate value IEnumerator <Argument> actual = null; //actual = target.GetEnumerator(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void GetInvalidArgumentsTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value ArgumentDictionary expected = null; // TODO: Initialize to an appropriate value ArgumentDictionary actual; actual = target.GetInvalidArguments(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void CreateWithMultipleNameChars() { var dict = new ArgumentDictionary(new[] { "-", "/", "--" }, "--flag", "-name1", "value1", "-name2", "/value2"); Assert.True(dict.HasFlag("flag")); Assert.Equal("value1", dict["name1"]); Assert.Null(dict["name2"]); Assert.True(dict.HasFlag("name2")); Assert.True(dict.HasFlag("value2")); }
public void CreateWithSingleNameChar() { var dict = new ArgumentDictionary(new[] { "-" }, "-flag", "-name1", "value1", "-name2", "/value2"); Assert.True(dict.HasFlag("flag")); Assert.False(dict.HasFlag("name2")); Assert.False(dict.HasFlag("value2")); Assert.Equal("value1", dict["name1"]); Assert.Equal("/value2", dict["name2"]); }
public void ParametersAreNotFlags() { var dict = new ArgumentDictionary("-flag", "-key", "value", "-key2", "value2"); Assert.True(dict.HasFlag("flag")); Assert.Null(dict["flag"]); Assert.False(dict.HasFlag("key")); Assert.False(dict.HasFlag("value")); Assert.False(dict.HasFlag("key2")); Assert.False(dict.HasFlag("value2")); }
public void IndexOfTest1() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value Argument argument = null; // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.IndexOf(argument); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void ContainsTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value string argumentName = string.Empty; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.Contains(argumentName); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void ProcessArgument_StatusFailed() { FailedTestCommand tc = new FailedTestCommand(); var args = new ArgumentDictionary(); args.Add("test", tc); Assert.AreEqual(CommandStatus.NotRun, tc.Status); tc.ProcessCommand(args); Assert.AreEqual(CommandStatus.Failed, tc.Status); }
public void ProcessArgument_StatusSuccess() { SuccessfulTestCommand sc = new SuccessfulTestCommand(); var args = new ArgumentDictionary(); args.Add("test", sc); Assert.AreEqual(CommandStatus.NotRun, sc.Status); sc.ProcessCommand(args); Assert.AreEqual(CommandStatus.Successful, sc.Status); }
public void TryGetValueTest() { ArgumentDictionary target = new ArgumentDictionary(); // TODO: Initialize to an appropriate value string argumentName = string.Empty; // TODO: Initialize to an appropriate value Argument value = null; // TODO: Initialize to an appropriate value Argument valueExpected = null; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.TryGetValue(argumentName, out value); Assert.AreEqual(valueExpected, value); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
internal static Options ParseArguments(string[] args) { Mode mode = Mode.NotSpecified; Options options = null; if (args.Length > 0) { ArgumentDictionary arguments = CommandParser.ParseCommand(args, switches); if (arguments.ContainsArgument(Cmd.Install)) { mode = Mode.Install; } if (arguments.ContainsArgument(Cmd.Uninstall)) { if (mode != Mode.NotSpecified) { throw Tool.CreateException(SR.GetString(SR.MultipleModeArguments), null); } mode = Mode.Uninstall; } if (arguments.ContainsArgument(Cmd.List)) { if (mode != Mode.NotSpecified) { throw Tool.CreateException(SR.GetString(SR.MultipleModeArguments), null); } mode = Mode.List; } options = new Options(mode, arguments); } else { return(new Options(mode, null)); } if (!options.Help && (mode == Mode.NotSpecified)) { throw Tool.CreateException(SR.GetString(SR.ModeArgumentMissing), null); } return(options); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += Application_ThreadException; ArgumentParser argumentParser = new ArgumentParser(new[] { "/", "-" }, true, new[] { new Argument("c", ArgumentValue.Optional, true), new Argument("d", ArgumentValue.None, true), new Argument("p", ArgumentValue.Required, true), new Argument("s", ArgumentValue.None, true) }); argumentParser.Parse(args); ArgumentDictionary validArguments = argumentParser.ParsedArguments.GetValidArguments(); if (validArguments.Contains("d")) { Debugger.Launch(); Settings.IsDebug = true; } if (validArguments.Contains("c")) { Application.Run(new FormOptions()); } else { IntPtr previewHandle = IntPtr.Zero; if (validArguments.Contains("p")) { long tempLong; if (long.TryParse(validArguments["p"].Value, out tempLong)) { previewHandle = new IntPtr(tempLong); Logging.LogMessage("Preview Handle: " + previewHandle); } } Application.Run(new FormMain(previewHandle)); } }
public bool TryInvokeRemoteMethod <TContract>(MethodInfo contractMethod, KeyValuePair <string, object>[] args, out object result) where TContract : class { MemoryStream requestStream = new MemoryStream(); ArgumentDictionary arguments = new ArgumentDictionary(args.ToDictionary(x => x.Key, x => x.Value)); invocationSerializer.Serialize(requestStream, arguments); requestStream.Position = 0; StreamContent requestContent = new StreamContent(requestStream); requestContent.Headers.ContentType = new MediaTypeHeaderValue(invocationSerializer.MediaType); HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, CreateRequestPath(typeof(TContract), contractMethod)) { Content = requestContent }; requestMessage.Headers.Accept.Clear(); requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(invocationSerializer.MediaType)); Type returnType; if (contractMethod.ReturnType == typeof(Task)) { result = GetResultNoReturnTypeAsync(typeof(TContract), requestMessage); } else { returnType = contractMethod.ReturnType.GetGenericArguments()[0]; result = GetType().GetMethod(nameof(GetResultAsync), BindingFlags.Instance | BindingFlags.NonPublic) .MakeGenericMethod(returnType) .Invoke(this, new object[] { typeof(TContract), requestMessage }); } return(true); }
public override void Command(ArgumentDictionary args) { IArgument showHelpFor; if (args.ContainsKey("name")) { showHelpFor = args.AllArguments[((IArgumentWithValue)args["name"]).Value]; } else { showHelpFor = this; } Console.WriteLine(showHelpFor.Summary); if (args.ContainsKey("full")) { Console.WriteLine(showHelpFor.HelpDetail); } if (args.ContainsKey("example")) { Console.WriteLine(showHelpFor.HelpExample); } }
public override void Command(ArgumentDictionary args) { }
private static int MainInternal(string[] args) { var arguments = new ArgumentDictionary(Globals.DriverUtility.ArgumentNameChars, args); var silent = arguments.HasFlag(Globals.DriverUtility.Arguments.Silent); InitLogging(silent); if (silent) { // In silent mode the console log is deactivated; only show the following: Console.WriteLine("Configuring virtual audio cable..."); } var logger = LogManager.GetCurrentClassLogger(); // TODO the check doesn't work during msi installation.. if (!silent && !UacHelper.IsProcessElevated) { logger.Error("The process must have elevated privileges to manage driver installation."); return(Globals.DriverUtility.ReturnCodes.RequiresAdminAccess); } logger.Info("Starting..."); try { logger.Info("Arguments: " + arguments); var sDeviceCount = arguments[Globals.DriverUtility.Arguments.DeviceCount]; if (string.IsNullOrEmpty(sDeviceCount) || !int.TryParse(sDeviceCount, out var deviceCount)) { logger.Error($"Invalid or missing device count argument '{Globals.DriverUtility.ArgumentNameChars[0]}{Globals.DriverUtility.Arguments.DeviceCount}' provided: '{sDeviceCount}'."); return(Globals.DriverUtility.ReturnCodes.InvalidParameter); } var controller = new DriverController(); var result = controller.SetDeviceSettingsAndReload(deviceCount); if (result != Globals.DriverUtility.ReturnCodes.Success) { logger.Error($"{nameof(DriverController.SetDeviceSettingsAndReload)} returned {result}"); return(result); } using (var deviceService = new DeviceService()) { var renameResult = deviceService.RenameDevices(deviceCount).GetAwaiter().GetResult(); if (!renameResult) { logger.Error("Renaming failed."); } } } catch (Exception ex) { logger.Error(ex); return(Globals.DriverUtility.ReturnCodes.UnknownError); } logger.Info("Success"); return(Globals.DriverUtility.ReturnCodes.Success); }
public void GetString() { var dict = new ArgumentDictionary("--flag1", "/Flag2", "-name1", "value1", "-name2", "value2"); Assert.Equal("Flags: flag1, flag2 | Parameters: [name1=value1], [name2=value2]", dict.ToString()); }
public void CreateWithDefaultNameCharsAndParams() { var dict = new ArgumentDictionary("--flag", "-name1", "value1", "-name2", "/value2"); Assert.True(dict.HasFlag("flag")); }
public override void Command(ArgumentDictionary args) { Status = CommandStatus.Failed; }
public override void Command(ArgumentDictionary args) { var name = ((NamedArgument)args["name"]).Value; Console.WriteLine($"Created a new item called {name}."); }