diff --git a/test/powershell/Common/TestHostCS.psm1 b/test/powershell/Common/TestHostCS.psm1 index 081c48254..c056fd7a9 100755 --- a/test/powershell/Common/TestHostCS.psm1 +++ b/test/powershell/Common/TestHostCS.psm1 @@ -86,7 +86,6 @@ namespace TestHost public class Streams { public ArrayList ConsoleOutput = new ArrayList(); - public ArrayList Output = new ArrayList(); public ArrayList Input = new ArrayList(); public ArrayList Error = new ArrayList(); public ArrayList Verbose = new ArrayList(); @@ -95,6 +94,17 @@ namespace TestHost public ArrayList Information = new ArrayList(); public ArrayList Progress = new ArrayList(); public ArrayList Prompt = new ArrayList(); + public void Clear() { + ConsoleOutput.Clear() + Input.Clear() + Error.Clear() + Verbose.Clear() + Debug.Clear() + Warning.Clear() + Information.Clear() + Progress.Clear() + Prompt.Clear() + } } public class TestPSHostUserInterface : PSHostUserInterface { @@ -112,7 +122,9 @@ namespace TestHost public override Dictionary Prompt(string caption, string message, Collection descriptions) { - Streams.Prompt.Add(caption + ":" + message); + string s = String.Empty; + if ( descriptions[0] != null ) { s = descriptions[0].Name; } + Streams.Prompt.Add(caption + ":" + message + ":" + s); Dictionary d = new Dictionary(); d.Add(descriptions[0].ToString(), new PSObject(promptResponse)); return d; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 new file mode 100644 index 000000000..bf9e624ef --- /dev/null +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Read-Host.Tests.ps1 @@ -0,0 +1,42 @@ +if ( ! (get-module -ea silentlycontinue TestHostCS )) +{ + $root = git rev-parse --show-toplevel + $pestertestroot = join-path $root test/powershell + $common = join-path $pestertestroot Common + $hostmodule = join-path $common TestHostCS.psm1 + import-module $hostmodule +} +Describe "Read-Host Test" -tag "CI" { + BeforeAll { + $th = New-TestHost + $rs = [runspacefactory]::Createrunspace($th) + $rs.open() + $ps = [powershell]::Create() + $ps.Runspace = $rs + $ps.Commands.Clear() + } + AfterEach { + $ps.Commands.Clear() + } + AfterAll { + $rs.Close() + $rs.Dispose() + $ps.Dispose() + } + It "Read-Host returns expected string" { + $result = $ps.AddCommand("Read-Host").Invoke() + $result | Should Be $th.UI.ReadLineData + } + It "Read-Host sets the prompt correctly" { + $result = $ps.AddScript("Read-Host -prompt myprompt").Invoke() + $prompt = $th.ui.streams.prompt[0] + $prompt | should Not BeNullOrEmpty + $prompt.split(":")[-1] | should be myprompt + } + It "Read-Host returns a secure string when using -AsSecureString parameter" { + $result = $ps.AddScript("Read-Host -AsSecureString").Invoke() | select-object -first 1 + $result.GetType().Name | should be "SecureString" + [pscredential]::New("foo",$result).GetNEtworkCredential().Password | should BeExactly TEST + + } +}