public void Property_must_have_a_type_that_implements_IEnumerable_in_order_to_be_bound_from_multiple_argument_values() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.Int), "1", "2", "3") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void Property_of_custom_type_that_implements_IEnumerable_can_only_be_bound_if_that_type_has_a_constructor_accepting_an_array() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(UnsupportedEnumerablePropertyTypeCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(UnsupportedEnumerablePropertyTypeCommand.Option), "foo", "bar") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void Property_of_non_nullable_type_can_only_be_bound_if_the_argument_value_is_set() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.Int)) .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void Property_must_have_a_type_supported_by_the_framework_in_order_to_be_bound() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(UnsupportedPropertyTypeCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(UnsupportedPropertyTypeCommand.Option), "foo") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void Property_annotated_as_parameter_must_always_be_bound_to_some_value() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(ParametersCommand) }); var input = new CommandLineInputBuilder() .AddUnboundArgument("foo") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void Property_annotated_as_a_required_option_must_always_be_bound_to_some_value() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(RequiredOptionCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(RequiredOptionCommand.OptionA), "foo") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void All_provided_option_arguments_must_be_bound_to_corresponding_properties() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption("not-a-real-option", "boom") .AddOption("fake-option", "poof") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void All_provided_parameter_arguments_must_be_bound_to_corresponding_properties() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(NoParameterCommand) }); var input = new CommandLineInputBuilder() .AddUnboundArgument("boom") .AddUnboundArgument("poof") .AddOption(nameof(NoParameterCommand.OptionA), "foo") .AddOption(nameof(NoParameterCommand.OptionB), "bar") .Build(); // Act & assert Assert.Throws <CliFxException>(() => schema.InitializeEntryPoint(input)); }
public void Property_of_type_string_array_is_bound_directly_from_the_argument_values() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.StringArray), "foo", "bar") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { StringArray = new[] { "foo", "bar" } }); }
public void Property_of_a_type_that_has_a_static_Parse_method_accepting_a_string_and_format_provider_is_bound_by_invoking_the_method() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.TestStringParseableWithFormatProvider), "foobar") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { TestStringParseableWithFormatProvider = StringParseableWithFormatProvider.Parse("foobar", CultureInfo.InvariantCulture) }); }
public void Property_of_an_array_of_type_that_has_a_constructor_accepting_a_string_is_bound_by_invoking_the_constructor_with_the_argument_values() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.TestStringConstructableArray), "foo", "bar") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { TestStringConstructableArray = new[] { new StringConstructable("foo"), new StringConstructable("bar") } }); }
public void Property_of_a_nullable_enum_type_is_bound_as_null_if_the_argument_value_is_not_set() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.CustomEnumNullable)) .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { CustomEnumNullable = null }); }
public void Property_of_type_DateTimeOffset_is_bound_by_parsing_the_argument_value() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.DateTimeOffset), "28 Apr 1995") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { DateTimeOffset = new DateTime(1995, 04, 28) }); }
public void Property_of_type_decimal_is_bound_by_parsing_the_argument_value() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.Decimal), "123.45") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { Decimal = 123.45M }); }
public void Property_of_type_nullable_int_array_is_bound_by_parsing_the_argument_values() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.IntNullableArray), "3", "14") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { IntNullableArray = new int?[] { 3, 14 } }); }
public void Property_of_type_char_is_bound_directly_from_the_argument_value_if_it_contains_only_one_character() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.Char), "a") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { Char = 'a' }); }
public void Property_of_type_bool_is_bound_as_false_if_the_argument_value_is_false() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.Bool), "false") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { Bool = false }); }
public void Property_of_type_nullable_TimeSpan_is_bound_by_parsing_the_argument_value_if_it_is_set() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.TimeSpanNullable), "00:14:59") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { TimeSpanNullable = new TimeSpan(00, 14, 59) }); }
public void Property_of_an_enum_array_type_is_bound_by_parsing_the_argument_values_as_either_names_or_ids() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(AllSupportedTypesCommand) }); var input = new CommandLineInputBuilder() .AddOption(nameof(AllSupportedTypesCommand.CustomEnumArray), "value1", "3") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new AllSupportedTypesCommand { CustomEnumArray = new[] { CustomEnum.Value1, CustomEnum.Value3 } }); }
public void Property_annotated_as_an_option_can_be_bound_from_multiple_values_even_if_the_inputs_use_mixed_naming() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(ArrayOptionCommand) }); var input = new CommandLineInputBuilder() .AddOption("option", "foo") .AddOption("o", "bar") .AddOption("option", "baz") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new ArrayOptionCommand { Option = new[] { "foo", "bar", "baz" } }); }
public void Property_annotated_as_parameter_is_bound_directly_from_argument_value_according_to_the_order() { // Arrange var schema = ApplicationSchema.Resolve(new[] { typeof(ParametersCommand) }); var input = new CommandLineInputBuilder() .AddUnboundArgument("foo") .AddUnboundArgument("bar") .AddUnboundArgument("hello") .AddUnboundArgument("world") .Build(); // Act var command = schema.InitializeEntryPoint(input); // Assert command.Should().BeEquivalentTo(new ParametersCommand { ParameterA = "foo", ParameterB = "bar", ParameterC = new[] { "hello", "world" } }); }