public virtual Collection <PSObject> RunPowerShellTest(params string[] scripts) { Collection <PSObject> output = null; for (int i = 0; i < scripts.Length; ++i) { Console.WriteLine(scripts[i]); powershell.AddScript(scripts[i]); } try { output = powershell.Invoke(); if (powershell.Streams.Error.Count > 0) { throw new RuntimeException(ErrorIsNotEmptyException); } return(output); } catch (Exception psException) { powershell.LogPowerShellException(psException, this.TestContext); throw; } finally { powershell.LogPowerShellResults(output, this.TestContext); powershell.Streams.Error.Clear(); } }
private Collection <PSObject> ExecuteShellTest( System.Management.Automation.PowerShell powershell, IEnumerable <string> setupScripts, IEnumerable <string> scripts) { SetupPowerShellModules(powershell, setupScripts); Collection <PSObject> output = null; foreach (var script in scripts) { if (TracingInterceptor != null) { TracingInterceptor.Information(script); } powershell.AddScript(script); } try { powershell.Runspace.Events.Subscribers.Clear(); powershell.Streams.Error.Clear(); output = powershell.Invoke(); if (powershell.Streams.Error.Count > 0) { var sb = new StringBuilder(); sb.AppendLine("Test failed due to a non-empty error stream, check the error stream in the test log for more details."); sb.AppendLine(string.Format("{0} total Errors", powershell.Streams.Error.Count)); foreach (var error in powershell.Streams.Error) { sb.AppendLine(error.Exception.ToString()); } throw new RuntimeException(sb.ToString()); } return(output); } catch (Exception psException) { powershell.LogPowerShellException(psException, TracingInterceptor); throw; } finally { powershell.LogPowerShellResults(output, TracingInterceptor); powershell.Streams.Error.Clear(); } }
/// <summary> /// Log the PowerShell Streams from a PowerShell invocation /// </summary> /// <param name="powershell">The PowerShell instance to log</param> public static void LogPowerShellResults(this System.Management.Automation.PowerShell powershell, TestContext context) { powershell.LogPowerShellResults(null, context); }
/// <summary> /// Log the PowerShell Streams from a PowerShell invocation /// </summary> /// <param name="powershell">The PowerShell instance to log</param> public static void LogPowerShellResults(this System.Management.Automation.PowerShell powershell) { powershell.LogPowerShellResults(null); }
/// <summary> /// Log the PowerShell Streams from a PowerShell invocation /// </summary> /// <param name="powershell">The PowerShell instance to log</param> public static void LogPowerShellResults( this System.Management.Automation.PowerShell powershell, XunitTracingInterceptor xunitLogger) { powershell.LogPowerShellResults(null, xunitLogger); }