From a3e193a6b3543c15fb3c545028ca050161bbfe0e Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Mon, 11 Sep 2017 12:53:34 -0700 Subject: [PATCH] Add tests for 'New-Object -ComObject' (#4776) --- .../New-Object.Tests.ps1 | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 index 6738d30c0..8e815036f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/New-Object.Tests.ps1 @@ -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 with property of 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 +}