public void Command_arguments_are_bound_by_name_to_property_setters(
            Type type,
            string commandLine,
            object expectedValue)
        {
            var targetType = typeof(ClassWithSetter <>).MakeGenericType(type);
            var binder     = new TypeBinder(targetType);

            var command = new Command("the-command")
            {
                Argument = new Argument
                {
                    Name         = "value",
                    ArgumentType = type
                }
            };
            var parser = new Parser(command);

            var invocationContext = new InvocationContext(parser.Parse(commandLine), parser);

            var instance = binder.CreateInstance(invocationContext);

            object valueReceivedValue = ((dynamic)instance).Value;

            valueReceivedValue.Should().Be(expectedValue);
        }
        public void Property_setters_with_no_default_value_and_no_matching_option_are_not_called()
        {
            var command = new Command("the-command");

            var binder = new TypeBinder(typeof(ClassWithSettersAndCtorParametersWithDifferentNames));

            foreach (var option in binder.BuildOptions())
            {
                command.Add(option);
            }

            var parser            = new Parser(command);
            var invocationContext = new InvocationContext(
                parser.Parse(""),
                parser);

            var instance = (ClassWithSettersAndCtorParametersWithDifferentNames)binder.CreateInstance(invocationContext);

            instance.StringOption.Should().Be("the default");
        }
        public void Option_arguments_are_bound_by_name_to_constructor_parameters()
        {
            var argument = new Argument <string>("the default");

            var option = new Option("--string-option",
                                    argument: argument);

            var command = new Command("the-command");

            command.AddOption(option);
            var binder = new TypeBinder(typeof(ClassWithMultiLetterCtorParameters));

            var parser            = new Parser(command);
            var invocationContext = new InvocationContext(
                parser.Parse("--string-option not-the-default"),
                parser);

            var instance = (ClassWithMultiLetterCtorParameters)binder.CreateInstance(invocationContext);

            instance.StringOption.Should().Be("not-the-default");
        }
        public void Explicitly_configured_default_values_can_be_bound_to_property_setters()
        {
            var argument = new Argument <string>("the default");

            var option = new Option("--string-option",
                                    argument: argument);

            var command = new Command("the-command");

            command.AddOption(option);
            var binder = new TypeBinder(typeof(ClassWithMultiLetterSetters));

            var parser            = new Parser(command);
            var invocationContext = new InvocationContext(
                parser.Parse(""),
                parser);

            var instance = (ClassWithMultiLetterSetters)binder.CreateInstance(invocationContext);

            instance.StringOption.Should().Be("the default");
        }
        public void Option_arguments_are_bound_by_name_to_property_setters()
        {
            var argument = new Argument <bool>();

            var option = new Option("--bool-option",
                                    argument: argument);

            var command = new Command("the-command");

            command.AddOption(option);
            var binder = new TypeBinder(typeof(ClassWithMultiLetterSetters));

            var parser            = new Parser(command);
            var invocationContext = new InvocationContext(
                parser.Parse("--bool-option"),
                parser);

            var instance = (ClassWithMultiLetterSetters)binder.CreateInstance(invocationContext);

            instance.BoolOption.Should().BeTrue();
        }