コード例 #1
0
ファイル: ModeParserTests.cs プロジェクト: zhang919/canvas
        public void ParseSinglePositionalOption_WithMultipleStringInputArgumentsAndMultipleValues_ReturnsFailedResult()
        {
            // arrange
            string inputArgument1  = "input";
            string inputArgument2  = "input2";
            string inputArgument3  = "input3";
            string inputArgumentB1 = "inputB";
            string inputArgumentB2 = "inputB2";
            string inputArgumentB3 = "inputB3";
            Func <string, string, string, IParsingResult <Tuple <string, string, string> > > parse = (value1, value2, value3) => ParsingResult <Tuple <string, string, string> > .SuccessfulResult(Tuple.Create(value1, value2, value3));

            var option1           = StringOption.CreateRequired("value1 option", "value1");
            var option2           = StringOption.CreateRequired("value2 option", "value2");
            var option3           = StringOption.CreateRequired("value3 option", "value2");
            var multiStringOption = new SinglePositionalOption <string, string, string, Tuple <string, string, string> >(parse, true, "", option1, option2, option3, "positional-option");

            string[] stringInputArgument =
            {
                "--positional-option", inputArgument1,  inputArgument2,  inputArgument3,
                "--positional-option", inputArgumentB1, inputArgumentB2, inputArgumentB3
            };

            // act
            var result = multiStringOption.Parse(stringInputArgument);

            // assert
            Assert.False(result.Success);
            Assert.Contains("only once", result.ErrorMessage);
        }
コード例 #2
0
ファイル: ModeParserTests.cs プロジェクト: zhang919/canvas
        public void ParseSinglePositionalOption_WithMultipleStringInputArguments_ReturnsMultipleStrings()
        {
            // arrange
            string inputArgument1 = "input";
            string inputArgument2 = "input2";
            string inputArgument3 = "input3";
            Func <string, string, string, IParsingResult <Tuple <string, string, string> > > parse = (value1, value2, value3) => ParsingResult <Tuple <string, string, string> > .SuccessfulResult(Tuple.Create(value1, value2, value3));

            var option1           = StringOption.CreateRequired("value1 option", "value1");
            var option2           = StringOption.CreateRequired("value2 option", "value2");
            var option3           = StringOption.CreateRequired("value3 option", "value2");
            var multiStringOption = new SinglePositionalOption <string, string, string, Tuple <string, string, string> >(parse, true, "", option1, option2, option3, "positional-option");

            string[] stringInputArgument =
            {
                "--positional-option", inputArgument1, inputArgument2, inputArgument3
            };

            // act
            var result = multiStringOption.Parse(stringInputArgument);

            // assert
            Assert.True(result.Success);
            Assert.Equal(inputArgument1, result.Result.Item1);
            Assert.Equal(inputArgument2, result.Result.Item2);
            Assert.Equal(inputArgument3, result.Result.Item3);
        }