Ejemplo n.º 1
0
        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"));
        }