public void Should_Start_Local_File() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath("../../Scripts/Test.ps1"), new PowershellSettings()); Assert.True((results != null) && (results.Count > 0), "Check Rights"); }
public void Start_File_With_Dot_Sourcing() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath("Scripts/Test.ps1"), new PowershellSettings().WithDotSourcing()); Assert.True((results != null) && (results.Count >= 1), "Check Rights"); }
public void Start_Service_Script() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Get-Service", new PowershellSettings()); Assert.True((results != null) && (results.Count > 0), "Check Rights"); }
public void Start_File_With_HashTableParameters() { var dict = new Dictionary <string, string> { { "A", "1" }, { "B", "2 " }, { "C", "3" } }; Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath("Scripts/HashTableTest.ps1"), new PowershellSettings() .WithArguments(args => args.AppendHashTable("AHashTable", dict)) .BypassExecutionPolicy()); Assert.True((results != null) && (results.Count == dict.Count + 1)); #if NET5_0 || NETCOREAPP3_1 Assert.Equal(string.Empty, results[0].BaseObject.ToString()); #else Assert.Equal("0", results[0].BaseObject.ToString()); #endif foreach (var item in dict.ToArray()) { Assert.True(results.FirstOrDefault(r => r.BaseObject.ToString().Equals(($"{item.Key} = {item.Value}"))) != null); } }
public void Exception_Script_Should_Throw_Exception() { var runner = CakeHelper.CreatePowershellRunner(); Assert.Throws <AggregateException>(() => runner.Start(new FilePath("Scripts/ErrorScript.ps1"), new PowershellSettings())); }
public void Start_Write_Script() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Write-Host", new PowershellSettings().WithArguments(args => args.Append("Testing..."))); Assert.True((DebugLog.Lines != null) && (DebugLog.Lines.Contains("Testing...")), "Output not written to the powershell host"); }
public void Start_File_With_Parameters() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath("Scripts/Test.ps1"), new PowershellSettings().WithArguments(args => args.Append("Service", "eventlog"))); Assert.True((results != null) && (results.Count >= 1), "Check Rights"); }
public void Escapes_Curley_Brackets() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Write-Host '{ blah }'", new PowershellSettings()); Assert.True((DebugLog.Lines != null) && (DebugLog.Lines.Contains("{ blah }")), "Output not written to the powershell host"); }
public void Working_Directory_With_Spaces_Should_Properly_Execute() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Write-Host", new PowershellSettings().WithArguments(args => args.Append("Testing...")) .UseWorkingDirectory(@"C:\Path With Spaces\")); Assert.True((DebugLog.Lines != null) && (DebugLog.Lines.Contains("Testing...")), "Output not written to the powershell host"); }
public void Should_Return_Result_With_Error_Code() { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath("../../Scripts/FailingScript.ps1"), new PowershellSettings()); Assert.True(results != null && results.Count >= 1, "Check Rights"); Assert.True(results.FirstOrDefault(r => r.BaseObject.ToString().Contains("Cannot find path")) != null); Assert.Equal("1", results[0].BaseObject.ToString()); }
public void Returned_Error_Code_Should_Throw_Exception() { var results = CakeHelper.CreatePowershellRunner() .Start(new FilePath("Scripts/FailingScript.ps1"), new PowershellSettings()); Assert.True(results != null && results.Count >= 1, "Check Rights"); Assert.True(results.FirstOrDefault(r => r.BaseObject.ToString().Contains("Cannot find path")) != null); Assert.Equal("1", results[0].BaseObject.ToString()); }
public void Returned_Error_Code_Should_Throw_Exception() { var runner = CakeHelper.CreatePowershellRunner(); Assert.Throws <AggregateException>(() => runner.Start(new FilePath("Scripts/FailingScript.ps1"), new PowershellSettings() { ExceptionOnScriptError = true })); }
public void Working_Directory_With_Spaces_Should_Properly_Execute() { var path = System.IO.Path.Combine(Environment.CurrentDirectory, "test dir"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Write-Host", new PowershellSettings().WithArguments(args => args.Append("Testing...")) .UseWorkingDirectory(path)); Assert.True((DebugLog.Lines != null) && (DebugLog.Lines.Contains("Testing...")), "Output not written to the powershell host"); }
public void Start_File_With_ArrayParameters() { var array = new string[] { "A", "B", "C" }; Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath("Scripts/ArrayTest.ps1"), new PowershellSettings().WithArguments(args => args.AppendArray("AnArray", array))); Assert.True((results != null) && (results.Count == array.Length + 1)); Assert.Equal("0", results[0].BaseObject.ToString()); foreach (var item in array) { Assert.True(results.FirstOrDefault(r => r.BaseObject.ToString().Equals((item))) != null); } }
public void Start_Local_File() { var testPath = "Scripts/TestNonWin.ps1"; #if NET5_0 if (OperatingSystem.IsWindows()) { testPath = "Scripts/Test.ps1"; } #else if (Environment.OSVersion.Platform == PlatformID.Win32NT) { testPath = "Scripts/Test.ps1"; } #endif Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath(testPath), new PowershellSettings().BypassExecutionPolicy()); Assert.True((results != null) && (results.Count > 0), "Check Rights"); }
public void Start_Service_Script() { #if NET5_0 if (OperatingSystem.IsWindows()) { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Get-Service", new PowershellSettings()); Assert.True((results != null) && (results.Count > 0), "Check Rights"); } #else if (Environment.OSVersion.Platform == PlatformID.Win32NT) { Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start("Get-Service", new PowershellSettings()); Assert.True((results != null) && (results.Count > 0), "Check Rights"); } #endif Assert.True(true); }
public void Start_File_With_Parameters() { var testPath = "Scripts/TestNonWin.ps1"; #if NET5_0 if (OperatingSystem.IsWindows()) { testPath = "Scripts/Test.ps1"; } #else if (Environment.OSVersion.Platform == PlatformID.Win32NT) { testPath = "Scripts/Test.ps1"; } #endif Collection <PSObject> results = CakeHelper.CreatePowershellRunner().Start(new FilePath(testPath), new PowershellSettings() .WithArguments(args => args.Append("Service", "eventlog")) .BypassExecutionPolicy()); Assert.True((results != null) && (results.Count >= 1), "Check Rights"); }