Exemple #1
0
        public async Task ExecuteAsync_WithoutHistoryOption_AvoidsAddingCommandsExecutedFromScriptToCommandHistory()
        {
            string commands = @"set header name value1 value2";

            if (!File.Exists(_pathToScript))
            {
                File.WriteAllText(_pathToScript, commands);
            }

            string parseResultSections = "run " + _pathToScript;

            ArrangeInputs(parseResultSections: parseResultSections,
                          out MockedShellState _,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            IShellState      shellState       = GetShellState(commands, httpState);
            MockedFileSystem mockedFileSystem = new MockedFileSystem();

            mockedFileSystem.AddFile(_pathToScript, commands);
            RunCommand runCommand = new RunCommand(mockedFileSystem);

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

            string previousCommand = shellState.CommandHistory.GetPreviousCommand();

            Assert.True(string.IsNullOrEmpty(previousCommand));
        }
Exemple #2
0
        public async Task DesktopApp_WithKestrel_WorksWhenRun(string project, string url, string framework)
        {
            // Disabled due to https://github.com/dotnet/cli/issues/2428
            if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
            {
                return;
            }

            var testInstance = GetTestInstance()
                               .WithLockFiles()
                               .WithBuildArtifacts();

            Task exec    = null;
            var  command = new RunCommand(Path.Combine(testInstance.TestRoot, project), framework);

            try
            {
                exec = command.ExecuteAsync(url);
                NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}");
                NetworkHelper.TestGetRequest(url, url);
            }
            finally
            {
                command.KillTree();
            }
            if (exec != null)
            {
                await exec;
            }
        }
Exemple #3
0
        public async Task ExecuteAsync_IfFileDoesNotExist_WritesToConsoleManagerError()
        {
            ArrangeInputs(parseResultSections: "run InputFileForRunCommand.txt",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            RunCommand runCommand = new RunCommand(new MockedFileSystem());
            await runCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            VerifyErrorMessageWasWrittenToConsoleManagerError(shellState);
        }
Exemple #4
0
        static int Main(string[] args)
        {
            ServicePointManager.UseNagleAlgorithm      = false;
            ServicePointManager.DefaultConnectionLimit = int.MaxValue;

            Trace.Listeners.Add(new ColorConsoleTraceListener());

            PrintHeader();

            return(Parser.Default.ParseArguments <RunOptions>(args)
                   .MapResult(
                       (RunOptions opts) => AsyncHelper.RunSync(() => RunCommand.ExecuteAsync(opts)),
                       errs => 1));
        }
Exemple #5
0
        public void ItRunsKestrelStandaloneApp()
        {
            TestInstance instance = TestAssetsManager.CreateTestInstance(KestrelSampleBase)
                                    .WithLockFiles();

            var url        = NetworkHelper.GetLocalhostUrlWithFreePort();
            var args       = $"{url} {Guid.NewGuid().ToString()}";
            var runCommand = new RunCommand(Path.Combine(instance.TestRoot, KestrelStandalone));

            try
            {
                runCommand.ExecuteAsync(args);
                NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {KestrelStandalone} @ {url}");
                NetworkHelper.TestGetRequest(url, args);
            }
            finally
            {
                runCommand.KillTree();
            }
        }
Exemple #6
0
        public async Task ExecuteAsync_WithValidInput_ExecutesTheCommandsInTheScript()
        {
            string commands = @"set header name value1 value2";

            if (!File.Exists(_pathToScript))
            {
                File.WriteAllText(_pathToScript, commands);
            }

            string parseResultSections = "run " + _pathToScript;

            ArrangeInputs(parseResultSections: parseResultSections,
                          out MockedShellState _,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            IShellState      shellState       = GetShellState(commands, httpState);
            MockedFileSystem mockedFileSystem = new MockedFileSystem();

            mockedFileSystem.AddFile(_pathToScript, commands);
            RunCommand runCommand = new RunCommand(mockedFileSystem);

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

            Dictionary <string, IEnumerable <string> >   headers      = httpState.Headers;
            KeyValuePair <string, IEnumerable <string> > firstHeader  = headers.First();
            KeyValuePair <string, IEnumerable <string> > secondHeader = headers.ElementAt(1);

            Assert.Equal(2, httpState.Headers.Count);
            Assert.Equal("User-Agent", firstHeader.Key);
            Assert.Equal("HTTP-REPL", firstHeader.Value.First());

            Assert.Equal("name", secondHeader.Key);
            Assert.Equal("value1", secondHeader.Value.First());
            Assert.Equal("value2", secondHeader.Value.ElementAt(1));
        }