クラスベースのDSCリソースのユニットテストに問題があります。私はクラスのいくつかの関数を模擬しようとしていると私はキャストエラーを取得します。ユニットPesterでクラスベースのDSCリソースをテストする
PSInvalidCastException: Cannot convert the "bool TestVMExists(string vmPath,
string vmName)" value of type "System.Management.Automation.PSMethod" to type
"System.Management.Automation.ScriptBlock".
私のテストコードはこれです:
using module 'C:\Program Files\WindowsPowerShell\Modules\xVMWareVM\xVMWareVM.psm1'
$resource = [xVMWareVM]::new()
Describe "Set" {
Context "If the VM does not exist" {
Mock xVMWareVM $resource.TestVMExists {return $false}
Mock xVMWareVM $resource.CreateVM
It "Calls Create VM once" {
Assert-MockCalled $resource.CreateVM -Times 1
}
}
}
誰もがこれを達成する方法を知っていますか?
ありがとうございます。
リソースの見た目はわかりませんが、最初のアイデアはコード内の 'InModuleScope xVMWareVM {}'ですか? – BartekB