public void Should_Pass_Case_5()
            {
                // Given
                var app = new CommandAppFixture();

                app.Configure(config =>
                {
                    config.PropagateExceptions();
                    config.SafetyOff().AddCommand("multi", typeof(OptionVectorCommand));
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "multi", "--foo", "a", "--foo", "b", "--bar", "1", "--foo", "c", "--bar", "2",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <OptionVectorSettings>().And(vec =>
                {
                    vec.Foo.Length.ShouldBe(3);
                    vec.Foo.ShouldBe(new[] { "a", "b", "c" });
                    vec.Bar.Length.ShouldBe(2);
                    vec.Bar.ShouldBe(new[] { 1, 2 });
                });
            }
Ejemplo n.º 2
0
            public void Should_Map_Lookup_Values()
            {
                // Given
                var app = new CommandAppFixture();

                app.WithDefaultCommand <GenericCommand <LookupSettings> >();
                app.Configure(config =>
                {
                    config.PropagateExceptions();
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "--var", "foo=bar",
                    "--var", "foo=qux",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <LookupSettings>().And(pair =>
                {
                    pair.Values.ShouldNotBeNull();
                    pair.Values.Count.ShouldBe(1);
                    pair.Values["foo"].ToList().Count.ShouldBe(2);
                });
            }
Ejemplo n.º 3
0
            public void Should_Map_Latest_Value_Of_Same_Key_When_Mapping_To_Dictionary()
            {
                // Given
                var app = new CommandAppFixture();

                app.WithDefaultCommand <GenericCommand <DictionarySettings> >();
                app.Configure(config =>
                {
                    config.PropagateExceptions();
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "--var", "foo=bar",
                    "--var", "foo=qux",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <DictionarySettings>().And(pair =>
                {
                    pair.Values.ShouldNotBeNull();
                    pair.Values.Count.ShouldBe(1);
                    pair.Values["foo"].ShouldBe("qux");
                });
            }
Ejemplo n.º 4
0
            public void Should_Map_Pairs_To_Pair_Deconstructable_Collection_Using_Default_Deconstructort()
            {
                // Given
                var app = new CommandAppFixture();

                app.WithDefaultCommand <GenericCommand <DefaultPairDeconstructorSettings> >();
                app.Configure(config =>
                {
                    config.PropagateExceptions();
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "--var", "foo=1",
                    "--var", "foo=3",
                    "--var", "bar=4",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <DefaultPairDeconstructorSettings>().And(pair =>
                {
                    pair.Values.ShouldNotBeNull();
                    pair.Values.Count.ShouldBe(2);
                    pair.Values["foo"].ShouldBe(3);
                    pair.Values["bar"].ShouldBe(4);
                });
            }
            public void Should_Map_ReadOnly_Dictionary_Values()
            {
                // Given
                var app = new CommandAppFixture();

                app.WithDefaultCommand <GenericCommand <ReadOnlyDictionarySettings> >();
                app.Configure(config =>
                {
                    config.PropagateExceptions();
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "--var", "foo=bar",
                    "--var", "baz=qux",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <ReadOnlyDictionarySettings>().And(pair =>
                {
                    pair.Values.ShouldNotBeNull();
                    pair.Values.Count.ShouldBe(2);
                    pair.Values["foo"].ShouldBe("bar");
                    pair.Values["baz"].ShouldBe("qux");
                });
            }
            public void Should_Pass_Case_6()
            {
                // Given
                var app = new CommandAppFixture();

                app.Configure(config =>
                {
                    config.PropagateExceptions();
                    config.AddCommand <GenericCommand <ArgumentVectorSettings> >("multi");
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "multi", "a", "b", "c",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <ArgumentVectorSettings>().And(vec =>
                {
                    vec.Foo.Length.ShouldBe(3);
                    vec.Foo.ShouldBe(new[] { "a", "b", "c" });
                });
            }
            public void Should_Pass_Case_4()
            {
                // Given
                var app = new CommandAppFixture();

                app.Configure(config =>
                {
                    config.PropagateExceptions();
                    config.SafetyOff().AddBranch("animal", typeof(AnimalSettings), animal =>
                    {
                        animal.AddCommand("dog", typeof(DogCommand));
                    });
                });

                // When
                var(result, _, _, settings) = app.Run(new[]
                {
                    "animal", "4", "dog", "12",
                    "--good-boy", "--name", "Rufus",
                });

                // Then
                result.ShouldBe(0);
                settings.ShouldBeOfType <DogSettings>().And(dog =>
                {
                    dog.Legs.ShouldBe(4);
                    dog.Age.ShouldBe(12);
                    dog.GoodBoy.ShouldBe(true);
                    dog.IsAlive.ShouldBe(false);
                    dog.Name.ShouldBe("Rufus");
                });
            }
Ejemplo n.º 8
0
            public void Should_Not_Propagate_Exceptions_If_Not_Explicitly_Told_To_Do_So()
            {
                // Given
                var app = new CommandAppFixture();

                app.Configure(config =>
                {
                    config.AddCommand <ThrowingCommand>("throw");
                });

                // When
                var(result, _, _, _) = app.Run(new[] { "throw" });

                // Then
                result.ShouldBe(-1);
            }
Ejemplo n.º 9
0
            public void Should_Dump_Correct_Model_For_Model_With_Default_Command(string expected)
            {
                // Given
                var fixture = new CommandAppFixture().WithDefaultCommand <DogCommand>();

                fixture.Configure(config =>
                {
                    config.AddCommand <HorseCommand>("horse");
                });

                // When
                var(_, output, _, _) = fixture.Run(Constants.XmlDocCommand);

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 10
0
            public void Should_Dump_Correct_Model_For_Case_2(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(config =>
                {
                    config.AddCommand <DogCommand>("dog");
                });

                // When
                var(_, output, _, _) = fixture.Run(Constants.XmlDocCommand);

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 11
0
            public Task Should_Dump_Correct_Model_For_Case_2()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(config =>
                {
                    config.AddCommand <DogCommand>("dog");
                });

                // When
                var(_, output, _, _) = fixture.Run(Constants.XmlDocCommand);

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 12
0
            public Task Should_Dump_Correct_Model_For_Model_With_Default_Command()
            {
                // Given
                var fixture = new CommandAppFixture().WithDefaultCommand <DogCommand>();

                fixture.Configure(config =>
                {
                    config.AddCommand <HorseCommand>("horse");
                });

                // When
                var(_, output, _, _) = fixture.Run(Constants.XmlDocCommand);

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 13
0
            public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddCommand <NoDescriptionCommand>("bar");
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 14
0
            public void Should_Output_Default_Command_Correctly(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.WithDefaultCommand <LionCommand>();
                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 15
0
            public Task Should_List_Arguments_In_Correct_Order()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.WithDefaultCommand <GenericCommand <ArgumentOrderSettings> >();
                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 16
0
            public Task Should_Output_Default_Command_Correctly()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.WithDefaultCommand <LionCommand>();
                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
            public void Should_Throw_If_Value_Is_Not_In_A_Valid_Format_Using_Default_Deconstructor(
                string input, string expected)
            {
                // Given
                var app = new CommandAppFixture();

                app.WithDefaultCommand <GenericCommand <DefaultPairDeconstructorSettings> >();

                // When
                var(result, output, _, settings) = app.Run(new[]
                {
                    "--var", input,
                });

                // Then
                result.ShouldBe(-1);
                output.ShouldBe(expected);
            }
Ejemplo n.º 18
0
            public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.WithDefaultCommand <LionCommand>();
                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddExample(new[] { "12", "-c", "3" });
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 19
0
            public void Should_Output_Root_Examples_If_Default_Command_Is_Specified(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.WithDefaultCommand <LionCommand>();
                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddExample(new[] { "12", "-c", "3" });
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 20
0
            public Task Should_Output_Root_Correctly()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddCommand <DogCommand>("dog");
                    configurator.AddCommand <HorseCommand>("horse");
                    configurator.AddCommand <GiraffeCommand>("giraffe");
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 21
0
            public void Should_Skip_Hidden_Commands(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddCommand <DogCommand>("dog");
                    configurator.AddCommand <HorseCommand>("horse");
                    configurator.AddCommand <GiraffeCommand>("giraffe").IsHidden();
                });

                // When
                var(_, output, _, _) = fixture.Run("--help");

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 22
0
            public void Should_Dump_Correct_Model_For_Case_3(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(config =>
                {
                    config.AddBranch <AnimalSettings>("animal", animal =>
                    {
                        animal.AddCommand <DogCommand>("dog");
                        animal.AddCommand <HorseCommand>("horse");
                    });
                });

                // When
                var(_, output, _, _) = fixture.Run(Constants.XmlDocCommand);

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 23
0
            public Task Should_Dump_Correct_Model_For_Case_3()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(config =>
                {
                    config.AddBranch <AnimalSettings>("animal", animal =>
                    {
                        animal.AddCommand <DogCommand>("dog");
                        animal.AddCommand <HorseCommand>("horse");
                    });
                });

                // When
                var(_, output, _, _) = fixture.Run(Constants.XmlDocCommand);

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 24
0
        public void Should_Throw_If_Required_Argument_Have_Default_Value()
        {
            // Given
            var app = new CommandAppFixture();

            app.WithDefaultCommand <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.");
            });
        }
Ejemplo n.º 25
0
            public void Should_Not_Propagate_Runtime_Exceptions_If_Not_Explicitly_Told_To_Do_So()
            {
                // Given
                var app = new CommandAppFixture();

                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.ShouldBe(-1);
            }
Ejemplo n.º 26
0
            public void Should_Output_Root_Examples_Defined_On_Root(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(configurator =>
                {
                    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(_, output, _, _) = fixture.Run("--help");

                // Then
                output.ShouldBe(expected);
            }
Ejemplo n.º 27
0
            public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples()
            {
                // Given
                var fixture = new CommandAppFixture();

                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(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 28
0
            public Task Should_Output_Leaf_Correctly()
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddBranch <CatSettings>("cat", animal =>
                    {
                        animal.SetDescription("Contains settings for a cat.");
                        animal.AddCommand <LionCommand>("lion");
                    });
                });

                // When
                var(_, output, _, _) = fixture.Run("cat", "lion", "--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 29
0
            public Task Should_Skip_Hidden_Commands()
            {
                // Given
                var fixture = new CommandAppFixture();

                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(_, output, _, _) = fixture.Run("--help");

                // Then
                return(Verifier.Verify(output));
            }
Ejemplo n.º 30
0
            public void Should_Output_Leaf_Correctly(string expected)
            {
                // Given
                var fixture = new CommandAppFixture();

                fixture.Configure(configurator =>
                {
                    configurator.SetApplicationName("myapp");
                    configurator.AddBranch <CatSettings>("cat", animal =>
                    {
                        animal.SetDescription("Contains settings for a cat.");
                        animal.AddCommand <LionCommand>("lion");
                    });
                });

                // When
                var(_, output, _, _) = fixture.Run("cat", "lion", "--help");

                // Then
                output.ShouldBe(expected);
            }