Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions test/powershell/Modules/CimCmdlets/CimInstance.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Try {
try {
if ( ! $IsWindows ) {
$PSDefaultParameterValues['it:pending'] = $true
}

Describe "CimInstance cmdlet tests" -Tag @("CI") {
BeforeAll {
if ( ! $IsWindows ) { return }
$instance = get-ciminstance cim_computersystem
$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
$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 ","
[string]$pLowerValue = $instance.$pLower -join ","
[string]$pUpperValue = $instance.$pUpper -join ","
$pLowerValue | Should -BeExactly $pUpperValue
}
}

It "GetCimSessionInstanceId method invocation should return data" {
$instance.GetCimSessionInstanceId() | Should -BeOfType "Guid"
$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"
}
{ Get-CimInstance -ClassName thisnameshouldnotexist -ErrorAction Stop } | Should -Throw -ErrorId "HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand"
}
}
}

finally {
$PSDefaultParameterValues.Remove('it:pending')
}
30 changes: 16 additions & 14 deletions test/powershell/Modules/CimCmdlets/CimSession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@ try {
if ( ! $IsWindows ) {
$PSDefaultParameterValues['it:pending'] = $true
}

Describe "New-CimSession" -Tag @("CI") {
BeforeAll {
$sessions = @()
}

AfterEach {
try {
$sessions | remove-cimsession
}
finally {
$sessions | Remove-CimSession -ErrorAction SilentlyContinue
$sessions = @()
}
}

It "A cim session can be created" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$session = New-CimSession -ComputerName . -Name $sessionName
$sessions += $session
$session.Name | Should -Be $sessionName
$session.Name | Should -BeExactly $sessionName
$session.InstanceId | Should -BeOfType "System.Guid"
}

It "A Cim session can be retrieved" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$session = New-CimSession -ComputerName . -Name $sessionName
$sessions += $session
(get-cimsession -Name $sessionName).InstanceId | Should -Be $session.InstanceId
(get-cimsession -Id $session.Id).InstanceId | Should -Be $session.InstanceId
(get-cimsession -InstanceId $session.InstanceId).InstanceId | Should -Be $session.InstanceId
(Get-CimSession -Name $sessionName).InstanceId | Should -Be $session.InstanceId
(Get-CimSession -Id $session.Id).InstanceId | Should -Be $session.InstanceId
(Get-CimSession -InstanceId $session.InstanceId).InstanceId | Should -Be $session.InstanceId
}

It "A cim session can be removed" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$session = New-CimSession -ComputerName . -Name $sessionName
$sessions += $session
$session.Name | Should -Be $sessionName
$session.Name | Should -BeExactly $sessionName
$session | Remove-CimSession
Get-CimSession $session.Id -ErrorAction SilentlyContinue | Should -BeNullOrEmpty
}
}
}

finally {
$PSDefaultParameterValues.remove('it:pending')
$PSDefaultParameterValues.Remove('it:pending')
}
24 changes: 8 additions & 16 deletions test/powershell/Modules/CimCmdlets/Get-CimClass.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,33 @@ try {
$PSDefaultParameterValues['it:pending'] = $true
}

Describe 'Get-CimClass' -tags "CI" {
Describe 'Get-CimClass' -Tags "CI" {

It 'can get CIM_Error CIM class' {
Get-CimClass -ClassName CIM_Error | Should -Not -BeNullOrEmpty
}

It 'can get class when namespace is specified' {
Get-CimClass -ClassName CIM_OperatingSystem -Namespace root/cimv2 | Should -Not -BeNullOrEmpty
}

It 'produces an error when a non-existent class is used' {
try {
Get-CimClass -ClassName thisclasstypedoesnotexist -ea stop
throw "Expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
{ Get-CimClass -ClassName thisclasstypedoesnotexist -ErrorAction Stop } | Should -Throw -ErrorId "HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}

It 'produces an error when an improper namespace is used' {
try {
Get-CimClass -ClassName CIM_OperatingSystem -Namespace badnamespace -ea stop
throw "Expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x8004100e,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
{ Get-CimClass -ClassName CIM_OperatingSystem -Namespace badnamespace -ErrorAction Stop } | Should -Throw -ErrorId "HRESULT 0x8004100e,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
}

# feature tests
Describe 'Get-CimClass' -tags @("Feature") {
Describe 'Get-CimClass' -Tags @("Feature") {
It 'can retrieve a class when a method is provided' {
Get-CimClass -MethodName Reboot | Should -Not -BeNullOrEmpty
}
}
}

finally {
$PSDefaultParameterValues.Remove('it:pending')
}