Add tests for 'New-Object -ComObject' (#4776)

This commit is contained in:
Travis Plunk authored and Dongbo Wang committed 2017-09-11 12:53:34 -07:00
1 parent 3815a95242
commit a3e193a6b3
1 file changed
+36
@@ -165,3 +165,39 @@ Describe "New-Object DRT basic functionality" -Tags "CI" {
$result.foo | Should Be 123
}
}
try
{
$defaultParamValues = $PSdefaultParameterValues.Clone()
$PSDefaultParameterValues["it:skip"] = ![System.Management.Automation.Platform]::IsWindowsDesktop
Describe "New-Object COM functionality" -Tags "CI" {
$testCases = @(
@{
Name = 'Microsoft.Update.AutoUpdate'
Property = 'Settings'
Type = 'Object'
}
@{
Name = 'Microsoft.Update.SystemInfo'
Property = 'RebootRequired'
Type = 'Bool'
}
)
It "Should be able to create <Name> with property <Property> of Type <Type>" -TestCases $testCases {
param($Name, $Property, $Type)
$comObject = New-Object -ComObject $name
$comObject.$Property | should not be $null
$comObject.$Property | should beoftype $Type
}
It "Should fail with correct error when creating a COM object that dose not exist" {
{New-Object -ComObject 'doesnotexist'} | shouldBeErrorId 'NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand'
}
}
}
finally
{
$global:PSdefaultParameterValues = $defaultParamValues
}