Skip to content

Commit

Permalink
Use new Pester syntax: -Parameter for Pester tests in Modules/CimCmdl…
Browse files Browse the repository at this point in the history
…ets (#6306)

* Use new Pester syntax: -Parameter for Pester tests in Modules/CimCmdlets.
  • Loading branch information
kalgiz authored and adityapatwardhan committed Mar 7, 2018
1 parent 30e9e30 commit 740c075
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions test/powershell/Modules/CimCmdlets/CimInstance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ Try {
# 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 ","
$pLowerValue | should be $pUpperValue
$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"
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand"
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/powershell/Modules/CimCmdlets/CimSession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ try {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$sessions += $session
$session.Name | Should be $sessionName
$session.InstanceId | should BeOfType "System.Guid"
$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
(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.Name | Should -Be $sessionName
$session | Remove-CimSession
Get-CimSession $session.Id -ErrorAction SilentlyContinue | should BeNullOrEmpty
Get-CimSession $session.Id -ErrorAction SilentlyContinue | Should -BeNullOrEmpty
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/powershell/Modules/CimCmdlets/Get-CimClass.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ try {

Describe 'Get-CimClass' -tags "CI" {
It 'can get CIM_Error CIM class' {
Get-CimClass -ClassName CIM_Error | Should Not BeNullOrEmpty
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
Get-CimClass -ClassName CIM_OperatingSystem -Namespace root/cimv2 | Should -Not -BeNullOrEmpty
}

It 'produces an error when a non-existent class is used' {
Expand All @@ -20,7 +20,7 @@ try {
throw "Expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | should be "HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
}
It 'produces an error when an improper namespace is used' {
Expand All @@ -29,15 +29,15 @@ try {
throw "Expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | should be "HRESULT 0x8004100e,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x8004100e,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
}
}

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

0 comments on commit 740c075

Please sign in to comment.