public void SinglePSObjectOutput() { // Arrange var scriptContent = new StringBuilder(); scriptContent.AppendLine("$psObject = New-Object PSObject"); scriptContent.AppendLine("$psObject | Add-Member -MemberType NoteProperty -Name 'Foo' -Value 'TestFoo'"); scriptContent.AppendLine("$psObject | Add-Member -MemberType NoteProperty -Name 'Bar' -Value 'TestBar'"); scriptContent.AppendLine("$psObject"); // Act IScriptExecutionResult result = null; var task = _scriptExecutionEngine.ExecuteScriptAsync(scriptContent.ToString(), OutputObjectsFormat.Json). ContinueWith((executionResult) => { result = executionResult.Result; }); task.Wait(); // Assert Assert.IsNotNull(result); Assert.AreEqual(ScriptState.Success, result.State); Assert.IsNotEmpty(result.OutputObjectCollection.SerializedObjects); Assert.AreEqual(1, result.OutputObjectCollection.SerializedObjects.Length); var jsonObject = result.OutputObjectCollection.SerializedObjects[0]; Assert.IsTrue(jsonObject.Contains(@"""TypeName"": ""System.Management.Automation.PSCustomObject"",")); Assert.IsTrue(jsonObject.Contains(@"""Interfaces"": null,")); Assert.IsTrue(jsonObject.Contains(@"""Foo"": ""TestFoo""")); Assert.IsTrue(jsonObject.Contains(@"""Bar"": ""TestBar""")); }
public void SingleCmdletCall() { // Arrange var scriptContent = "Get-ChildItem"; // Act IScriptExecutionResult result = null; var task = _scriptExecutionEngine.ExecuteScriptAsync(scriptContent). ContinueWith((executionResult) => { result = executionResult.Result; }); task.Wait(); // Assert Assert.IsNotNull(result); Assert.AreEqual(ScriptState.Success, result.State); Assert.IsNotEmpty(result.OutputObjectCollection.FormattedTextPresentation); Assert.NotNull(result.StarTime); Assert.NotNull(result.EndTime); }