Esempio n. 1
0
        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:\Program Files\"));

            Assert.True((DebugLog.Lines != null) && (DebugLog.Lines.Contains("Testing...")), "Output not written to the powershell host");
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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_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)));

            Assert.True((results != null) && (results.Count == dict.Count + 1));
            Assert.Equal("0", results[0].BaseObject.ToString());

            foreach (var item in dict.ToArray())
            {
                Assert.True(results.FirstOrDefault(r => r.BaseObject.ToString().Equals(($"{item.Key} = {item.Value}"))) != 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);
        }
Esempio n. 10
0
        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");
        }
Esempio n. 11
0
 public static IPowershellRunner CreatePowershellRunner()
 {
     return(new PowershellRunner(CakeHelper.CreateEnvironment(), new DebugLog()));
 }