如果我有这个功能:
Function Test-Foo {
$filePath = Read-Host "Tell me a file path"
}
我如何模拟 Read-Host 以返回我想要的?例如,我想做这样的事情(这是行不通的):
Describe "Test-Foo" {
Context "When something" {
Mock Read-Host {return "c:\example"}
$result = Test-Foo
It "Returns correct result" {
$result | Should Be "c:\example"
}
}
}