public void TestHelpParameter() { IParameterParser processor; string[] commandline = {"--help"}; ParsedParameters output; processor = new UnixParameters(); processor.RegisterParameter<string>("run-scheduled-task", ParameterType.ValueRequired, new string[] { "run-scheduled-task" }, new string[] { "s" }); processor.RegisterParameter<string>("verbose", ParameterType.NoValue, new string[] { "verbose" }, new string[] { "v" }); processor.RegisterParameter<string>("quiet", ParameterType.NoValue, new string[] { "quiet" }, new string[] { "q" }); processor.RegisterParameter<string>("help", ParameterType.NoValue, new string[] { "help" }, new string[] { "h" }); output = processor.Parse(commandline); Assert.IsTrue(output.HasParameter("help"), "Help key is present"); }
public void TestParametersEnumeration() { IParameterParser processor = new UnixParameters(); processor.RegisterParameters(typeof(ParametersEnumeration)); ParsedParameters output; Assert.AreEqual(5, processor.ParameterCount, "Correct count of parameters"); Assert.IsInstanceOfType(typeof(Parameter<int>), processor[ParametersEnumeration.Count], "Count parameter is correct generic type."); output = processor.Parse(new string[] { "-A", "Do something interesting", "/home/craig/foo/bar", "--help", "--explode", "--count", "78" }); Assert.IsTrue(output.HasParameter(ParametersEnumeration.Action), "Action parameter is present."); Assert.AreEqual("Do something interesting", output.GetValue<string>(ParametersEnumeration.Action), "Action parameter has correct value."); Assert.IsTrue(output.HasParameter(ParametersEnumeration.Help), "Help parameter is present."); Assert.IsFalse(output.HasParameter(ParametersEnumeration.Verbose), "Verbose parameter is not present."); Assert.AreEqual(1, output.GetRemainingArguments().Count, "Correct count of remaining args"); Assert.AreEqual("/home/craig/foo/bar", output.GetRemainingArguments()[0], "Correct remaining arg"); Assert.IsTrue(output.HasParameter(ParametersEnumeration.Explode), "Explode parameter is present."); Assert.IsTrue(output.HasParameter(ParametersEnumeration.Count), "Count parameter is present."); Assert.AreEqual(78, output.GetValue<int>(ParametersEnumeration.Count), "Count parameter has correct value."); }
/// <summary> /// <para>Creates and configures a <see cref="IParameterParser"/> instance for testing.</para> /// </summary> /// <param name="paramaterTwoType"> /// A <see cref="ParameterType"/> /// </param> /// <returns> /// A <see cref="IParameterParser"/> /// </returns> private IParameterParser SetUpParamaterParser(ParameterType paramaterTwoType) { IParameterParser output; output = new UnixParameters(); output.RegisterParameter<string>("one", ParameterType.NoValue, new string[] { "one" }, new string[] { "o" }); output.RegisterParameter<string>("two", paramaterTwoType, new string[] { "Number-Two" }, new string[] { "t" }); output.RegisterParameter<string>("three", ParameterType.NoValue, new string[] { "four" }, new string[] { "f" }); return output; }
public void TestErroneousEnumeration() { IParameterParser processor = new UnixParameters(); processor.RegisterParameters(typeof(ErroneousParametersEnumeration)); }