예제 #1
0
        public void GetDocument_returns_expected_document_03()
        {
            var model = new MultiCommandApplicationDocumentation("TestApp", version: null)
                        .WithCommand(name: "command1", helpText: "Documentation for command 1")
                        .WithCommand(name: "command2");

            Approve(model);
        }
예제 #2
0
        public static MultiCommandApplicationDocumentation WithCommand(this MultiCommandApplicationDocumentation application, string name, string?helpText = null)
        {
            var command = application.AddCommand(name);

            command.Description = helpText;

            return(application);
        }
예제 #3
0
        public void AddCommand_throws_InvaldModelException_if_command_name_is_null_or_whitespace(string commandName)
        {
            // ARRANGE
            var sut = new MultiCommandApplicationDocumentation("app", "1.0");

            // ACT / ASSERT
            Assert.Throws <InvalidModelException>(() => sut.AddCommand(commandName));
        }
예제 #4
0
        public void Name_and_short_name_must_not_be_both_null_or_empty(string invalidName)
        {
            // ARRANGE
            var application = new MultiCommandApplicationDocumentation("app", "1.2.3");
            var command     = application.AddCommand("command");

            // ACT / ASSERT
            Assert.Throws <ArgumentException>(() => new SwitchParameterDocumentation(application, command, invalidName, invalidName));
        }
예제 #5
0
        public void GetDocument_returns_expected_document_04()
        {
            // commands must be ordered by name
            var model = new MultiCommandApplicationDocumentation(name: "TestApp", version: null)
                        .WithCommand(name: "commandXYZ")
                        .WithCommand(name: "commandAbc");

            Approve(model);
        }
예제 #6
0
        public void GetDocument_returns_expected_document_05()
        {
            // commands must be ordered by name
            var model = new MultiCommandApplicationDocumentation(name: "TestApp", version: "4.5.6")
            {
                Usage = new[] { "usage line 1", "usage line 2", "usage line 3" }
            };

            Approve(model);
        }
예제 #7
0
        private MultiCommandApplicationDocumentation LoadMultiCommandApplication(AssemblyDefinition assembly)
        {
            var name        = GetApplicationName(assembly);
            var version     = assembly.GetInformationalVersionOrVersion();
            var application = new MultiCommandApplicationDocumentation(name, version);

            LoadCommands(application, assembly);

            return(application);
        }
예제 #8
0
        public void AddCommand_throws_InvaldModelException_if_command_with_the_same_name_already_exists(string commandName1, string commandName2)
        {
            // ARRANGE
            var sut = new MultiCommandApplicationDocumentation("app", "1.0");

            _ = sut.AddCommand(commandName1);

            // ACT / ASSERT
            Assert.Throws <InvalidModelException>(() => sut.AddCommand(commandName2));
        }
예제 #9
0
        public void GetDocument_returns_expected_Markdown_for_default_settings()
        {
            var configuration = new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var model = new MultiCommandApplicationDocumentation(name: "TestApp", version: "4.5.6")
            {
                Usage = new[] { "usage line 1", "usage line 2", "usage line 3" }
            };

            Approve(model, configuration);
        }
예제 #10
0
 public MultiCommandApplicationPage(
     DocumentSet <IDocument> documentSet,
     ICommandLineHelpPathProvider pathProvider,
     MultiCommandApplicationDocumentation model,
     CommandLineHelpConfiguration configuration)
 {
     m_DocumentSet   = documentSet ?? throw new ArgumentNullException(nameof(documentSet));
     m_PathProvider  = pathProvider ?? throw new ArgumentNullException(nameof(pathProvider));
     m_Model         = model ?? throw new ArgumentNullException(nameof(model));
     m_Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
예제 #11
0
        public void GetDocument_does_not_include_AutoGenerated_notice_if_the_includeAutoGeneratedNotice_setting_is_false()
        {
            var configuration = new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            configuration.Template.Default.IncludeAutoGeneratedNotice = false;

            var model = new MultiCommandApplicationDocumentation(name: "TestApp", version: "4.5.6")
            {
                Usage = new[] { "usage line 1", "usage line 2", "usage line 3" }
            };

            Approve(model, configuration);
        }
예제 #12
0
        public void GetDocument_returns_expected_document_06()
        {
            var configuration = new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            configuration.Template.Default.IncludeVersion = false;

            var model = new MultiCommandApplicationDocumentation(name: "TestApp", version: "4.5.6")
            {
                Usage = new[] { "usage line 1", "usage line 2", "usage line 3" }
            };

            Approve(model, configuration);
        }
예제 #13
0
        private void LoadCommands(MultiCommandApplicationDocumentation applicationDocumentation, AssemblyDefinition assembly)
        {
            var commandTypes = assembly.MainModule
                               .GetAllTypes()
                               .Where(x => !x.IsAbstract)
                               .WithAttribute(CommandLineParserTypeNames.VerbAttributeFullName)
                               .Where(x => !x.GetAttribute(CommandLineParserTypeNames.VerbAttributeFullName).GetPropertyValueOrDefault <bool>(s_Hidden));


            foreach (var commandType in commandTypes)
            {
                var verbAttribute = commandType.GetAttribute(CommandLineParserTypeNames.VerbAttributeFullName);

                var name = (string)verbAttribute.ConstructorArguments.First(x => x.Type.FullName == SystemTypeNames.StringFullName).Value;

                var commandDocumentation = applicationDocumentation.AddCommand(name);
                commandDocumentation.Description = verbAttribute.GetPropertyValueOrDefault <string>(s_HelpText);

                LoadOptions(commandDocumentation, commandType);

                LoadValues(commandDocumentation, commandType);
            }
        }
예제 #14
0
        private void Approve(MultiCommandApplicationDocumentation model, CommandLineHelpConfiguration?configuration = null)
        {
            var pathProvider = new DefaultCommandLineHelpPathProvider();
            var documentSet  = new DocumentSet <IDocument>();

            // add dummy pages for all commands
            foreach (var command in model.Commands)
            {
                documentSet.Add(pathProvider.GetPath(command), new TextDocument());
            }

            configuration ??= new ConfigurationProvider().GetDefaultCommandLineHelpConfiguration();

            var applicationPage = new MultiCommandApplicationPage(documentSet, pathProvider, model, configuration);

            documentSet.Add(pathProvider.GetPath(model), applicationPage);

            var doc = applicationPage.GetDocument();

            Assert.NotNull(doc);
            var writer = new ApprovalTextWriter(doc.ToString());

            Approvals.Verify(writer, new ApprovalNamer(relativeOutputDirectory: "../../../_referenceResults"), Approvals.GetReporter());
        }
예제 #15
0
        public void GetDocument_returns_expected_document_02()
        {
            var model = new MultiCommandApplicationDocumentation(name: "TestApp", version: "1.2.3-beta");

            Approve(model);
        }
예제 #16
0
        public void GetDocument_returns_expected_document_01()
        {
            var model = new MultiCommandApplicationDocumentation("TestApp", version: null);

            Approve(model);
        }