我有一个 PowerShell 脚本,它从 REST API 调用返回一个字符串。我在用
$Response = Invoke-RestMethod -Method Post -Uri $Uri -Body $Body -ContentType 'application/x-www-form-urlencoded'
return $Response.ToString()
我能够模拟请求,但我也应该能够模拟响应,以便它返回 $Response 的虚拟字符串值。目前我收到一个错误 RuntimeException: You cannot call a method on an null-valued expression。
我已经尝试了以下代码作为响应,但我得到了同样的错误。
Mock Invoke-RestMethod -MockWith{return "abc"}
有什么想法吗?