コード例 #1
0
        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;
        }
コード例 #2
0
        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)");
        }
コード例 #3
0
        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\""));
        }
コード例 #4
0
 public IISExpressRunnerTestImpl(IFileSystem fileSystem, ICakeEnvironment environment,
                                 IProcessRunner processRunner, IGlobber globber, IRegistry registry, ICakeLog log,
                                 IAdvProcessRunner advProcessRunner)
     : base(
         fileSystem, environment, processRunner, globber, registry, log, advProcessRunner
         )
 {
 }
コード例 #5
0
        public void ShouldThrowWhenBothSiteIdAndSiteNameAreSet([Frozen] IAdvProcessRunner runner,
                                                               ConfigBasedIISExpressRunner sut)
        {
            var settings = new ConfigBasedIISExpressSettings
            {
                SiteIdToLaunch   = 53,
                SiteNameToLaunch = "MySite"
            };

            sut.Invoking(s => s.StartServer(settings)).ShouldThrow <InvalidOperationException>();
        }
コード例 #6
0
 /// <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;
 }
コード例 #7
0
        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() == ""));
        }
コード例 #8
0
                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.");
                }
コード例 #9
0
                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.");
                }
コード例 #10
0
        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"));
        }
コード例 #11
0
        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"));
        }
コード例 #12
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);
                }
コード例 #13
0
        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);
        }
コード例 #14
0
        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"));
        }
コード例 #15
0
        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"));
        }
コード例 #16
0
        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"));
        }
コード例 #17
0
                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"));
                }
コード例 #18
0
                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"));
                }
コード例 #19
0
        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"));
        }
コード例 #20
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\""));
        }
コード例 #21
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"));
                }
コード例 #22
0
        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\""));
        }
コード例 #23
0
        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'");
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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[]>());
        }
コード例 #26
0
        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);
        }
コード例 #27
0
 internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName,
                                             IAdvProcessRunner processRunner)
 {
     return(StartAdvProcess(context, fileName, new AdvProcessSettings(),
                            processRunner));
 }
コード例 #28
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);
                }
コード例 #29
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"));
                }
コード例 #30
0
 internal static IAdvProcess StartAdvProcess(this ICakeContext context, FilePath fileName,
     IAdvProcessRunner processRunner)
 {
     return StartAdvProcess(context, fileName, new AdvProcessSettings(),
         processRunner);
 }
コード例 #31
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"));
                }
コード例 #32
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"));
                }