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)"); }
public void ShouldSetConfigFileSwitchFromRelativeFilePath( [Frozen] ICakeEnvironment environment, IFileSystem fileSystem, [Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { environment.WorkingDirectory.Returns("c:/MyWorkingDirectory"); var settings = new ConfigBasedIISExpressSettings { ConfigFilePath = FilePath.FromString("applicationhost.config") }; fileSystem.Exist( Arg.Is <FilePath>( f => f.FullPath.Equals("c:/MyWorkingDirectory/applicationhost.config", StringComparison.OrdinalIgnoreCase))).Returns(true); sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>( p => p.Arguments.Render() == "/config:\"c:/MyWorkingDirectory/applicationhost.config\"")); }
public IISExpressRunnerTestImpl(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IGlobber globber, IRegistry registry, ICakeLog log, IAdvProcessRunner advProcessRunner) : base( fileSystem, environment, processRunner, globber, registry, log, advProcessRunner ) { }
public void ShouldThrowWhenBothSiteIdAndSiteNameAreSet([Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { var settings = new ConfigBasedIISExpressSettings { SiteIdToLaunch = 53, SiteNameToLaunch = "MySite" }; sut.Invoking(s => s.StartServer(settings)).ShouldThrow <InvalidOperationException>(); }
/// <summary> /// Initializes a new instance of the <see cref="IISExpressRunner{TSettings}" /> class. /// </summary> /// <param name="fileSystem">The file system.</param> /// <param name="environment">The environment.</param> /// <param name="processRunner">The process runner.</param> /// <param name="globber">The globber.</param> /// <param name="registry">The registry.</param> /// <param name="log">The log.</param> /// <param name="advProcessRunner">The adv process runner.</param> protected IISExpressRunner(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IGlobber globber, IRegistry registry, ICakeLog log, IAdvProcessRunner advProcessRunner) : base(fileSystem, environment, processRunner, globber) { _registry = registry; _log = log; _advProcessRunner = advProcessRunner; _cakeEnvironment = environment; _fileSystem = fileSystem; }
public void ShouldNotSetAnySwitchesByDefault([Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { var settings = new ConfigBasedIISExpressSettings(); sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(p => p.Arguments.Render() == "")); }
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 ShouldSetTraceSwitch([Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { var settings = new ConfigBasedIISExpressSettings { TraceLevel = TraceLevel.Warning }; sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(p => p.Arguments.Render() == "/trace:warning")); }
public void ShouldSetSystraySwitch([Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { var settings = new ConfigBasedIISExpressSettings { EnableSystemTray = false }; sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(p => p.Arguments.Render() == "/systray:false")); }
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 ShouldThrowIfAppPathDoesNotExist([Frozen] IAdvProcessRunner runner, IFileSystem fileSystem, AppPathBasedIISExpressRunner sut) { var settings = new AppPathBasedIISExpressSettings(@"c:\MyApp"); fileSystem.Exist(settings.AppPath).Returns(false); sut.Invoking(s => s.StartServer(settings)).ShouldThrow <CakeException>(); runner.DidNotReceiveWithAnyArgs() .Start(null, null); }
public void ShouldSetSiteIdSwitch([Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { var settings = new ConfigBasedIISExpressSettings { SiteIdToLaunch = 53 }; sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(p => p.Arguments.Render() == "/siteid:53")); }
public void ShouldSetAppPoolSwitch([Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { var settings = new ConfigBasedIISExpressSettings { AppPoolToLaunch = "MyAppPool" }; sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(p => p.Arguments.Render() == "/apppool:MyAppPool")); }
public void ShouldSetSystraySwitch([Frozen] IAdvProcessRunner runner, IFileSystem fileSystem, AppPathBasedIISExpressRunner sut) { var settings = new AppPathBasedIISExpressSettings(@"c:\MyApp") { EnableSystemTray = false }; fileSystem.Exist(settings.AppPath).Returns(true); sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(p => p.Arguments.Render() == "/path:\"c:/MyApp\" /systray:false")); }
public void Should_Use_Environments_Working_Directory(ICakeContext context, IAdvProcessRunner runner) { // Arrange context.Environment.WorkingDirectory.Returns(new DirectoryPath("/Working")); Action sut = () => context.StartAdvProcess("hello.exe", runner); // Act sut(); // Assert runner.Received(1).Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>(info => info.WorkingDirectory.FullPath == "/Working")); }
public void Should_Use_Environments_Working_Directory(ICakeContext context, IAdvProcessRunner runner) { // Arrange context.Environment.WorkingDirectory.Returns(new DirectoryPath("/Working")); Action sut = () => context.StartAdvProcess("hello.exe", runner); // Act sut(); // Assert runner.Received(1).Start(Arg.Any<FilePath>(), Arg.Is<AdvProcessSettings>(info => info.WorkingDirectory.FullPath == "/Working")); }
public void ShouldSetClrVersionSwitch([Frozen] IAdvProcessRunner runner, IFileSystem fileSystem, AppPathBasedIISExpressRunner sut) { var settings = new AppPathBasedIISExpressSettings(@"c:\MyApp") { ClrVersion = ClrVersion.Version20 }; fileSystem.Exist(settings.AppPath).Returns(true); sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>( p => p.Arguments.Render() == "/path:\"c:/MyApp\" /clr:v2.0")); }
public void ShouldSetAppPathSwitchFromAbsolutePath( [Frozen] ICakeEnvironment environment, IFileSystem fileSystem, [Frozen] IAdvProcessRunner runner, AppPathBasedIISExpressRunner sut) { var settings = new AppPathBasedIISExpressSettings(@"c:\MyApp"); fileSystem.Exist(Arg.Is(settings.AppPath)).Returns(true); sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>( p => p.Arguments.Render() == "/path:\"c:/MyApp\"")); }
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")); }
public void ShouldSetAppPathSwitchFromRelativeFilePath( [Frozen] ICakeEnvironment environment, IFileSystem fileSystem, [Frozen] IAdvProcessRunner runner, AppPathBasedIISExpressRunner sut) { environment.WorkingDirectory.Returns("c:/build/MyWorkingDirectory"); var settings = new AppPathBasedIISExpressSettings(@"..\MyApp"); fileSystem.Exist(Arg.Is <DirectoryPath>(x => x.FullPath == "c:/build/MyApp")).Returns(true); sut.StartServer(settings); runner.Received() .Start(Arg.Any <FilePath>(), Arg.Is <AdvProcessSettings>( p => p.Arguments.Render() == "/path:\"c:/build/MyApp\"")); }
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 ShouldThrowWhenConfigFileDoesNotExist([Frozen] ICakeEnvironment environment, IFileSystem fileSystem, [Frozen] IAdvProcessRunner runner, ConfigBasedIISExpressRunner sut) { environment.WorkingDirectory.Returns("c:/MyWorkingDirectory"); var settings = new ConfigBasedIISExpressSettings { ConfigFilePath = FilePath.FromString(@"c:\someOtherDirectory\applicationhost.config") }; fileSystem.Exist( Arg.Is <FilePath>( f => f.FullPath.Equals(settings.ConfigFilePath.FullPath, StringComparison.OrdinalIgnoreCase))).Returns(false); sut.Invoking(s => s.StartServer(settings)).ShouldThrow <CakeException>(); runner.DidNotReceiveWithAnyArgs().Start(null, null); }
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[]>()); }
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); }
internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, IAdvProcessRunner processRunner) { return(StartAdvProcess(context, fileName, new AdvProcessSettings(), processRunner)); }
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_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")); }
internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName, IAdvProcessRunner processRunner) { return StartAdvProcess(context, fileName, new AdvProcessSettings(), processRunner); }
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")); }
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")); }