public Task Should_List_Arguments_In_Correct_Order() { // Given var fixture = new CommandAppTester(); fixture.SetDefaultCommand <GenericCommand <ArgumentOrderSettings> >(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Not_Show_Hidden_Command_Options() { // Given var fixture = new CommandAppTester(); fixture.SetDefaultCommand <GenericCommand <HiddenOptionSettings> >(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Output_Default_Command_Correctly() { // Given var fixture = new CommandAppTester(); fixture.SetDefaultCommand <LionCommand>(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description() { // Given var fixture = new CommandAppTester(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddCommand <NoDescriptionCommand>("bar"); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public void Should_Not_Override_Value_If_Value_Was_Specified() { // Given var app = new CommandAppTester(); app.SetDefaultCommand <GenericCommand <ValueProviderSettings> >(); app.Configure(config => config.PropagateExceptions()); // When var result = app.Run("--foo", "12"); // Then result.Settings.ShouldBeOfType <ValueProviderSettings>().And(settings => { settings.Foo.ShouldBe("C"); // 12 is 0xC }); }
public void Should_Use_Provided_Value_If_No_Value_Was_Specified() { // Given var app = new CommandAppTester(); app.SetDefaultCommand <GenericCommand <ValueProviderSettings> >(); app.Configure(config => config.PropagateExceptions()); // When var result = app.Run(); // Then result.Settings.ShouldBeOfType <ValueProviderSettings>().And(settings => { settings.Foo.ShouldBe("20"); // 32 is 0x20 }); }
public Task Should_Dump_Correct_Model_For_Model_With_Default_Command() { // Given var fixture = new CommandAppTester(); fixture.SetDefaultCommand <DogCommand>(); fixture.Configure(config => { config.AddCommand <HorseCommand>("horse"); }); // When var result = fixture.Run(Constants.XmlDocCommand); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified() { // Given var fixture = new CommandAppTester(); fixture.SetDefaultCommand <LionCommand>(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddExample(new[] { "12", "-c", "3" }); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public void Should_Throw_If_Value_Is_Not_In_A_Valid_Format_Using_Default_Deconstructor( string input, string expected) { // Given var app = new CommandAppTester(); app.SetDefaultCommand <GenericCommand <DefaultPairDeconstructorSettings> >(); // When var result = app.Run(new[] { "--var", input, }); // Then result.ExitCode.ShouldBe(-1); result.Output.ShouldBe(expected); }
public void PathToCsProjFileIsSetButNoValueGiven() { var app = new CommandAppTester(); app.Configure(config => { // config.PropagateExceptions(); config.AddCommand <CheckCommand>("check"); }); CommandAppResult result = app.Run(new[] { "check", "--csprojFile" }); // No .csproj file is given or can be found, so we expect -1 Assert.Equal(-1, result.ExitCode); Assert.StartsWith( "Error: Option 'csprojFile' is defined but no value has been provided.", result.Output ); }
public Task Should_Dump_Correct_Model_For_Case_4() { // Given var fixture = new CommandAppTester(); fixture.Configure(config => { config.AddBranch <AnimalSettings>("animal", animal => { animal.AddCommand <DogCommand>("dog"); }); }); // When var result = fixture.Run(Constants.XmlDocCommand); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Output_Root_Correctly() { // Given var fixture = new CommandAppTester(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddCommand <DogCommand>("dog"); configurator.AddCommand <HorseCommand>("horse"); configurator.AddCommand <GiraffeCommand>("giraffe"); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples() { // Given var fixture = new CommandAppTester(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddCommand <DogCommand>("dog") .WithExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" }); configurator.AddCommand <HorseCommand>("horse") .WithExample(new[] { "horse", "--name", "Brutus" }); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public void PathToCsProjFileIsNotSet() { var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.AddCommand <CheckCommand>("check"); }); CommandAppResult result = app.Run(new[] { "check" }); // No .csproj file is given or can be found, so we expect -1 Assert.Equal(-1, result.ExitCode); Assert.NotNull(result.Settings); Assert.IsType <CheckSettings>(result.Settings); CheckSettings settings = result.Settings as CheckSettings; Assert.Null(settings !.PathToCsProjFile); }
public void Should_Not_Propagate_Runtime_Exceptions_If_Not_Explicitly_Told_To_Do_So() { // Given var app = new CommandAppTester(); app.Configure(config => { config.AddBranch <AnimalSettings>("animal", animal => { animal.AddCommand <DogCommand>("dog"); animal.AddCommand <HorseCommand>("horse"); }); }); // When var result = app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" }); // Then result.ExitCode.ShouldBe(-1); }
public void Should_Throw_If_Required_Argument_Have_Default_Value() { // Given var app = new CommandAppTester(); app.SetDefaultCommand <GenericCommand <RequiredArgumentWithDefaultValueSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var result = Record.Exception(() => app.Run(Array.Empty <string>())); // Then result.ShouldBeOfType <CommandConfigurationException>().And(ex => { ex.Message.ShouldBe("The required argument 'GREETING' cannot have a default value."); }); }
public void Should_Assign_Default_Value_To_Optional_Argument_Using_Converter_If_Necessary() { // Given var app = new CommandAppTester(); app.SetDefaultCommand <GenericCommand <OptionalArgumentWithDefaultValueAndTypeConverterSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var result = app.Run(Array.Empty <string>()); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType <OptionalArgumentWithDefaultValueAndTypeConverterSettings>().And(settings => { settings.Greeting.ShouldBe(5); }); }
public void TargetVersionGetsSetToLatest() { var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.AddCommand <UpgradeCommand>("upgrade"); }); CommandAppResult result = app.Run(new[] { "upgrade", "--version", "latest" }); // No .csproj file is given or can be found, so we expect -1 Assert.Equal(-1, result.ExitCode); Assert.NotNull(result.Settings); Assert.IsType <UpgradeSettings>(result.Settings); UpgradeSettings settings = result.Settings as UpgradeSettings; Assert.NotNull(settings !.Version); Assert.Equal("latest", settings !.Version); }
public Task Should_Skip_Hidden_Commands() { // Given var fixture = new CommandAppTester(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddCommand <DogCommand>("dog"); configurator.AddCommand <HorseCommand>("horse"); configurator.AddCommand <GiraffeCommand>("giraffe") .WithExample(new[] { "giraffe", "123" }) .IsHidden(); }); // When var result = fixture.Run("--help"); // Then return(Verifier.Verify(result.Output)); }
public Task Should_Output_Leaf_Correctly() { // Given var fixture = new CommandAppTester(); fixture.Configure(configurator => { configurator.SetApplicationName("myapp"); configurator.AddBranch <CatSettings>("cat", animal => { animal.SetDescription("Contains settings for a cat."); animal.AddCommand <LionCommand>("lion"); }); }); // When var result = fixture.Run("cat", "lion", "--help"); // Then return(Verifier.Verify(result.Output)); }
public void Should_Only_Set_Flag_If_No_Value_Was_Provided() { // Given var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.AddCommand <GenericCommand <FlagSettings> >("foo"); }); // When var result = app.Run(new[] { "foo", "--serve" }); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType <FlagSettings>().And(flag => { flag.Serve.IsSet.ShouldBeTrue(); flag.Serve.Value.ShouldBe(0); }); }
public void Should_Create_Unset_Instance_With_Null_For_Nullable_Value_Type_If_Flag_Was_Not_Set() { // Given var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.AddCommand <GenericCommand <FlagSettingsWithNullableValueType> >("foo"); }); // When var result = app.Run(new[] { "foo" }); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType <FlagSettingsWithNullableValueType>().And(flag => { flag.Serve.IsSet.ShouldBeFalse(); flag.Serve.Value.ShouldBeNull(); }); }
public void Should_Set_Value_To_Default_Value_If_None_Was_Explicitly_Set() { // Given var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.AddCommand <GenericCommand <FlagSettingsWithDefaultValue> >("foo"); }); // When var result = app.Run(new[] { "foo", "--serve" }); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType <FlagSettingsWithDefaultValue>().And(flag => { flag.Serve.IsSet.ShouldBeTrue(); flag.Serve.Value.ShouldBe(987); }); }
public void Should_Handle_Exceptions_If_ExceptionHandler_Is_Set_Using_Action() { // Given var exceptionHandled = false; var app = new CommandAppTester(); app.Configure(config => { config.AddCommand <ThrowingCommand>("throw"); config.SetExceptionHandler(_ => { exceptionHandled = true; }); }); // When var result = app.Run(new[] { "throw" }); // Then result.ExitCode.ShouldBe(-1); exceptionHandled.ShouldBeTrue(); }
public void Should_Add_Unknown_Option_To_Remaining_Arguments_In_Strict_Mode() { // Given var app = new CommandAppTester(); app.Configure(config => { config.UseStrictParsing(); config.PropagateExceptions(); config.AddBranch <AnimalSettings>("animal", animal => { animal.AddCommand <DogCommand>("dog"); }); }); // When var result = app.Run(new[] { "animal", "4", "dog", "12", "--", "--foo", "bar", "-f", "baz", "qux", }); // Then result.Context.ShouldNotBeNull(); result.Context.Remaining.Parsed.Count.ShouldBe(2); result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar" }); result.Context.ShouldHaveRemainingArgument("f", values: new[] { "baz" }); result.Context.Remaining.Raw.Count.ShouldBe(5); result.Context.Remaining.Raw.ShouldBe(new[] { "--foo", "bar", "-f", "baz", "qux", }); }
public void InteractiveIsSetByLongCode() { var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.AddCommand <UpgradeCommand>("upgrade"); }); CommandAppResult result = app.Run(new[] { "upgrade", "--interactive" }); // No .csproj file is given or can be found, so we expect -1 Assert.Equal(-1, result.ExitCode); Assert.NotNull(result.Settings); Assert.IsType <UpgradeSettings>(result.Settings); UpgradeSettings settings = result.Settings as UpgradeSettings; Assert.True(settings !.Interactive); }
public void Should_Output_The_Version_To_The_Console() { // Given var fixture = new CommandAppTester(); fixture.Configure(config => { config.AddBranch <AnimalSettings>("animal", animal => { animal.AddBranch <MammalSettings>("mammal", mammal => { mammal.AddCommand <DogCommand>("dog"); mammal.AddCommand <HorseCommand>("horse"); }); }); }); // When var result = fixture.Run(Constants.VersionCommand); // Then result.Output.ShouldStartWith("Spectre.Cli version "); }
public void Should_Be_Able_To_Set_The_Default_Command() { // Given var app = new CommandAppTester(); app.SetDefaultCommand <DogCommand>(); // When var result = app.Run(new[] { "4", "12", "--good-boy", "--name", "Rufus", }); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType <DogSettings>().And(dog => { dog.Legs.ShouldBe(4); dog.Age.ShouldBe(12); dog.GoodBoy.ShouldBe(true); dog.Name.ShouldBe("Rufus"); }); }
public void Should_Overwrite_Property_Initializer_With_Argument_Value() { // Given var app = new CommandAppTester(); app.SetDefaultCommand <GenericCommand <OptionalArgumentWithPropertyInitializerSettings> >(); app.Configure(config => { config.PropagateExceptions(); }); // When var result = app.Run("-c", "0", "-v", "50", "ABBA", "Herreys"); // Then result.ExitCode.ShouldBe(0); result.Settings .ShouldBeOfType <OptionalArgumentWithPropertyInitializerSettings>() .And(settings => settings.Count.ShouldBe(0)) .And(settings => settings.Value.ShouldBe(50)) .And(settings => settings.Names.ShouldContain("ABBA")) .And(settings => settings.Names.ShouldContain("Herreys")); }
public void Can_Turn_Safety_On_After_Turning_It_Off_For_Branch() { // Given var app = new CommandAppTester(); app.Configure(config => { config.PropagateExceptions(); config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal => { animal.SafetyOn <AnimalSettings>() .AddBranch <MammalSettings>("mammal", mammal => { mammal.SafetyOff().AddCommand("dog", typeof(DogCommand)); mammal.AddCommand <HorseCommand>("horse"); }); }); }); // When var result = app.Run(new[] { "animal", "--alive", "mammal", "--name", "Rufus", "dog", "12", "--good-boy", }); // Then result.ExitCode.ShouldBe(0); result.Settings.ShouldBeOfType <DogSettings>().And(dog => { dog.Age.ShouldBe(12); dog.GoodBoy.ShouldBe(true); dog.Name.ShouldBe("Rufus"); dog.IsAlive.ShouldBe(true); }); }