Write-Information accept objects from the pipeline (#2680)

* Write-Information accept objects from the pipeline

* Add test

* Fix test

Remove unneeded runspace.

* Clear streams before each test case

Streams of the PowerShell instance might have records from other test runs. Clear the streams before each test case.
This commit is contained in:
iSazonov
2016-11-15 22:41:34 -08:00
committed by Dongbo Wang
parent 80101176d1
commit 47be2c372a
2 changed files with 31 additions and 2 deletions
@@ -171,13 +171,13 @@ namespace Microsoft.PowerShell.Commands
/// This class implements Write-Information command
///
/// </summary>
[Cmdlet("Write", "Information", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=525909", RemotingCapability = RemotingCapability.None)]
[Cmdlet(VerbsCommunications.Write, "Information", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=525909", RemotingCapability = RemotingCapability.None)]
public sealed class WriteInformationCommand : PSCmdlet
{
/// <summary>
/// Object to be sent to the Information stream.
/// </summary>
[Parameter(Position = 0, Mandatory = true)]
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
[Alias("Msg")]
public Object MessageData { get; set; }
@@ -206,10 +206,18 @@ namespace Microsoft.PowerShell.Commands
}
}
}
}
/// <summary>
/// This method implements the ProcessRecord method for Write-Information command
/// </summary>
protected override void ProcessRecord()
{
WriteInformation(MessageData, Tags);
}
}//WriteInformationCommand
#endregion WriteInformationCommand
@@ -70,6 +70,19 @@ Describe "Stream writer tests" -Tags "CI" {
}
Context "Write-Information cmdlet" {
BeforeAll {
$ps = [powershell]::Create()
}
BeforeEach {
$ps.Commands.Clear()
$ps.Streams.ClearStreams()
}
AfterAll {
$ps.Dispose()
}
It "Write-Information outputs an information object" {
# redirect the streams is sufficient
$result = Write-Information "Test Message" *>&1
@@ -89,5 +102,13 @@ Describe "Stream writer tests" -Tags "CI" {
}
"$result" | Should be "Test Message"
}
It "Write-Information accept objects from pipe" {
$ps.AddScript("'teststring',12345 | Write-Information -InformationAction Continue").Invoke()
$result = $ps.Streams.Information
$result.Count | Should be 2
$result[0].MessageData | Should be "teststring"
$result[1].MessageData | Should be "12345"
}
}
}