PowerShell/test/powershell/Modules/CimCmdlets/CimSession.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

44 lines
1.6 KiB
PowerShell

try {
if ( ! $IsWindows ) {
$PSDefaultParameterValues['it:pending'] = $true
}
Describe "New-CimSession" -Tag @("CI") {
BeforeAll {
$sessions = @()
}
AfterEach {
try {
$sessions | remove-cimsession
}
finally {
$sessions = @()
}
}
It "A cim session can be created" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$sessions += $session
$session.Name | Should be $sessionName
$session.InstanceId | should BeOfType "System.Guid"
}
It "A Cim session can be retrieved" {
$sessionName = [guid]::NewGuid()
$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
}
It "A cim session can be removed" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$sessions += $session
$session.Name | Should be $sessionName
$session | Remove-CimSession
Get-CimSession $session.Id -ErrorAction SilentlyContinue | should BeNullOrEmpty
}
}
}
finally {
$PSDefaultParameterValues.remove('it:pending')
}