Create new test for Get-Credential which requires module to create a test host

This commit is contained in:
James Truher committed 2016-08-19 13:01:04 -07:00
1 parent d7b31245d3
commit 5644c4c54b
2 files changed
+303

No files matched your search

@@ -0,0 +1,31 @@
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 "Get-Credential Test" -tag "CI" {
BeforeAll {
$th = New-TestHost
$th.UI.StringForSecureString = "This is a test"
$rs = [runspacefactory]::Createrunspace($th)
$rs.open()
$ps = [powershell]::Create()
$ps.Runspace = $rs
$ps.Commands.Clear()
}
AfterAll {
$rs.Close()
$rs.Dispose()
$ps.Dispose()
}
It "Get-Credential produces as credential object" {
$cred = $ps.AddScript("Get-Credential -User Joe -Message Foo").Invoke() | Select-Object -First 1
$cred.gettype().FullName | Should Be "System.Management.Automation.PSCredential"
$netcred = $cred.GetNetworkCredential()
$netcred.UserName | Should be "Joe"
$netcred.Password | Should be "this is a test"
}
}