public void TestPowerArgsRichCommandLineReaderFindContextualArgument()
{
try
{
PowerArgsRichCommandLineReader.FindContextualArgument("-TheString", null);
Assert.Fail("An exception should have been thrown");
}
catch(NullReferenceException ex)
{
Assert.IsTrue(ex.Message.Contains("ambient"));
}
CommandLineArgumentsDefinition def = new CommandLineArgumentsDefinition();
var globalArg = new CommandLineArgument(typeof(string), "TheString");
def.Arguments.Add(globalArg);
var found = PowerArgsRichCommandLineReader.FindContextualArgument("-TheString", null, def);
Assert.AreSame(globalArg, found);
found = PowerArgsRichCommandLineReader.FindContextualArgument("/TheString", null, def);
Assert.AreSame(globalArg, found);
Assert.IsNull(PowerArgsRichCommandLineReader.FindContextualArgument("-ActionInt", null, def));
Assert.IsNull(PowerArgsRichCommandLineReader.FindContextualArgument(null, null, def));
var action = new CommandLineAction((d) => { });
action.Aliases.Add("TheAction");
var actionArg = new CommandLineArgument(typeof(int), "ActionInt");
action.Arguments.Add(actionArg);
def.Actions.Add(action);
found = PowerArgsRichCommandLineReader.FindContextualArgument("-TheString", action, def);
Assert.AreSame(globalArg, found);
found = PowerArgsRichCommandLineReader.FindContextualArgument("-ActionInt", action, def);
Assert.AreSame(actionArg, found);
}