public void XCommandSystemTest2() { var execInfo = Utils.GetExecInfo("exact"); string?CallCommand(string command) => CommandManager.Execute(execInfo !, command).GetAwaiter().GetResult().AsString(); var group = execInfo.GetModule <CommandManager>() !.RootGroup; var o1 = new OverloadedFunctionCommand(); o1.AddCommand(new FunctionCommand(new Action <int>((_) => { }))); o1.AddCommand(new FunctionCommand(new Action <long>((_) => { }))); group.AddCommand("one", o1); group.AddCommand("two", new FunctionCommand(new Action <StringSplitOptions>((_) => { }))); var o2 = new CommandGroup(); o2.AddCommand("a", new FunctionCommand(new Action(() => { }))); o2.AddCommand("b", new FunctionCommand(new Action(() => { }))); group.AddCommand("three", o2); Assert.Throws <CommandException>(() => CallCommand("!one")); Assert.Throws <CommandException>(() => CallCommand("!one \"\"")); Assert.Throws <CommandException>(() => CallCommand("!one (!print \"\")")); Assert.Throws <CommandException>(() => CallCommand("!one string")); Assert.DoesNotThrow(() => CallCommand("!one 42")); Assert.DoesNotThrow(() => CallCommand("!one 4200000000000")); Assert.Throws <CommandException>(() => CallCommand("!two")); Assert.Throws <CommandException>(() => CallCommand("!two \"\"")); Assert.Throws <CommandException>(() => CallCommand("!two (!print \"\")")); Assert.Throws <CommandException>(() => CallCommand("!two 42")); Assert.DoesNotThrow(() => CallCommand("!two None")); Assert.Throws <CommandException>(() => CallCommand("!three")); Assert.Throws <CommandException>(() => CallCommand("!three \"\"")); Assert.Throws <CommandException>(() => CallCommand("!three (!print \"\")")); Assert.Throws <CommandException>(() => CallCommand("!three c")); Assert.DoesNotThrow(() => CallCommand("!three a")); Assert.DoesNotThrow(() => CallCommand("!three b")); }
public void XCommandSystemTest2() { var execInfo = Utils.GetExecInfo("exact"); var commandSystem = new XCommandSystem(); var group = commandSystem.RootCommand; var o1 = new OverloadedFunctionCommand(); o1.AddCommand(new FunctionCommand(new Action <int>((_) => { }))); o1.AddCommand(new FunctionCommand(new Action <long>((_) => { }))); group.AddCommand("one", o1); group.AddCommand("two", new FunctionCommand(new Action <StringSplitOptions>((_) => { }))); var o2 = new CommandGroup(); o2.AddCommand("a", new FunctionCommand(new Action(() => { }))); o2.AddCommand("b", new FunctionCommand(new Action(() => { }))); group.AddCommand("three", o2); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one \"\"")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one (!print \"\")")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!one string")); Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!one 42")); Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!one 4200000000000")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two \"\"")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two (!print \"\")")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!two 42")); Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!two None")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three \"\"")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three (!print \"\")")); Assert.Throws <CommandException>(() => commandSystem.ExecuteCommand(execInfo, "!three c")); Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!three a")); Assert.DoesNotThrow(() => commandSystem.ExecuteCommand(execInfo, "!three b")); }