public void CommandLineHelpCommandShouldUseOrder()
        {
            var commandRepository = Substitute.For <ICommandRepository>();

            commandRepository.GetCommandsInfo()
            .Returns(new List <CommandInfo>()
            {
                new CommandInfo()
                {
                    Name = "command1", Description = "The first command.", Order = 2
                },
                new CommandInfo()
                {
                    Name = "command2", Order = 1
                },
            });

            var memoryOutput           = new MemoryOutput();
            var commandLineHelpCommand = new CommandLineHelpCommand(commandRepository, memoryOutput);

            commandLineHelpCommand.Execute();

            var command1position = memoryOutput.Content.IndexOf(memoryOutput.Content.First(l => l.Contains("command1")));
            var command2position = memoryOutput.Content.IndexOf(memoryOutput.Content.First(l => l.Contains("command2")));

            Assert.IsTrue(command1position > command2position);
        }
Exemplo n.º 2
0
        private static bool OnCommandLineHelpCommand(ILogger logger, CommandLineHelpOptions opts)
        {
            var configurationProvider = GetConfigurationProvider(opts);
            var command = new CommandLineHelpCommand(logger, configurationProvider.GetCommandLineHelpConfiguration());

            return(command.Execute());
        }
        public void CommandLineHelpCommandShouldReturnAllCommandInfo()
        {
            var memoryOutput           = new MemoryOutput();
            var commandLineHelpCommand = new CommandLineHelpCommand(_commandRepository, memoryOutput);

            commandLineHelpCommand.Execute();

            Assert.IsTrue(memoryOutput.Content.Any(l => l.Contains("command1")));
            Assert.IsTrue(memoryOutput.Content.Any(l => l.Contains("command2")));
        }
        public void CommandLineHelpCommandShouldShowNoCommandsMessageIfThereAreNoCommands()
        {
            var emptyCommandRepository = Substitute.For <ICommandRepository>();

            emptyCommandRepository.GetCommandsInfo().Returns(new List <CommandInfo>());

            var memoryOutput           = new MemoryOutput();
            var commandLineHelpCommand = new CommandLineHelpCommand(emptyCommandRepository, memoryOutput);

            commandLineHelpCommand.Execute();

            Assert.IsTrue(memoryOutput.Content.Any(l => l.Contains("There are no commands.")));
        }
Exemplo n.º 5
0
        public override bool Execute()
        {
            if (!ValidateParameters())
            {
                return(false);
            }

            var configuration = GetConfigurationProvider().GetCommandLineHelpConfiguration();
            var command       = new CommandLineHelpCommand(Logger, configuration);
            var success       = command.Execute();

            return(success && (Log.HasLoggedErrors == false));
        }
Exemplo n.º 6
0
        public void Execute_returns_false_if_AssemblyPath_is_invalid(string assemblyPath)
        {
            // ARRANGE
            var configuration = new CommandLineHelpConfiguration()
            {
                AssemblyPath = assemblyPath,
                OutputPath   = "./some-output-path"
            };

            var sut = new CommandLineHelpCommand(m_Logger, configuration);

            // ACT
            var success = sut.Execute();

            // ASSERT
            Assert.False(success);
        }
Exemplo n.º 7
0
        public void Execute_generates_commandlinehelp_output()
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();

            var assemblyPath         = Path.Combine(temporaryDirectory, $"myAssembly.dll");
            var xmlDocumentationPath = Path.ChangeExtension(assemblyPath, ".xml");
            var outputPath           = Path.Combine(temporaryDirectory, "output");

            CompileToFile(@"
                using CommandLine;

                public class Class1
                {
                    [Option(""option1"", Required = true)]
                    public string Option1 { get; set; }

                    [Option(""option2"", Required = true)]
                    public int Option2 { get; set; }

                    [Option(""option3"", Required = true)]
                    public int Option3 { get; set; }
                }
            ", assemblyPath, xmlDocumentationPath);

            var configuration = new CommandLineHelpConfiguration()
            {
                AssemblyPath = assemblyPath,
                OutputPath   = outputPath
            };

            var sut = new CommandLineHelpCommand(m_Logger, configuration);

            // ACT
            var success = sut.Execute();

            // ASSERT
            Assert.True(success);
            Assert.True(Directory.Exists(outputPath));
            Assert.True(File.Exists(Path.Combine(outputPath, "index.md")));
        }
Exemplo n.º 8
0
        public void Execute_returns_false_if_OutputPath_is_invalid(string outputPath)
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();
            var assemblyPath = Path.Combine(temporaryDirectory, "myAssembly.dll");

            File.WriteAllText(assemblyPath, "");

            var configuration = new CommandLineHelpConfiguration()
            {
                AssemblyPath = assemblyPath,
                OutputPath   = outputPath
            };

            var sut = new CommandLineHelpCommand(m_Logger, configuration);

            // ACT
            var success = sut.Execute();

            // ASSERT
            Assert.False(success);
        }