Exemple #1
0
        public void Parse_options()
        {
            // Fixture setup
            var expectedOptions = new FakeOptions
                {
                    StringValue = "strvalue", IntSequence = new[] { 1, 2, 3 }
                };
            var sut = new Parser();

            // Exercize system
            var result = sut.ParseArguments<FakeOptions>(new[] { "--stringvalue=strvalue", "-i1", "2", "3" });

            // Verify outcome
            result.Value.ShouldBeEquivalentTo(expectedOptions);
            // Teardown
        }
        public void Parse_options()
        {
            // Fixture setup
            var expectedOptions = new FakeOptions
                {
                    StringValue = "strvalue", IntSequence = new[] { 1, 2, 3 }
                };
            var sut = new Parser();

            // Exercize system
            var result = sut.ParseArguments<FakeOptions>(new[] { "--stringvalue=strvalue", "-i1", "2", "3" });

            // Verify outcome
            result.Value.ShouldHave().AllProperties().EqualTo(expectedOptions);
            Assert.False(result.Errors.Any());
            // Teardown
        }
        public void Explicit_help_request_generates_help_requested_error()
        {
            // Fixture setup
            var fakeOptions = new FakeOptions();
            var expectedResult = ParserResult.Create(
                ParserResultType.Options,
                fakeOptions, new Error[] { new HelpRequestedError() });

            // Exercize system 
            var result = InstanceBuilder.Build(
                () => fakeOptions,
                new[] { "--help" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.True(expectedResult.Equals(result));

            // Teardown
        }
        public void Parse_to_mutable()
        {
            // Fixture setup
            var expectedResult = new FakeOptions { StringValue="strval0", IntSequence=new[] { 9, 7, 8 }, BoolValue = true,  LongValue = 9876543210L };

            // Exercize system
            var result = InstanceBuilder.Build(
                Maybe.Just<Func<FakeOptions>>(() => new FakeOptions()),
                new[] { "--stringvalue=strval0", "-i", "9", "7", "8", "-x", "9876543210" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            expectedResult.ShouldBeEquivalentTo(((Parsed<FakeOptions>)result).Value);

            // Teardown
        }
        }

        [Theory]
        [MemberData("UnParseData")]
            new Parser()
                .FormatCommandLine(options)
                .ShouldBeEquivalentTo(result);
        }

        [Fact]
        public static void UnParsing_instance_with_equal_token_returns_command_line_with_long_option_using_equal_sign()
        public void Explicit_help_request_generates_help_requested_error()
        {
            // Fixture setup
            var fakeOptions = new FakeOptions();
            var expectedResult = new NotParsed<FakeOptions>(
                TypeInfo.Create(typeof(FakeOptions)), new Error[] { new HelpRequestedError() });

            // Exercize system
            var result = InstanceBuilder.Build(
                Maybe.Just<Func<FakeOptions>>(() => fakeOptions),
                new[] { "--help" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            result.ShouldBeEquivalentTo(expectedResult);

            // Teardown
        }
Exemple #8
0
        public void Short_Parameters_names_are_used()
        {
            // Fixture setup
            var expectedOptions = new FakeOptions
            {
                IntSequence = new[] { 1, 2, 3 },
                BoolValue = true
            };
            var sut = new Parser();

            // Exercize system
            var result = sut.ParseArguments<FakeOptions>(new[] { "-x", "-i1", "2", "3" });

            // Verify outcome
            result.Value.ShouldHave().AllProperties().EqualTo(expectedOptions);
            Assert.False(result.Errors.Any());
            // Teardown
        }