Tests/Get-JIMConnectedSystem.Tests.ps1
|
#Requires -Modules Pester <# .SYNOPSIS Pester tests for Get-JIMConnectedSystem cmdlet. #> BeforeAll { $ModulePath = Join-Path $PSScriptRoot '..' Get-Module JIM -ErrorAction SilentlyContinue | Remove-Module -Force Import-Module $ModulePath -Force } AfterAll { Get-Module JIM -ErrorAction SilentlyContinue | Remove-Module -Force } Describe 'Get-JIMConnectedSystem' { Context 'Parameter Sets' { BeforeAll { $command = Get-Command Get-JIMConnectedSystem } It 'Should have a List parameter set as default' { $command.DefaultParameterSet | Should -Be 'List' } It 'Should have a ById parameter set' { $command.ParameterSets.Name | Should -Contain 'ById' } It 'Should have an ObjectTypes parameter set' { $command.ParameterSets.Name | Should -Contain 'ObjectTypes' } It 'Should have a DeletionPreview parameter set' { $command.ParameterSets.Name | Should -Contain 'DeletionPreview' } } Context 'Parameter Validation' { BeforeAll { $command = Get-Command Get-JIMConnectedSystem } It 'Should have Id parameter that accepts pipeline by property name' { $idParam = $command.Parameters['Id'] $idParam.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.ValueFromPipelineByPropertyName } | Should -Not -BeNullOrEmpty } It 'Should have Name parameter that supports wildcards' { $nameParam = $command.Parameters['Name'] $nameParam.Attributes | Where-Object { $_ -is [System.Management.Automation.SupportsWildcardsAttribute] } | Should -Not -BeNullOrEmpty } It 'Should have ObjectTypes as a switch parameter' { $command.Parameters['ObjectTypes'].SwitchParameter | Should -BeTrue } It 'Should have DeletionPreview as a switch parameter' { $command.Parameters['DeletionPreview'].SwitchParameter | Should -BeTrue } } Context 'Requires Connection' { BeforeEach { Disconnect-JIM } It 'Should throw when not connected' { { Get-JIMConnectedSystem } | Should -Throw '*Connect-JIM*' } It 'Should throw when getting by ID without connection' { { Get-JIMConnectedSystem -Id 1 } | Should -Throw '*Connect-JIM*' } } Context 'Help Documentation' { BeforeAll { $help = Get-Help Get-JIMConnectedSystem -Full } It 'Should have a synopsis' { $help.Synopsis | Should -Not -BeNullOrEmpty } It 'Should have a description' { $help.Description | Should -Not -BeNullOrEmpty } It 'Should have examples' { $help.Examples.Example.Count | Should -BeGreaterThan 0 } It 'Should document the Id parameter' { $help.Parameters.Parameter | Where-Object { $_.Name -eq 'Id' } | Should -Not -BeNullOrEmpty } It 'Should document the Name parameter' { $help.Parameters.Parameter | Where-Object { $_.Name -eq 'Name' } | Should -Not -BeNullOrEmpty } It 'Should have related links' { $help.RelatedLinks | Should -Not -BeNullOrEmpty } } } Describe 'Remove-JIMConnectedSystem' { Context 'Parameter Validation' { BeforeAll { $command = Get-Command Remove-JIMConnectedSystem } It 'Should support ShouldProcess' { $command.Parameters['WhatIf'] | Should -Not -BeNullOrEmpty $command.Parameters['Confirm'] | Should -Not -BeNullOrEmpty } It 'Should have a Force switch parameter' { $command.Parameters['Force'].SwitchParameter | Should -BeTrue } It 'Should have a PassThru switch parameter' { $command.Parameters['PassThru'].SwitchParameter | Should -BeTrue } It 'Should have Id parameter that accepts pipeline by property name' { $idParam = $command.Parameters['Id'] $idParam.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.ValueFromPipelineByPropertyName } | Should -Not -BeNullOrEmpty } It 'Should have InputObject parameter that accepts pipeline input' { $inputParam = $command.Parameters['InputObject'] $inputParam.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.ValueFromPipeline } | Should -Not -BeNullOrEmpty } } Context 'Requires Connection' { BeforeEach { Disconnect-JIM } It 'Should write error when not connected' { { Remove-JIMConnectedSystem -Id 1 -Force -ErrorAction Stop } | Should -Throw '*Connect-JIM*' } } Context 'Help Documentation' { BeforeAll { $help = Get-Help Remove-JIMConnectedSystem -Full } It 'Should have a synopsis' { $help.Synopsis | Should -Not -BeNullOrEmpty } It 'Should have examples' { $help.Examples.Example.Count | Should -BeGreaterThan 0 } } } |