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 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 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 CreateWithDefaultNameCharsAndArray() { var args = new[] { "--flag", "-name1", "value1", "-name2", "/value2" }; var dict = new ArgumentDictionary(args); Assert.True(dict.HasFlag("flag")); }
public void NameIsCaseInsensitive() { var dict = new ArgumentDictionary(new[] { "-" }, "-flag", "-name1", "value1"); Assert.True(dict.HasFlag("Flag")); Assert.Equal("value1", dict["Name1"]); }
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 CreateWithDefaultNameCharsAndParams() { var dict = new ArgumentDictionary("--flag", "-name1", "value1", "-name2", "/value2"); Assert.True(dict.HasFlag("flag")); }