PowerShell/test/powershell/Modules/CimCmdlets/CimInstance.Tests.ps1
James Truher [MSFT] 3f99de5784 Added tests to close code coverage in CIM area (#2528)
* Added tests to close code coverage in CIM area

Added CimAdapter.Tests for adaptation layer (code cribbed from BVT tests)
Added SessionOption.Tests.ps1 (Code cribbed from BVT tests)
Modified CimClass tests by adding more tests
Added CimSession.Tests for basic tests of New-CimSession cmdlet
Added CimInstance.Tests for basic tests of Get-CimInstance

* Add CI tags to tests

* unify test execution to use try/catch for marking tests as skipped

moved test which retrieves cimclass via method to feature as it is not
a common operation, this test can take some time as well
2016-11-17 11:46:07 -08:00

42 lines
1.6 KiB
PowerShell

Try {
if ( ! $IsWindows ) {
$PSDefaultParameterValues['it:pending'] = $true
}
Describe "CimInstance cmdlet tests" -Tag @("CI") {
BeforeAll {
if ( ! $IsWindows ) { return }
$instance = get-ciminstance cim_computersystem
}
It "CimClass property should not be null" {
# we can't use equals here as on windows cimclassname
# is win32_computersystem, but that's not likely to be the
# case on non-Windows systems
$instance.cimClass.CimClassName | should match _computersystem
}
It "Property access should be case insensitive" {
foreach($property in $instance.psobject.properties.name) {
$pUpper = $property.ToUpper()
$pLower = $property.ToLower()
[string]$pLowerValue = $pinstance.$pLower -join ","
[string]$pUpperValue = $pinstance.$pUpper -join ","
$pLowerValue | should be $pUpperValue
}
}
It "GetCimSessionInstanceId method invocation should return data" {
$instance.GetCimSessionInstanceId() | Should BeOfType "Guid"
}
It "should produce an error for a non-existing classname" {
try {
get-ciminstance -classname thisnameshouldnotexist -ea stop
throw "expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | should be "HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand"
}
}
}
}
finally {
$PSDefaultParameterValues.Remove('it:pending')
}