Пример #1
0
        CommandLineArgParser CreateSut()
        {
            var parser = new CommandLineArgParser(environment);

            parser.Parse();
            return(parser);
        }
Пример #2
0
        public void CommandLineArgParserTest()
        {
            // 正常入力テスト
            var testCase = new string[] {
                "",
                "4",
                "5 -o -t 12:30",
                "--help",
                "hoge piyo meu -i input -o output",
                "-a ikorin 24 -b hoge --hoge --time 3:34 piyo",
            };
            var answers = new CommandLineArgument[] {
                new CommandLineArgument(new string[0], new Dictionary <string, string>()),
                new CommandLineArgument(new [] { "4" }, new Dictionary <string, string>()),
                new CommandLineArgument(new [] { "5" }, new Dictionary <string, string>()
                {
                    { "-o", "" }, { "-t", "12:30" }
                }),
                new CommandLineArgument(new string[0], new Dictionary <string, string>()
                {
                    { "--help", "" }
                }),
                new CommandLineArgument(new [] { "hoge", "piyo", "meu" }, new Dictionary <string, string>()
                {
                    { "-i", "input" }, { "-o", "output" }
                }),
                new CommandLineArgument(new [] { "24", "piyo", },
                                        new Dictionary <string, string>()
                {
                    { "-a", "ikorin" }, { "-b", "hoge" }, { "--hoge", "" }, { "--time", "3:34" }
                }),
            };

            foreach (var(param, answer) in testCase.Zip(answers, (test, ans) => (test, ans)))
            {
                var args   = param.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var parsed = CommandLineArgParser.Parse(args);
                Assert.True(parsed.Args.SequenceEqual(answer.Args));
                Assert.True(parsed.OptionalArgs.SequenceEqual(answer.OptionalArgs));
            }

            // エラー入力テスト
            var errorCase = new string?[] {
                null,
                "-o -o",
            };
            var errors = new Action <Action>[] {
                action => Assert.Throws <ArgumentNullException>(action),
                action => Assert.Throws <ArgumentException>(action),
            };

            foreach (var(param, assertError) in errorCase.Zip(errors, (test, err) => (test, err)))
            {
                var args = param?.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) !;
                assertError(() => CommandLineArgParser.Parse(args));
            }
        }
Пример #3
0
        public void CommandMessage(string args, Type commandType, string message)
        {
            LogioConfig     config = GetTestConfig();
            LogioTestClient client = new LogioTestClient();

            var parser  = new CommandLineArgParser(() => config, x => client);
            var command = parser.Parse(Helper.CommandLineToArgs(args));

            Assert.NotNull(command);
            Assert.IsType(commandType, command);

            command.Execute();

            Assert.Equal(message, client.Message);
        }
Пример #4
0
        private LogioConfig RunAndReturnConfig(string args, Type commandType)
        {
            var config = GetTestConfig();
            var client = new LogioTestClient();

            var argsArray = Helper.CommandLineToArgs(args);

            var parser  = new CommandLineArgParser(() => config, x => client);
            var command = parser.Parse(argsArray);

            Assert.NotNull(command);
            Assert.IsType(commandType, command);

            command.Execute();

            return(config);
        }
 CommandLineArgParser CreateSut()
 {
     var parser = new CommandLineArgParser(environment);
     parser.Parse();
     return parser;
 }