Ejemplo n.º 1
0
        public void Dispose_Does_Not_Kill_Underlying_Process_If_Still_Running()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithArguments(args => args.Append("--sleep 5000"));

            int processId;

            using (var process = runner.Start(_appExe, settings))
            {
                processId = process.ProcessId;
                process.HasExited.Should().BeFalse();
            }

            using (var p2 = System.Diagnostics.Process.GetProcessById(processId))
            {
                p2.HasExited.Should().BeFalse();
                p2.Kill();
            }
        }
            public void EnvironmentVariable_Key_Should_Not_Be_Null()
            {
                var sut = new AdvProcessSettings();

                sut.Invoking(_ => _.WithEnvironmentVariable(null, "Value1"))
                .ShouldThrow <ArgumentNullException>();
            }
Ejemplo n.º 3
0
        public void Process_WillNotMissOutputViaEvents()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .WithArguments(args => args.Append("--out line1 line2 --echoArgs --delay 100"))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .SetRedirectStandardOutput(true);

            var outputDataReceived = new List <string>();

            using (var process = runner.Start(_appExe, settings))
            {
                process.OutputDataReceived +=
                    (sender, args) => { outputDataReceived.Add(args.Output); };

                process.WaitForExit();

                outputDataReceived.Should()
                .BeEquivalentTo("Args received: --out line1 line2 --echoArgs --delay 100",
                                "line1", "line2");
            }
        }
            public void EnvironmentVariable_Set_Multiple_Times_Should_Use_The_Last_One()
            {
                var settings =
                    new AdvProcessSettings().WithEnvironmentVariable("Key1", "Value1")
                    .WithEnvironmentVariable("Key1", "Value1-A");

                settings.EnvironmentVariables["Key1"].Should().Be("Value1-A");
            }
            public void Should_Return_Settings_With_Correct_EnvironmentVariables()
            {
                var settings =
                    new AdvProcessSettings().WithEnvironmentVariable("Key1", "Value1")
                        .WithEnvironmentVariable("Key2", "Value2");

                settings.EnvironmentVariables["Key1"].Should().Be("Value1");
                settings.EnvironmentVariables["Key2"].Should().Be("Value2");
            }
            public void Should_Return_Settings_With_Correct_EnvironmentVariables()
            {
                var settings =
                    new AdvProcessSettings().WithEnvironmentVariable("Key1", "Value1")
                    .WithEnvironmentVariable("Key2", "Value2");

                settings.EnvironmentVariables["Key1"].Should().Be("Value1");
                settings.EnvironmentVariables["Key2"].Should().Be("Value2");
            }
                public void Should_Return_Process_Created_By_Runner(ICakeContext context,
                    FilePath filePath, AdvProcessSettings settings, IAdvProcessRunner runner,
                    IAdvProcess expectedResult)
                {
                    runner.Start(filePath, settings).Returns(expectedResult);

                    Func<IAdvProcess> sut =
                        () => context.StartAdvProcess(filePath, settings, runner);

                    var result = sut();

                    result.Should().BeSameAs(expectedResult);
                }
Ejemplo n.º 8
0
        /// <summary>
        /// Starts the process.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="toolPath">The tool path.</param>
        /// <param name="processSettings">The process settings.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">arguments</exception>
        /// <exception cref="Cake.Core.CakeException">
        /// </exception>
        protected IAdvProcess StartProcess(TSettings settings, ProcessArgumentBuilder arguments, FilePath toolPath,
                                           AdvProcessSettings processSettings)
        {
            if (arguments == null && (processSettings == null || processSettings.Arguments == null))
            {
                throw new ArgumentNullException("arguments");
            }

            // Get the tool name.
            var toolName = GetToolName();

            // Get the tool path.
            toolPath = GetToolPath(settings, toolPath);
            if (toolPath == null || !_fileSystem.Exist(toolPath))
            {
                const string message = "{0}: Could not locate executable.";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, toolName));
            }

            // Get the working directory.
            var workingDirectory = GetWorkingDirectory(settings);

            if (workingDirectory == null)
            {
                const string message = "{0}: Could not resolve working directory.";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, toolName));
            }

            // Create the process start info.
            var info = processSettings ?? new AdvProcessSettings();

            if (info.Arguments == null)
            {
                info.Arguments = arguments;
            }
            if (info.WorkingDirectory == null)
            {
                info.WorkingDirectory = workingDirectory.MakeAbsolute(_cakeEnvironment).FullPath;
            }

            // Run the process.
            var process = _advProcessRunner.Start(toolPath, info);

            if (process == null)
            {
                const string message = "{0}: Process was not started.";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, toolName));
            }
            return(process);
        }
Ejemplo n.º 9
0
        public void Kill_Process_Returns_Minus1_ExitCode()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithArguments(args => args.Append("--sleep 5000 --exitcode 3"));

            using (var process = runner.Start(_appExe, settings))
            {
                process.Kill();
                process.GetExitCode().Should().Be(-1);
            }
        }
Ejemplo n.º 10
0
        public void Process_Can_Be_Killed()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithArguments(args => args.Append("--sleep 5000"));

            using (var process = runner.Start(_appExe, settings))
            {
                process.Kill();

                process.HasExited.Should().BeTrue();
            }
        }
Ejemplo n.º 11
0
                public void Should_Use_Provided_Working_Directory_If_Set(ICakeContext context,
                                                                         [NoAutoProperties] AdvProcessSettings settings, IAdvProcessRunner runner)
                {
                    // Arrange
                    settings.WorkingDirectory = "/OtherWorking";

                    Action sut =
                        () => context.StartAdvProcess("hello.exe", settings, runner);

                    // Act
                    sut();

                    // Assert
                    runner.Received(1).Start(
                        Arg.Any <FilePath>(),
                        Arg.Is <AdvProcessSettings>(info =>
                                                    info.WorkingDirectory.FullPath == "/OtherWorking"));
                }
Ejemplo n.º 12
0
            public void Process_With_Output_Not_Redirected_Will_Throw()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log         = new FakeLog();
                var runner      = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                    .WithArguments(args => args.Append("--out OutputLine1"))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .SetRedirectStandardOutput(false);

                using (var process = runner.Start(_appExe, settings))
                {
                    process.Invoking(sut => sut.OutputDataReceived += (sender, args) => { })
                    .ShouldThrow <InvalidOperationException>();
                }
            }
Ejemplo n.º 13
0
        public void Process_Should_Return_Correct_Exit_Code()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings().WithArguments(args => args.Append("--exitcode 3"))
                .UseWorkingDirectory(Environment.CurrentDirectory);


            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var exitCode = process.GetExitCode();
                Console.WriteLine(string.Join("\r\n", log.Messages));
                exitCode.Should().Be(3);
            }
        }
Ejemplo n.º 14
0
        public void Process_Should_Return_Correct_Exit_Code()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings().WithArguments(args => args.Append("--exitcode 3"))
                    .UseWorkingDirectory(Environment.CurrentDirectory);


            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var exitCode = process.GetExitCode();
                Console.WriteLine(string.Join("\r\n", log.Messages));
                exitCode.Should().Be(3);
            }
        }
Ejemplo n.º 15
0
        public void Process_Should_Return_Correct_StandardError()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings().WithArguments(
                    args => args.Append("--err \"error line1\" \"error line2\" \"error line3\""))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .SetRedirectStandardError(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var output = process.GetStandardError().ToArray();

                output.Should().BeEquivalentTo("error line1", "error line2", "error line3");
            }
        }
Ejemplo n.º 16
0
                public void Should_Make_Working_Directory_Absolute_If_Set_To_Relative(
                    ICakeContext context,
                    [NoAutoProperties] AdvProcessSettings settings, IAdvProcessRunner runner)
                {
                    // Arrange
                    context.Environment.WorkingDirectory.Returns("/Working");
                    settings.WorkingDirectory = "OtherWorking";

                    Action sut =
                        () => context.StartAdvProcess("hello.exe", settings, runner);

                    // Act
                    sut();

                    // Assert
                    runner.Received(1).Start(
                        Arg.Any <FilePath>(),
                        Arg.Is <AdvProcessSettings>(info =>
                                                    info.WorkingDirectory.FullPath == "/Working/OtherWorking"));
                }
Ejemplo n.º 17
0
        public void Process_Should_Return_Correct_StandardError()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings().WithArguments(
                    args => args.Append("--err \"error line1\" \"error line2\" \"error line3\""))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .SetRedirectStandardError(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var output = process.GetStandardError().ToArray();

                output.Should().BeEquivalentTo("error line1", "error line2", "error line3");
            }
        }
Ejemplo n.º 18
0
        public void Process_Should_Use_Provided_EnvironmentVariables()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                .WithArguments(args => args.Append("--environmentVariables EnvVar1 EnvVar2"))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .WithEnvironmentVariable("EnvVar1", "Value1")
                .WithEnvironmentVariable("EnvVar2", "Value2")
                .SetRedirectStandardOutput(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var output = process.GetStandardOutput().ToArray();

                output.Should().BeEquivalentTo("EnvVar1: 'Value1'", "EnvVar2: 'Value2'");
            }
        }
Ejemplo n.º 19
0
        public void Enumerating_GetStandardError_WillThrowWhenUsingOutputEvents()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log         = new FakeLog();
            var runner      = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                //.WithArguments(args => args.Append("--out line1 line2 --echoArgs --delay 100"))
                .UseWorkingDirectory(Environment.CurrentDirectory)
                .SetRedirectStandardError(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.ErrorDataReceived +=
                    (sender, args) => { };

                process.WaitForExit();

                process.Invoking(p => p.GetStandardError().ToArray())
                .ShouldThrow <InvalidOperationException>();
            }
        }
Ejemplo n.º 20
0
            public void Process_Raises_Exited_Event_With_ExitCode()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log         = new FakeLog();
                var runner      = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings().WithArguments(args => args.Append("--exitcode 3"))
                    .UseWorkingDirectory(Environment.CurrentDirectory);

                var exitCodeUponExit = 0;

                using (var process = runner.Start(_appExe, settings))
                {
                    process.Exited += (sender, args) =>
                    {
                        exitCodeUponExit = args.ExitCode;
                    };

                    process.WaitForExit();

                    exitCodeUponExit.Should().Be(3);
                }
            }
Ejemplo n.º 21
0
            public void Process_Should_Capture_Exited_Event_Added_Before_Start()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log         = new FakeLog();
                var runner      = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                    .WithArguments(args => args.Append("--exitCode 5"))
                    .UseWorkingDirectory(Environment.CurrentDirectory);

                using (var process = runner.Start(_appExe, settings))
                {
                    var exitedEventWasCaptured = false;

                    process.Exited += (sender, args) => { exitedEventWasCaptured = true; };

                    // process.Start();

                    process.WaitForExit();

                    exitedEventWasCaptured.Should().BeTrue();
                }
            }
Ejemplo n.º 22
0
            public void Process_Raises_OutputDataReceived_Event()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log         = new FakeLog();
                var runner      = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                    .WithArguments(args => args.Append("--out OutputLine1"))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .SetRedirectStandardOutput(true);

                string outputDataReceived = null;

                using (var process = runner.Start(_appExe, settings))
                {
                    process.OutputDataReceived +=
                        (sender, args) => { outputDataReceived = args.Output; };

                    process.WaitForExit();

                    outputDataReceived.Should().Be("OutputLine1");
                }
            }
Ejemplo n.º 23
0
        public void Process_Should_Use_Provided_EnvironmentVariables()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                    .WithArguments(args => args.Append("--environmentVariables EnvVar1 EnvVar2"))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .WithEnvironmentVariable("EnvVar1", "Value1")
                    .WithEnvironmentVariable("EnvVar2", "Value2")
                    .SetRedirectStandardOutput(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.WaitForExit();
                var output = process.GetStandardOutput().ToArray();

                output.Should().BeEquivalentTo("EnvVar1: 'Value1'", "EnvVar2: 'Value2'");
            }
        }
            public void Should_Return_Settings_With_Correct_Timeout(int value, int expected)
            {
                var settings = new AdvProcessSettings().SetTimeout(value);

                settings.Timeout.Should().Be(expected);
            }
Ejemplo n.º 25
0
        public void Process_WillNotMissOutputViaEvents()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                    .WithArguments(args => args.Append("--out line1 line2 --echoArgs --delay 100"))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .SetRedirectStandardOutput(true);

            var outputDataReceived = new List<string>();

            using (var process = runner.Start(_appExe, settings))
            {
                process.OutputDataReceived +=
                    (sender, args) => { outputDataReceived.Add(args.Output); };

                process.WaitForExit();

                outputDataReceived.Should()
                    .BeEquivalentTo("Args received: --out line1 line2 --echoArgs --delay 100",
                        "line1", "line2");
            }
        }
Ejemplo n.º 26
0
        public void Dispose_Does_Not_Kill_Underlying_Process_If_Still_Running()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .WithArguments(args => args.Append("--sleep 5000"));

            int processId;
            using (var process = runner.Start(_appExe, settings))
            {
                processId = process.ProcessId;
                process.HasExited.Should().BeFalse();
            }

            using (var p2 = System.Diagnostics.Process.GetProcessById(processId))
            {
                p2.HasExited.Should().BeFalse();
                p2.Kill();
            }
        }
            public void Should_Return_Settings_With_Correct_StandardError(bool value, bool expected)
            {
                var settings = new AdvProcessSettings().SetRedirectStandardError(value);

                settings.RedirectStandardError.Should().Be(expected);
            }
            public void Should_Return_Settings_With_Correct_Arguments(string value, string expected)
            {
                var settings = new AdvProcessSettings().WithArguments(args => { args.Append(value); });

                settings.Arguments.Render().Should().Be(expected);
            }
            public void Should_Return_Settings_With_Correct_StandardError(bool value, bool expected)
            {
                var settings = new AdvProcessSettings().SetRedirectStandardError(value);

                settings.RedirectStandardError.Should().Be(expected);
            }
Ejemplo n.º 30
0
                public void Should_Return_Process_Created_By_Runner(ICakeContext context,
                                                                    FilePath filePath, AdvProcessSettings settings, IAdvProcessRunner runner,
                                                                    IAdvProcess expectedResult)
                {
                    runner.Start(filePath, settings).Returns(expectedResult);

                    Func <IAdvProcess> sut =
                        () => context.StartAdvProcess(filePath, settings, runner);

                    var result = sut();

                    result.Should().BeSameAs(expectedResult);
                }
Ejemplo n.º 31
0
        public void Enumerating_GetStandardError_WillThrowWhenUsingOutputEvents()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                    //.WithArguments(args => args.Append("--out line1 line2 --echoArgs --delay 100"))
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .SetRedirectStandardError(true);

            using (var process = runner.Start(_appExe, settings))
            {
                process.ErrorDataReceived +=
                    (sender, args) => { };

                process.WaitForExit();

                process.Invoking(p => p.GetStandardError().ToArray())
                    .ShouldThrow<InvalidOperationException>();
            }
        }
Ejemplo n.º 32
0
            public void Process_Should_Capture_Exited_Event_Added_Before_Start()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log = new FakeLog();
                var runner = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                        .WithArguments(args => args.Append("--exitCode 5"))
                        .UseWorkingDirectory(Environment.CurrentDirectory);

                using (var process = runner.Start(_appExe, settings))
                {
                    var exitedEventWasCaptured = false;

                    process.Exited += (sender, args) => { exitedEventWasCaptured = true; };

                    // process.Start();

                    process.WaitForExit();

                    exitedEventWasCaptured.Should().BeTrue();
                }
            }
Ejemplo n.º 33
0
            public void Process_Raises_Exited_Event_With_ExitCode()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log = new FakeLog();
                var runner = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings().WithArguments(args => args.Append("--exitcode 3"))
                        .UseWorkingDirectory(Environment.CurrentDirectory);

                var exitCodeUponExit = 0;

                using (var process = runner.Start(_appExe, settings))
                {
                    process.Exited += (sender, args) =>
                    {
                        exitCodeUponExit = args.ExitCode;
                    };

                    process.WaitForExit();

                    exitCodeUponExit.Should().Be(3);
                }
            }
Ejemplo n.º 34
0
            public void Process_With_Output_Not_Redirected_Will_Throw()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log = new FakeLog();
                var runner = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                        .WithArguments(args => args.Append("--out OutputLine1"))
                        .UseWorkingDirectory(Environment.CurrentDirectory)
                        .SetRedirectStandardOutput(false);

                using (var process = runner.Start(_appExe, settings))
                {
                    process.Invoking(sut => sut.OutputDataReceived += (sender, args) => { })
                        .ShouldThrow<InvalidOperationException>();
                }
            }
Ejemplo n.º 35
0
            public void Process_Raises_OutputDataReceived_Event()
            {
                var environment = FakeEnvironment.CreateWindowsEnvironment();
                var log = new FakeLog();
                var runner = new AdvProcessRunner(environment, log);

                var settings =
                    new AdvProcessSettings()
                        .WithArguments(args => args.Append("--out OutputLine1"))
                        .UseWorkingDirectory(Environment.CurrentDirectory)
                        .SetRedirectStandardOutput(true);

                string outputDataReceived = null;

                using (var process = runner.Start(_appExe, settings))
                {
                    process.OutputDataReceived +=
                        (sender, args) => { outputDataReceived = args.Output; };

                    process.WaitForExit();

                    outputDataReceived.Should().Be("OutputLine1");
                }
            }
Ejemplo n.º 36
0
        public void Process_Can_Be_Killed()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .WithArguments(args => args.Append("--sleep 5000"));

            using (var process = runner.Start(_appExe, settings))
            {
                process.Kill();

                process.HasExited.Should().BeTrue();
            }
        }
 public void EnvironmentVariable_Key_Should_Not_Be_Null()
 {
     var sut = new AdvProcessSettings();
     sut.Invoking(_ => _.WithEnvironmentVariable(null, "Value1"))
         .ShouldThrow<ArgumentNullException>();
 }
            public void EnvironmentVariables_Should_Be_Empty_By_Default()
            {
                var settings = new AdvProcessSettings();

                settings.EnvironmentVariables.Should().NotBeNull().And.BeEmpty();
            }
 public void EnvironmentVariables_Should_Be_Empty_By_Default()
 {
     var settings = new AdvProcessSettings();
     settings.EnvironmentVariables.Should().NotBeNull().And.BeEmpty();
 }
            public void Should_Return_Settings_With_Correct_Arguments(string value, string expected)
            {
                var settings = new AdvProcessSettings().WithArguments(args => { args.Append(value); });

                settings.Arguments.Render().Should().Be(expected);
            }
            public void Should_Return_Settings_With_Correct_Directory(string value, string expected)
            {
                var settings = new AdvProcessSettings().UseWorkingDirectory(value);

                settings.WorkingDirectory.FullPath.Should().Be(expected);
            }
            public void Should_Return_Settings_With_Correct_Directory(string value, string expected)
            {
                var settings = new AdvProcessSettings().UseWorkingDirectory(value);

                settings.WorkingDirectory.FullPath.Should().Be(expected);
            }
            public void Should_Return_Settings_With_Correct_Timeout(int value, int expected)
            {
                var settings = new AdvProcessSettings().SetTimeout(value);

                settings.Timeout.Should().Be(expected);
            }
Ejemplo n.º 44
0
        /// <summary>
        ///     Runs the IIS Express process
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public virtual IAdvProcess StartServer(TSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            var arguments = BuildArguments(settings);

            if (settings.TraceLevel != TraceLevel.None)
            {
                arguments.Append("/trace:" + settings.TraceLevel.ToString().ToLowerInvariant());
            }

            if (!settings.EnableSystemTray)
            {
                arguments.Append("/systray:false");
            }

            var processSettings = new AdvProcessSettings
            {
                Arguments = arguments,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };

            var process = StartProcess(settings, arguments, null, processSettings);


            process.ErrorDataReceived += ((sender, args) =>
            {
                var errorMessage =
                    string.Format("IIS Express returned the following error message: '{0}'",
                                  args.Output);
                throw new CakeException(errorMessage);
            });

            if (settings.WaitForStartup > 0)
            {
                // this supports a timeout on waiting for startup
                var stopwatch       = Stopwatch.StartNew();
                var serverIsStarted = false;

                process.OutputDataReceived += ((sender, args) =>
                {
                    if (!serverIsStarted &&
                        "IIS Express is running.".Equals(args.Output,
                                                         StringComparison.InvariantCultureIgnoreCase))
                    {
                        stopwatch.Stop();
                        serverIsStarted = true;
                    }
                });

                Log.Verbose("Waiting for IIS Express to start (timeout: {0}ms)",
                            settings.WaitForStartup);
                do
                {
                    if (stopwatch.ElapsedMilliseconds > settings.WaitForStartup)
                    {
                        throw new CakeException(string.Format(CultureInfo.CurrentCulture,
                                                              "Timed out while waiting for IIS Express to start. (timeout: {0}ms)",
                                                              settings.WaitForStartup));
                    }

                    Thread.Sleep(10);
                } while (!serverIsStarted);

                Log.Information("IIS Express is running -- it took ~{0}ms to start.", stopwatch.ElapsedMilliseconds);
            }

            return(process);
        }
            public void EnvironmentVariable_Set_Multiple_Times_Should_Use_The_Last_One()
            {
                var settings =
                    new AdvProcessSettings().WithEnvironmentVariable("Key1", "Value1")
                        .WithEnvironmentVariable("Key1", "Value1-A");

                settings.EnvironmentVariables["Key1"].Should().Be("Value1-A");
            }
Ejemplo n.º 46
0
        public void Kill_Process_Returns_Minus1_ExitCode()
        {
            var environment = FakeEnvironment.CreateWindowsEnvironment();
            var log = new FakeLog();
            var runner = new AdvProcessRunner(environment, log);

            var settings =
                new AdvProcessSettings()
                    .UseWorkingDirectory(Environment.CurrentDirectory)
                    .WithArguments(args => args.Append("--sleep 5000 --exitcode 3"));

            using (var process = runner.Start(_appExe, settings))
            {
                process.Kill();
                process.GetExitCode().Should().Be(-1);
            }
        }