2016-08-15 57 views
0

我正在爲一個調用c#dll函數的Powershell模塊編寫一個測試。 例如:[命名空間] :: SomeMethod($ param1,$ param2) 任何關於如何在我的Pester測試中模擬此方法的想法?在pester中模擬c#dll函數?

回答

1

引用Pester文檔模擬僅適用於powershell cmdlet,命令或函數。

在該description section它說:

模擬任何PowerShell命令的行爲。

但是你可以像這樣的包裝嘲笑它:

Function Invoke-FooBar() { 
    [CmdletBinding()] 
    Param(
     [Parameter(Mnadatory=$True)] 
     [ValidateNotNullOrEmpty()] 
     [String]$param1, 

     [Parameter(Mnadatory=$True)] 
     [ValidateNotNullOrEmpty()] 
     [String]$param2 
    ) 
    [Namespace]::SomeMethod($param1, $param2) 
} 

然後使用糾纏的是這樣嘲諷:

Describe "Unit1" { 
    Context "Basic logic tests" { 
     Mock Invoke-Foobar {return $True} 
     It "Test1: Invoke-FooBar" { 
      Invoke-FooBar | Should Be $True 
     } 
    } 
}