public void DefaultArgumentCorrectlyUsed_Test() { var idArg = new IdArgument() { Name = "id" }; var est = new EstimateArgument() { Name = "estimate" }; var startCmd = new StartCommand() { Name = "start", Default = true }; var lst = new List <IArgument>() { est, idArg, startCmd }; var parser = new Parser(lst) { Delimiter = new char[] { ':', '=' } }; // Start command not passed, but should be used anyway var testArgs = new string[] { "/id:20", "/estimate=5" }; var rtn = parser.Parse(testArgs); Assert.AreEqual(startCmd, (rtn.CommandArgument)); }
public void SequenceInterpretedCorrectyWithDefault_Test() { var idArg = new IdArgument() { Name = "id" }; var est = new EstimateArgument() { Name = "estimate" }; var startCmd = new StartCommand() { Name = "start", Default = true, ArgumentSequence = new List <IArgument>() { idArg, est } }; var lst = new List <IArgument>() { est, idArg, startCmd }; var parser = new Parser(lst) { Delimiter = new char[] { ':', '=' } }; // Start command not passed, but should be used anyway var testArgs = new string[] { "20", "5" }; var rtn = parser.Parse(testArgs); Assert.AreEqual("5", ((NamedArgument)rtn["estimate"]).Value); Assert.AreEqual("20", ((NamedArgument)rtn["id"]).Value); }
public void ParseWithMultipleDelimitersPasses_Test() { var idArg = new IdArgument() { Name = "id" }; var est = new EstimateArgument() { Name = "estimate" }; var startCmd = new StartCommand() { Name = "start", Default = true }; var lst = new List <IArgument>() { est, idArg, startCmd }; var parser = new Parser(lst) { Delimiter = new char[] { ':', '=' } }; // Note that both : and = are used as delimiters var testArgs = new string[] { "/id:20", "/estimate=5" }; var rtn = parser.Parse(testArgs); Assert.AreEqual("5", ((NamedArgument)rtn["estimate"]).Value); Assert.AreEqual("20", ((NamedArgument)rtn["id"]).Value); }
public void ParseCommandWithRequiredArgumentPasses_Test() { var idArg = new IdArgument() { Name = "id" }; var startCmd = new StartCommand() { Name = "start", RequiredArguments = new List <IArgument>() { idArg } }; var lst = new List <IArgument>() { startCmd, idArg }; var parser = new Parser(lst); var testArgs = new string[] { "start", "/id:5", "/dummySwitch" }; var rtn = parser.Parse(testArgs); // (doesn't raise an exception) Assert.AreEqual(startCmd, rtn.CommandArgument); }
public void executed_command_with_expected_argument() { var mock = new Mock<ICommand<IdArgument>>(); var engine = CleeEngine.Create(cfg => { cfg.Factory(f => f.Use(new StubCommandFactory(mock.Object))); cfg.Registry(r => r.Register("foo", mock.Object.GetType())); }); engine.Execute("foo -id 1"); var expectedArgument = new IdArgument { Id = "1" }; mock.Verify(x => x.Execute(expectedArgument)); }
public void executed_command_with_expected_argument() { var mock = new Mock <ICommand <IdArgument> >(); var engine = CleeEngine.Create(cfg => { cfg.Factory(f => f.Use(new StubCommandFactory(mock.Object))); cfg.Registry(r => r.Register("foo", mock.Object.GetType())); }); engine.Execute("foo -id 1"); var expectedArgument = new IdArgument { Id = "1" }; mock.Verify(x => x.Execute(expectedArgument)); }
public void TestAliasesGetFullNames_Test() { var idArg = new IdArgument() { Name = "id" }; var est = new EstimateArgument() { Name = "estimate", Aliases = new List <string>() { "est" } }; var startCmd = new StartCommand() { Name = "start", RequiredArguments = new List <IArgument>() { idArg }, Aliases = new string[] { "st" }, ArgumentSequence = new List <IArgument>() { idArg } }; var dc = new CompletedSwitch() { Name = "Completed", Aliases = new List <string>() { "c", "comp" } }; var lst = new List <IArgument>() { est, idArg, startCmd, dc }; var parser = new Parser(lst); // Start command not passed, but should be used anyway var testArgs = new string[] { "st", "c" }; parser.ReplaceAliasesWithFullNames(testArgs); Assert.AreEqual("start", testArgs[0]); Assert.AreEqual("Completed", testArgs[1]); }
public void TestAliasesWithArgumentSequence_Test() { var idArg = new IdArgument() { Name = "id" }; var est = new EstimateArgument() { Name = "estimate", Aliases = new List <string>() { "est" } }; var startCmd = new StartCommand() { Name = "start", RequiredArguments = new List <IArgument>() { idArg }, Aliases = new string[] { "st" }, ArgumentSequence = new List <IArgument>() { idArg } }; var dc = new CompletedSwitch() { Name = "Completed", Aliases = new List <string>() { "c", "comp" } }; var lst = new List <IArgument>() { est, idArg, startCmd, dc }; var parser = new Parser(lst); // Start command not passed, but should be used anyway var testArgs = new string[] { "st", "5036" }; var rtn = parser.Parse(testArgs); Assert.AreEqual("5036", ((NamedArgument)rtn["id"]).Value); }
public void MultipleCommandsInArgumentSequenceShouldWork_Test() { var idArg = new IdArgument() { Name = "id" }; var nameArg = new NamedArgument() { Name = "name" }; var startCmd = new StartCommand() { Name = "start", RequiredArguments = new List <IArgument>() { idArg }, Aliases = new string[] { "st" }, ArgumentSequence = new List <IArgument>() { idArg } }; var hc = new Help() { Name = "help", ArgumentSequence = new List <IArgument>() { nameArg } }; var lst = new List <IArgument>() { hc, startCmd, nameArg }; var parser = new Parser(lst); // These args say "show me the help for the start command" // So "start" should be picked up as a value of nameArg, not another command var testArgs = new string[] { "help", "start" }; var rtn = parser.Parse(testArgs); Assert.AreEqual(hc, rtn.CommandArgument); Assert.AreEqual("start", ((IArgumentWithValue)rtn["name"]).Value); }
public void SeeThatAliasesAreWorking_Test() { var idArg = new IdArgument() { Name = "id" }; var est = new EstimateArgument() { Name = "estimate", Aliases = new List <string>() { "est" } }; var startCmd = new StartCommand() { Name = "start", Aliases = new List <string>() { "st", "s" } }; var dc = new CompletedSwitch() { Name = "Completed", Aliases = new List <string>() { "c", "comp" } }; var lst = new List <IArgument>() { est, idArg, startCmd, dc }; var parser = new Parser(lst); // Start command not passed, but should be used anyway var testArgs = new string[] { "s", "/est:25", "/comp" }; var rtn = parser.Parse(testArgs); Assert.AreEqual("25", ((NamedArgument)rtn["estimate"]).Value); Assert.AreEqual(true, ((SwitchArgument)rtn["completed"]).Value); Assert.AreEqual(startCmd, (rtn.CommandArgument)); }
public void ThrowErrorIfNoCommandOrDefaultFails_Test() { var idArg = new IdArgument() { Name = "id" }; var startCmd = new StartCommand() { Name = "start" }; var hc = new Help(); var lst = new List <IArgument>() { startCmd, hc, idArg }; var parser = new Parser(lst); var testArgs = new string[] { "/dummySwitch" }; var rtn = parser.Parse(testArgs); }
public void MultipleCommandArgumentFails_Test() { var idArg = new IdArgument() { Name = "id" }; var startCmd = new StartCommand() { Name = "start", Default = true }; var hc = new Help(); var lst = new List <IArgument>() { startCmd, hc, idArg }; var parser = new Parser(lst); var testArgs = new string[] { "start", "help", "/dummySwitch" }; var rtn = parser.Parse(testArgs); }
public void ParseCommandWithoutRequiredArgumentFails_Test() { var idArg = new IdArgument() { Name = "id" }; var startCmd = new StartCommand() { Name = "start", RequiredArguments = new List <IArgument>() { idArg } }; var hc = new Help(); var lst = new List <IArgument>() { startCmd, hc, idArg }; var parser = new Parser(lst); var testArgs = new string[] { "start", "/dummySwitch" }; var rtn = parser.Parse(testArgs); }