コード例 #1
0
        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"));
        }
コード例 #2
0
ファイル: TestBuildRunner.cs プロジェクト: SaberZA/Prismatic
        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, ""));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: ExecuteTests.cs プロジェクト: LachlanS/tfsdeployer
        public void ShouldReturnValueOfEnvironmentVariable()
        {
            var pr = new PowerShellRunner();

            pr.ExecuteCommand("$Env:TEMP", null);

            Assert.IsFalse(pr.ErrorOccurred, "ErrorOccurred");
            StringAssert.Contains(pr.Output, Environment.GetEnvironmentVariable("TEMP"));
        }
コード例 #5
0
 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();
 }
コード例 #6
0
ファイル: ExecuteTests.cs プロジェクト: LachlanS/tfsdeployer
        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"));
        }
コード例 #7
0
 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;
 }
コード例 #8
0
ファイル: TestBuildRunner.cs プロジェクト: SaberZA/Prismatic
        public void Construct_PowerShellRunner()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var powerShellRunner = new PowerShellRunner();

            //---------------Test Result -----------------------
            Assert.IsNotNull(powerShellRunner);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 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);
     }
 }
コード例 #12
0
ファイル: TestBuildRunner.cs プロジェクト: SaberZA/Prismatic
        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);
        }
コード例 #13
0
ファイル: ExecuteTests.cs プロジェクト: LachlanS/tfsdeployer
        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
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        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));
        }
コード例 #16
0
 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;
 }
コード例 #17
0
 public ChocolateyInstaller(ProcessRunner processRunner, PowerShellRunner powerShellRunner)
 {
     this.processRunner    = processRunner;
     this.powerShellRunner = powerShellRunner;
 }
コード例 #18
0
 public PSHostUserInterface(PowerShellRunner powerShellRunner)
 {
     this.powerShellRunner = powerShellRunner;
 }
コード例 #19
0
 public PSHostUserInterface(PowerShellRunner powerShellRunner)
 {
     this.powerShellRunner = powerShellRunner;
 }
コード例 #20
0
 public GroupPollicyErrorViewModel(IEventAggregator eventAggregator, PowerShellRunner powerShellRunner)
 {
     this.eventAggregator  = eventAggregator;
     this.powerShellRunner = powerShellRunner;
 }
コード例 #21
0
 public ChocolateyInstaller(ProcessRunner processRunner, PowerShellRunner powerShellRunner)
 {
     this.processRunner = processRunner;
     this.powerShellRunner = powerShellRunner;
 }
コード例 #22
0
 public PackageManager(PowerShellRunner powerShellRunner, ChocolateyInstaller chocolateyInstaller)
 {
     this.powerShellRunner = powerShellRunner;
     this.chocolateyInstaller = chocolateyInstaller;
 }
コード例 #23
0
 public PackageManager(PowerShellRunner powerShellRunner, ChocolateyInstaller chocolateyInstaller)
 {
     this.powerShellRunner    = powerShellRunner;
     this.chocolateyInstaller = chocolateyInstaller;
 }
コード例 #24
0
 public GroupPollicyErrorViewModel(IEventAggregator eventAggregator, PowerShellRunner powerShellRunner)
 {
     this.eventAggregator = eventAggregator;
     this.powerShellRunner = powerShellRunner;
 }