Exemple #1
0
        public async Task ListCommand_WithSwagger_ShowsControllerActionsWithHttpVerbs()
        {
            string scriptText = $@"set base {_serverConfig.BaseAddress}
cd api/Values
ls";
            var    console    = new LoggingConsoleManagerDecorator(new NullConsoleManager());

            using (var scriptFile = new TestScript(scriptText))
            {
                await new Program().Start($"run {scriptFile.FilePath}".Split(' '), console);
            }
            string output = console.LoggedOutput;

            // remove the first line because it has the randomly generated script file name.
            output = output.Substring(output.IndexOf(Environment.NewLine) + Environment.NewLine.Length);
            output = NormalizeOutput(output, _serverConfig.BaseAddress);

            string expected = NormalizeOutput(@"(Disconnected)~ set base [BaseUrl]
Using swagger metadata from [BaseUrl]/swagger/v1/swagger.json

[BaseUrl]/~ cd api/Values
/api/Values    [get|post]

[BaseUrl]/api/Values~ ls
.      [get|post]
..     []
{id}   [get|put|delete]

[BaseUrl]/api/Values~", null);

            Assert.Equal(expected, output);
        }
Exemple #2
0
        public void Suggest(string commandText, params string[] expectedResults)
        {
            HttpState        httpState      = GetHttpState(out MockedFileSystem fileSystem, out _);
            ICoreParseResult parseResult    = CreateCoreParseResult(commandText);
            IConsoleManager  consoleManager = new LoggingConsoleManagerDecorator(new NullConsoleManager());
            DefaultCommandDispatcher <HttpState> commandDispatcher = DefaultCommandDispatcher.Create((ss) => { }, httpState);

            commandDispatcher.AddCommand(new ClearCommand());
            commandDispatcher.AddCommand(new ChangeDirectoryCommand());
            commandDispatcher.AddCommand(new RunCommand(fileSystem));
            IShellState shellState = new ShellState(commandDispatcher, consoleManager: consoleManager);

            HelpCommand helpCommand = new HelpCommand();

            IEnumerable <string> result = helpCommand.Suggest(shellState, httpState, parseResult);

            Assert.NotNull(result);

            List <string> resultList = result.ToList();

            Assert.Equal(expectedResults.Length, resultList.Count);

            for (int index = 0; index < expectedResults.Length; index++)
            {
                Assert.Contains(expectedResults[index], resultList, StringComparer.OrdinalIgnoreCase);
            }
        }
Exemple #3
0
        public async Task ListCommand_WithoutSwagger_ShowsNoSubpaths()
        {
            string scriptText = $@"set base {_serverConfig.BaseAddress}
ls
cd api
ls";
            var    console    = new LoggingConsoleManagerDecorator(new NullConsoleManager());

            using (var script = new TestScript(scriptText))
            {
                await new Program().Start($"run {script.FilePath}".Split(' '), console);
            }

            string output = console.LoggedOutput;

            // remove the first line because it has the randomly generated script file name.
            output = output.Substring(output.IndexOf(Environment.NewLine) + Environment.NewLine.Length);
            output = NormalizeOutput(output, _serverConfig.BaseAddress);

            // make sure to normalize newlines in the expected output
            string expected = NormalizeOutput(@"(Disconnected)~ set base [BaseUrl]

[BaseUrl]/~ ls

[BaseUrl]/~ cd api

[BaseUrl]/api~ ls

[BaseUrl]/api~", null);

            Assert.Equal(expected, output);
        }
Exemple #4
0
        public async Task ExecuteAsync_CallsConsoleManagerClear()
        {
            HttpState        httpState   = GetHttpState(out _, out _);
            ICoreParseResult parseResult = CreateCoreParseResult("clear");
            DefaultCommandDispatcher <HttpState> dispatcher     = DefaultCommandDispatcher.Create((ss) => { }, httpState);
            LoggingConsoleManagerDecorator       consoleManager = new LoggingConsoleManagerDecorator(new NullConsoleManager());
            IShellState shellState = new ShellState(dispatcher, consoleManager: consoleManager);

            ClearCommand clearCommand = new ClearCommand();

            await clearCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.True(consoleManager.WasClearCalled);
        }
        protected static async Task <string> RunTestScript(string scriptText, string baseAddress)
        {
            LoggingConsoleManagerDecorator console = new LoggingConsoleManagerDecorator(new NullConsoleManager());
            NullPreferences preferences            = new NullPreferences();

            using (var script = new TestScript(scriptText))
            {
                await new Program().Start($"run {script.FilePath}".Split(' '), console, preferences);
            }

            string output = console.LoggedOutput;

            // remove the first line because it has the randomly generated script file name.
            output = output.Substring(output.IndexOf(Environment.NewLine) + Environment.NewLine.Length);
            output = NormalizeOutput(output, baseAddress);

            return(output);
        }