private DeployAgentResult DeployInternetZoneScript(PowerShellExecutionPolicyBehaviour executionPolicyBehaviour) { DeployAgentResult result; using (var scriptFile = new TemporaryFile(".ps1", PowerShellScripts.GetExecutionPolicyScript)) { ApplyInternetZoneIdentifier(scriptFile.FileInfo.FullName); var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.FullName, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), Tfs2008BuildDetail = new StubBuildDetail() }; var psAgent = new LocalPowerShellDeployAgent(); psAgent.ExecutionPolicyBehaviour = executionPolicyBehaviour; result = psAgent.Deploy(testDeployData); } return(result); }
public void LocalPowerShellDeployAgent_should_return_output_prior_to_a_script_error() { // Arrange var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>(); DeployAgentResult result; using (var scriptFile = new TemporaryFile(".ps1", "'Output this first'\nthrow 'fail'")) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), TfsBuildDetail = new BuildDetail() }; var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder); // Act result = agent.Deploy(testDeployData); } // Assert Assert.IsTrue(result.HasErrors, "HasErrors"); StringAssert.Contains(result.Output, "Output this first"); }
public void LocalPowerShellDeployAgent_should_finish_cleanly_when_scripts_leave_background_jobs_running() { // Arrange var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>(); DeployAgentResult result; using (var scriptFile = new TemporaryFile(".ps1", @"Start-Job { Get-Date; Start-Sleep -Seconds 1} ; 'ExpectedOutput'")) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), TfsBuildDetail = new BuildDetail() }; var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder); // Act result = agent.Deploy(testDeployData); } // Assert Assert.IsFalse(result.HasErrors, "HasErrors: {0}", result.Output); StringAssert.Contains(result.Output, "ExpectedOutput", "Output"); }
public void LocalPowerShellDeployAgent_should_marshal_build_detail_across_AppDomains() { // Arrange var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>(); DeployAgentResult result; using (var scriptFile = new TemporaryFile(".ps1", "$TfsDeployerBuildDetail | Format-List")) { var buildDetail = new BuildDetail(); var mapping = new Mapping { NewQuality = "Released", OriginalQuality = null, ScriptParameters = new ScriptParameter[0], Script = scriptFile.FileInfo.Name }; var buildStatusChangeEvent = new BuildStatusChangeEvent { StatusChange = new Change() }; var testDeployData = (new DeployAgentDataFactory()).Create(scriptFile.FileInfo.DirectoryName, mapping, buildDetail, buildStatusChangeEvent); var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder); // Act result = agent.Deploy(testDeployData); } // Assert Assert.IsFalse(result.HasErrors, "Test script failed."); }
public void LocalPowerShellDeployAgent_should_support_backticks_in_script_path() { // Arrange var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>(); DeployAgentResult result; const string subDirectory = "back`tick"; using (var scriptFile = new TemporaryFile(".ps1", @"'Script path is ' + $MyInvocation.MyCommand.Path", subDirectory)) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), TfsBuildDetail = new BuildDetail() }; var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder); // Act result = agent.Deploy(testDeployData); } // Assert Assert.IsFalse(result.HasErrors, "HasErrors: {0}", result.Output); StringAssert.Contains(result.Output, "Script path is", "Output prefix"); StringAssert.Contains(result.Output, subDirectory, "Output subdirectory"); }
public void LocalPowerShellDeployAgent_should_unload_assemblies_loaded_by_scripts() { // Arrange var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>(); DeployAgentResult result; using (var scriptFile = new TemporaryFile(".ps1", Resource.AsString("LoadSystemWebAssemblyScript.ps1"))) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), TfsBuildDetail = new BuildDetail() }; var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder); // Act result = agent.Deploy(testDeployData); } // Assert Assert.IsFalse(result.HasErrors, "Test script failed."); var systemWebAssembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "System.Web").SingleOrDefault(); Assert.IsNull(systemWebAssembly, "Assembly was not unloaded."); }
public void LocalPowerShellDeployAgent_should_expose_build_process_server_path_to_scripts() { // Arrange var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>(); DeployAgentResult result; using (var scriptFile = new TemporaryFile(".ps1", @"$TfsDeployerBuildDetail.BuildDefinition.Process.ServerPath")) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), TfsBuildDetail = new BuildDetail { BuildDefinition = { Process = { ServerPath = "$/foo.xaml" } } } }; var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder); // Act result = agent.Deploy(testDeployData); } // Assert Assert.IsFalse(result.HasErrors, "HasErrors"); StringAssert.Contains(result.Output, "$/foo.xaml"); }
public void ShouldReturnFormattedObjects() { var pr = new LocalPowerShellDeployAgent(); pr.ExecuteCommand("Get-ChildItem Env:", null); Assert.IsFalse(pr.ErrorOccurred, "ErrorOccurred"); StringAssert.Contains(pr.Output, Environment.GetEnvironmentVariable("TEMP")); }
public void ShouldReturnValueOfEnvironmentVariable() { var pr = new LocalPowerShellDeployAgent(); pr.ExecuteCommand("$Env:TEMP", null); Assert.IsFalse(pr.ErrorOccurred, "ErrorOccurred"); StringAssert.Contains(pr.Output, Environment.GetEnvironmentVariable("TEMP")); }
private static DeployAgentResult DeployFailingPowerShellScript() { using (var scriptFile = new TemporaryFile(".ps1", PowerShellScripts.FailingPowerShellScript)) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List <DeployScriptParameter>(), TfsBuildDetail = new BuildDetail() }; var psAgent = new LocalPowerShellDeployAgent(); return(psAgent.Deploy(testDeployData)); } }
public void Should_include_written_text_in_output() { using (var scriptFile = TemporaryFile.FromResource(".ps1", "Tests.TfsDeployer.PowerShellRunnerTests.WriteHostScript.ps1")) { var testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = scriptFile.FileInfo.Name, DeployScriptRoot = scriptFile.FileInfo.DirectoryName, DeployScriptParameters = new List<DeployScriptParameter>(), TfsBuildDetail = new BuildDetail() }; var psAgent = new LocalPowerShellDeployAgent(); var result = psAgent.Deploy(testDeployData); Assert.AreEqual("Hello world\n", result.Output); } }
private static DeployAgentResult DeployFailingPowerShellScript() { 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 testDeployData = new DeployAgentData { NewQuality = "Released", OriginalQuality = null, DeployScriptFile = testScriptFileName, DeployScriptRoot = testDirectory, DeployScriptParameters = new List <DeployScriptParameter>(), Tfs2008BuildDetail = new StubBuildDetail() }; var psAgent = new LocalPowerShellDeployAgent(); DeployAgentResult result; try { result = psAgent.Deploy(testDeployData); } finally { scriptFile.Delete(); } return(result); }