2016-08-15 60 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 
     } 
    } 
}