- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为使用 New-AzureRmDnsRecordSet 的脚本编写单元测试。 New-AzureRmDnsRecordSet
上的 DnsRecords
参数验证我是否传入了 Microsoft.Azure.Commands.Dns.DnsRecordBase[]
类型,该类型是New-AzureRmDnsRecordConfig
的返回值。问题是,我似乎无法将任何内容转换为 DnsRecordBase 类型。
这是一个显示我的问题的虚拟脚本:
function test-mocking {
$arecordtype = New-AzureRmDnsRecordConfig -Ipv4Address 1.2.3.4
New-AzureRmDnsRecordSet -Name "UT" -RecordType A -ResourceGroupName 'RG-UT' -TTL 60 -ZoneName 'zone1' -DnsRecords $arecordtype -Confirm:$False -Overwrite
}
Describe 'test-mocking' {
Mock New-AzureRmDnsRecordSet { return 'sup' }
Mock New-AzureRmDnsRecordConfig { return '1.2.3.4' }
it 'does nothing' {
test-mocking
Assert-MockCalled New-AzureRmDnsRecordSet
}
}
输出:
Describing test-mocking
[-] does nothing 47ms
PSInvalidCastException: Cannot convert the "1.2.3.4" value of type "System.String" to type "Microsoft.Azure.Commands.Dns.DnsRecordBase[]".
ArgumentTransformationMetadataException: Cannot convert the "1.2.3.4" value of type "System.String" to type "Microsoft.Azure.Commands.Dns.DnsRecordBase[]".
ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'DnsRecords'. Cannot convert the "1.2.3.4" value of type "System.String" to type "Microsoft.Azure.Commands.Dns.DnsRecordBase[]".
at test-mocking, C:\Temp\testMock.ps1: line 3
at <ScriptBlock>, C:\Temp\testMock.ps1: line 11
我已经尝试了所有代替“1.2.3.4”的方法...整数、字符串、哈希表、数组、System.Object、$null
我也不能只运行 New-AzureRmDnsRecordConfig
来获取真实对象,因为该 commandlet 要求我运行 Login-AzureRmAccount。这是一个更大的脚本的一部分,我真的只是想模拟这些来测试脚本内的其他内容。
我尝试使用 Pester 的新 CMDLET New-MockObject
但收到此错误:
[-] does nothing 110ms
MemberAccessException: Cannot create an abstract class.
MethodInvocationException: Exception calling "GetUninitializedObject" with "1" argument(s): "Cannot create an abstract class."
at New-MockObject, C:\Program Files\WindowsPowerShell\Modules\Pester\4.0.6\Functions\New-MockObject.ps1: line 22
at <ScriptBlock>, <No file>: line 1
at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\Pester\4.0.6\Functions\Mock.ps1: line 1111
at ExecuteBlock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.0.6\Functions\Mock.ps1: line 1123
at Invoke-Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\4.0.6\Functions\Mock.ps1: line 966
at <ScriptBlock><Process>, <No file>: line 119
at test-mocking, C:\Temp\testMock.ps1: line 2
at <ScriptBlock>, C:\Temp\testMock.ps1: line 11
代码:
function test-mocking {
$arecordtype = New-AzureRmDnsRecordConfig -Ipv4Address 1.2.3.4
New-AzureRmDnsRecordSet -Name "UT" -RecordType A -ResourceGroupName 'RG-UT' -TTL 60 -ZoneName 'zone1' -DnsRecords $arecordtype -Confirm:$False -Overwrite
}
Describe 'test-mocking' {
Mock New-AzureRmDnsRecordSet { return 'sup' }
Mock New-AzureRmDnsRecordConfig { return New-MockObject -Type Microsoft.Azure.Commands.Dns.DnsRecordBase }
it 'does nothing' {
test-mocking
Assert-MockCalled New-AzureRmDnsRecordSet
}
}
最佳答案
模拟这个对象的方法是:
New-MockObject -Type ([Microsoft.Azure.Commands.Dns.DnsRecordSet])
我遇到了同样的问题,并在中找到了完整的类型 Set-AzureRmDnsRecordSet online help通过查看为 -RecordSet 参数列出的类型。
更新:如果您可以使用 $object.GetType().FullName
获取对象类型的实例,则有一种更简单的方法来获取完整类型:
$temp = Get-AzureRmDnsRecordSet -ZoneName "myzone.com" -ResourceGroupName "myResources" -Name "mysite" -RecordType A
$temp.GetType().FullName
这将输出Microsoft.Azure.Commands.Dns.DnsRecordSet
关于powershell - 模拟 New-AzureRmDnsRecordConfig 返回 Microsoft.Azure.Commands.Dns.DnsRecordBase[] 类型的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45866150/
我正在尝试安装一种用于 TCPDF 的字体。为此,我需要运行附带的命令行实用程序 ttf2ufm。 (包含在 TCPDF 中的 fonts/utils/ttf2ufm 中)但是当我运行它时,出现错误
我是 answering a question并假设 if [ $(command) ]; then ... 总是等同于 if command; then ... 但是,我得到了a couple of
我的package.json定义: ... "scripts": { "start": "node scripts/start.js", "build"
我知道默认的“CTRL+B”Windows 命令可用于显示所有嵌套文件。 是否有显示所有嵌套文件夹的快捷方式? 最佳答案 我怀疑 Total Commander 中是否存在此功能。内置tree实用性对
任何人都可以告诉我,是否有任何可以检测当前运营商名称的AT命令? 我用过AT+COPS? 它返回给我运算符(operator)的数字代码:0,2,40410 然后我使用命令 AT+WOPN = 0,4
我需要将网站托管到 google firebase 托管。 我几乎到处都看过,但钢有问题。 我已安装 npm install --global firebase 还有 npm install -g f
我想要这样的东西 如果(command_not_exists)退出 谁能告诉我如何在 cshell 脚本中实现此功能? 最佳答案 我的问题是使用 where 命令解决的(我尝试使用 which 命令)
通过使用 + 的参数调用它,我可以使 vim 将光标定位在文件的最后一行。 : vi + myfile # "+" = go to last line of file 我怎样才能做到
我想要这样的东西 如果(command_not_exists)退出 谁能告诉我如何在 cshell 脚本中实现此功能? 最佳答案 我的问题是使用 where 命令解决的(我尝试使用 which 命令)
在 cobra 中,我创建了一个命令命令: myapp zip -directory "xzy" -output="zipname" myapp upload -filename="abc" 我想制作
我应用了所有可能的答案,但仍然是同样的问题。 也试过 $this->db->reconnect(); 我的查询没有问题 我的代码: public function GetdistributorsDet
有什么区别: eval echo lala 和: command="echo lala" $command 它们似乎都具有相同的效果,但我可能遗漏了一些东西。此外,如果它们确实具有相同的效果,那么ev
要将命令的输出存储为 sh/ksh/bash 中的变量,您可以执行任一操作 var=$(command) 或 var=`command` 这两种方法有什么区别? 最佳答案 反引号/标记已被弃用,取而代
我想让我的用户根据他的选择以 sudo 和普通用户身份运行。他可以使用 sudo 或普通用户,但如果不使用 sudo,我必须禁用某些功能来消除错误。那么我怎么知道该用户是否给了我 sudo 执行权限?
这个问题已经有答案了: Command substitution: backticks or dollar sign / paren enclosed? [duplicate] (3 个回答) 已关闭
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Command substitution: backticks or dollar sign / paren enc
要将命令的输出存储为 sh/ksh/bash 中的变量,您可以执行任一操作 var=$(command) 或 var=`command` 这两种方法有什么区别? 最佳答案 反引号/标记已被弃用,取而代
Linux 101 Hacks 这本书的第 38 页建议: cat url-list.txt | xargs wget –c 我通常这样做: for i in `cat url-list.txt`
问题是当我为我的项目编写 Makefile 时,当我需要检测当前分支名称时,在 make 规则中我这样做了: check_branch: if [ "$(git rev-parse --abb
默认情况下,控制台命令文件夹位于:MyProject\MyBundle\Command并且一切都按预期工作,但是如果我将文件夹移动到另一个目录中,例如:MyProject\MyBundle\MyFol
我是一名优秀的程序员,十分优秀!