public void Should_Output_Root_Correctly(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.SetApplicationName("myapp"); configurator.AddCommand <DogCommand>("dog"); configurator.AddCommand <HorseCommand>("horse"); configurator.AddCommand <GiraffeCommand>("giraffe"); // When var result = Fixture.Write(configurator); // Then result.ShouldBe(expected); }
public void Should_Set_Parents_Correctly() { // Given var configurator = new Configurator(null); configurator.AddCommand <AnimalSettings>("animal", animal => { animal.AddCommand <MammalSettings>("mammal", mammal => { mammal.AddCommand <DogCommand>("dog"); mammal.AddCommand <HorseCommand>("horse"); }); }); // When var model = CommandModelBuilder.Build(configurator); // Then model.Commands.Count.ShouldBe(1); model.Commands[0].As(animal => { animal.Parent.ShouldBeNull(); animal.Children.Count.ShouldBe(1); animal.Children[0].As(mammal => { mammal.Parent.ShouldBe(animal); mammal.Children.Count.ShouldBe(2); mammal.Children[0].As(dog => dog.Parent.ShouldBe(mammal)); mammal.Children[1].As(horse => horse.Parent.ShouldBe(mammal)); }); }); }
public void Should_Shadow_Options_Declared_In_Parent_Command_If_Settings_Are_Of_Same_Type() { // Given var configurator = new Configurator(null); configurator.AddCommand <MammalSettings>("mammal", mammal => { mammal.AddCommand <HorseCommand>("horse"); }); // When var model = CommandModelBuilder.Build(configurator); // Then model.Commands[0].As(mammal => { mammal.GetOption(option => option.LongName == "name").As(o1 => { o1.ShouldNotBeNull(); o1.IsShadowed.ShouldBe(false); }); mammal.Children[0].As(horse => { horse.GetOption(option => option.LongName == "name").As(o2 => { o2.ShouldNotBeNull(); o2.IsShadowed.ShouldBe(true); }); }); }); }
public void Should_Set_Descriptions_For_Proxy_Commands() { // Given var configurator = new Configurator(null); configurator.AddCommand <AnimalSettings>("animal", animal => { animal.SetDescription("An animal"); animal.AddCommand <MammalSettings>("mammal", mammal => { mammal.SetDescription("A mammal"); mammal.AddCommand <DogCommand>("dog"); mammal.AddCommand <HorseCommand>("horse"); }); }); // When var model = CommandModelBuilder.Build(configurator); // Then model.Commands[0].As(animal => { animal.Description.ShouldBe("An animal"); animal.Children[0].As(mammal => { mammal.Description.ShouldBe("A mammal"); }); }); }
public void Should_Make_Shadowed_Options_Non_Required() { // Given var configurator = new Configurator(null); configurator.AddCommand <MammalSettings>("mammal", mammal => { mammal.AddCommand <HorseCommand>("horse"); }); // When var model = CommandModelBuilder.Build(configurator); // Then model.Commands[0].As(mammal => { mammal.Children[0].As(horse => { horse.GetOption(option => option.LongName == "name").As(o2 => { o2.ShouldNotBeNull(); o2.Required.ShouldBe(false); }); }); }); }
public void Should_Output_Root_Examples_Defined_On_Root(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.SetApplicationName("myapp"); configurator.AddExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); configurator.AddExample(new[] { "horse", "--name", "Brutus" }); configurator.AddCommand <DogCommand>("dog"); configurator.AddCommand <HorseCommand>("horse"); // When var result = Fixture.Write(configurator); // Then result.ShouldBe(expected); }
public void Should_Allow_Special_Symbols_In_Name(string option) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.AddCommand <DogCommand>("dog"); // When var result = Fixture.GetParseMessage(new[] { "dog", option }, configurator, shouldThrowOnSuccess: false); // Then result.ShouldBeNull(); }
public void Should_Return_Correct_Text(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.AddCommand <DogCommand>("dog"); // When var result = Fixture.GetParseMessage(new[] { "dog", "--f€oo" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Return_Correct_Text(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.AddCommand <GiraffeCommand>("giraffe"); // When var result = Fixture.GetParseMessage(new[] { "giraffe", "foo", "bar", "baz" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Return_Correct_Text_For_Unknown_Command_When_Current_Command_Has_No_Arguments(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.AddCommand <EmptyCommand>("empty"); // When var result = Fixture.GetParseMessage(new[] { "empty", "other" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Return_Correct_Text_With_Suggestion_And_No_Arguments_When_Root_Command_Is_Unknown_And_Distance_Is_Small(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar(), typeof(GenericCommand <EmptySettings>)); configurator.AddCommand <GenericCommand <EmptySettings> >("cat"); // When var result = Fixture.GetParseMessage(new[] { "bat" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Return_Correct_Text_For_Expected_Short_Option_Value(string expected, char separator) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.AddCommand <DogCommand>("dog"); // When var result = Fixture.GetParseMessage(new[] { "dog", $"-f{separator}" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Return_Correct_Text_With_Suggestion_When_Root_Command_Followed_By_Argument_Is_Unknown_And_Distance_Is_Small(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.SetDefaultCommand <GenericCommand <EmptyCommandSettings> >(); configurator.AddCommand <CatCommand>("cat"); // When var result = Fixture.GetParseMessage(new[] { "bat", "14" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Return_Correct_Text_For_Short_Option_If_Strict_Mode_Is_Enabled(string expected) { // Given var configurator = new Configurator(new FakeTypeRegistrar()); configurator.UseStrictParsing(); configurator.AddCommand <DogCommand>("dog"); // When var result = Fixture.GetParseMessage(new[] { "dog", "-u" }, configurator); // Then result.ShouldBe(expected); }
public void Should_Set_Default_Value_For_Options() { // Given var configurator = new Configurator(null); configurator.AddCommand <CatCommand>("cat"); // When var model = CommandModelBuilder.Build(configurator); // Then model.Commands[0] .GetOption(option => option.LongNames.Contains("agility", StringComparer.Ordinal)) .DefaultValue.Value.ShouldBe(10); }
public void Should_Set_TypeConverter_For_Options() { // Given var configurator = new Configurator(null); configurator.AddCommand <CatCommand>("cat"); // When var model = CommandModelBuilder.Build(configurator); // Then model.Commands[0] .GetOption(option => option.LongNames.Contains("agility", StringComparer.Ordinal)) .Converter.ConverterTypeName .ShouldStartWith("Spectre.Cli.Tests.Data.Converters.CatAgilityConverter"); }
public void Should_Create_Configured_Commands_Correctly() { // Given var configurator = new Configurator(null); configurator.AddCommand <AnimalSettings>("animal", animal => { animal.AddCommand <MammalSettings>("mammal", mammal => { mammal.AddCommand <DogCommand>("dog"); mammal.AddCommand <HorseCommand>("horse"); }); }); // When var commands = configurator.Commands; // Then commands.Count.ShouldBe(1); commands[0].As(animal => { animal.ShouldBeProxy <AnimalSettings>(); animal.Children.Count.ShouldBe(1); animal.Children[0].As(mammal => { mammal.ShouldBeProxy <MammalSettings>(); mammal.Children.Count.ShouldBe(2); mammal.Children[0].As(dog => { dog.ShouldBeCommand <DogCommand, DogSettings>(); dog.Children.Count.ShouldBe(0); }); mammal.Children[1].As(horse => { horse.ShouldBeCommand <HorseCommand, MammalSettings>(); horse.Children.Count.ShouldBe(0); }); }); }); }