internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, AdvProcessSettings settings, IAdvProcessRunner processRunner) { if (context == null) { throw new ArgumentNullException("context"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (processRunner == null) { throw new ArgumentNullException("processRunner"); } // Get the working directory. var workingDirectory = settings.WorkingDirectory ?? context.Environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(context.Environment); // Start the process. var process = processRunner.Start(fileName, settings); if (process == null) { throw new CakeException("Could not start process."); } return(process); }
public void ShouldTimeoutWhenIISExpressTakesLongerThanSpecifiedWaitTimeToStart( [Frozen] ICakeLog log, [Frozen] IAdvProcess process, [Frozen] IAdvProcessRunner processRunner, [Frozen] IRegistry registry, ConfigBasedIISExpressRunner sut) { var simulatedStandardOutput = new[] { "1", "2", "3", "4", "IIS Express is running.", "5" }; // hooking into the logging call that occurs previous to waiting is the only place I could // think of to send in simulated output to signal IIS Express has started. log.When( l => l.Write(Arg.Any <Verbosity>(), Arg.Any <LogLevel>(), "Waiting for IIS Express to start (timeout: {0}ms)", Arg.Any <object[]>())) .Do(ci => { Thread.Sleep(100); foreach (var s in simulatedStandardOutput) { process.OutputDataReceived += Raise.EventWith(process, new ProcessOutputReceivedEventArgs(s)); } }); processRunner.Start(Arg.Any <FilePath>(), Arg.Any <AdvProcessSettings>()) .Returns(ci => process); var settings = new ConfigBasedIISExpressSettings { WaitForStartup = 50 }; sut.Invoking(s => s.StartServer(settings)) .ShouldThrow <CakeException>() .WithMessage("Timed out while waiting for IIS Express to start. (timeout: 50ms)"); }
internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, AdvProcessSettings settings, IAdvProcessRunner processRunner ) { if (context == null) { throw new ArgumentNullException("context"); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (processRunner == null) { throw new ArgumentNullException("processRunner"); } // Get the working directory. var workingDirectory = settings.WorkingDirectory ?? context.Environment.WorkingDirectory; settings.WorkingDirectory = workingDirectory.MakeAbsolute(context.Environment); // Start the process. var process = processRunner.Start(fileName, settings); if (process == null) { throw new CakeException("Could not start process."); } return process; }
public void Should_Throw_If_No_Process_Was_Returned_From_Process_Runner( ICakeContext context, IAdvProcessRunner runner) { // Arrange runner.Start(Arg.Any <FilePath>(), Arg.Any <AdvProcessSettings>()) .Returns((IAdvProcess)null); Action sut = () => context.StartAdvProcess("hello.exe", runner); // Act / Assert sut.ShouldThrow <CakeException>().WithMessage("Could not start process."); }
public void Should_Throw_If_No_Process_Was_Returned_From_Process_Runner( ICakeContext context, IAdvProcessRunner runner) { // Arrange runner.Start(Arg.Any<FilePath>(), Arg.Any<AdvProcessSettings>()) .Returns((IAdvProcess) null); Action sut = () => context.StartAdvProcess("hello.exe", runner); // Act / Assert sut.ShouldThrow<CakeException>().WithMessage("Could not start process."); }
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); }
public void Should_Return_Process_Created_By_Runner(ICakeContext context, FilePath filePath, IAdvProcessRunner runner, IAdvProcess expectedResult) { runner.Start(filePath, Arg.Any<AdvProcessSettings>()).Returns(expectedResult); Func<IAdvProcess> sut = () => context.StartAdvProcess(filePath, runner); var result = sut(); result.Should().BeSameAs(expectedResult); }
/// <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); }
public void ShouldThrowWhenIISExpressProcessWritesToErrorStream( [Frozen] IAdvProcess process, [Frozen] IAdvProcessRunner processRunner, [Frozen] IRegistry registry, ConfigBasedIISExpressRunner sut) { processRunner.Start(Arg.Any <FilePath>(), Arg.Any <AdvProcessSettings>()).Returns(process); var settings = new ConfigBasedIISExpressSettings(); sut.StartServer(settings); process.Invoking( p => p.ErrorDataReceived += Raise.EventWith( new ProcessOutputReceivedEventArgs("some dummy error data received"))) .ShouldThrow <CakeException>() .WithMessage( "IIS Express returned the following error message: 'some dummy error data received'"); }
public void ShouldWaitUntilIISExpressServerIsStarted([Frozen] ICakeLog log, [Frozen] IAdvProcess process, IFileSystem fileSystem, [Frozen] IAdvProcessRunner processRunner, [Frozen] IRegistry registry, AppPathBasedIISExpressRunner sut) { var simulatedStandardOutput = new[] { "1", "2", "3", "4", "IIS Express is running.", "5" }; // hooking into the logging call that occurs previous to waiting is the only place I could // think of to send in simulated output to signal IIS Express has started. log.When( l => l.Write(Arg.Any <Verbosity>(), Arg.Any <LogLevel>(), "Waiting for IIS Express to start (timeout: {0}ms)", Arg.Any <object[]>())) .Do(ci => { foreach (var s in simulatedStandardOutput) { process.OutputDataReceived += Raise.EventWith(process, new ProcessOutputReceivedEventArgs(s)); } }); processRunner.Start(Arg.Any <FilePath>(), Arg.Any <AdvProcessSettings>()) .Returns(ci => process); var settings = new AppPathBasedIISExpressSettings(@"c:\MyApp") { WaitForStartup = 1000 }; fileSystem.Exist(settings.AppPath).Returns(true); sut.StartServer(settings); log.Received() .Write(Verbosity.Normal, LogLevel.Information, Arg.Is <string>(s => s.StartsWith("IIS Express is running")), Arg.Any <object[]>()); }