Tests/DataGeneration.Tests.ps1
|
#Requires -Modules Pester <# .SYNOPSIS Pester tests for Data Generation cmdlets. #> 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-JIMExampleDataSet' { Context 'Parameter Validation' { BeforeAll { $command = Get-Command Get-JIMExampleDataSet } It 'Should have Page parameter with validation' { $param = $command.Parameters['Page'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateRangeAttribute] } | Should -Not -BeNullOrEmpty } It 'Should have PageSize parameter with validation' { $param = $command.Parameters['PageSize'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateRangeAttribute] } | Should -Not -BeNullOrEmpty } } Context 'Requires Connection' { BeforeEach { Disconnect-JIM } It 'Should throw when not connected' { { Get-JIMExampleDataSet } | Should -Throw '*Connect-JIM*' } } Context 'Help Documentation' { BeforeAll { $help = Get-Help Get-JIMExampleDataSet -Full } It 'Should have a synopsis' { $help.Synopsis | Should -Not -BeNullOrEmpty } It 'Should have examples' { $help.Examples.Example.Count | Should -BeGreaterThan 0 } It 'Should have related links' { $help.RelatedLinks | Should -Not -BeNullOrEmpty } } } Describe 'Get-JIMDataGenerationTemplate' { Context 'Parameter Sets' { BeforeAll { $command = Get-Command Get-JIMDataGenerationTemplate } 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 a ByName parameter set' { $command.ParameterSets.Name | Should -Contain 'ByName' } } Context 'Parameter Validation' { BeforeAll { $command = Get-Command Get-JIMDataGenerationTemplate } It 'Should have Id parameter' { $command.Parameters['Id'] | Should -Not -BeNullOrEmpty } It 'Should have Name parameter' { $command.Parameters['Name'] | Should -Not -BeNullOrEmpty } It 'Should have Name parameter with validation' { $param = $command.Parameters['Name'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateNotNullOrEmptyAttribute] } | Should -Not -BeNullOrEmpty } It 'Should have Id parameter that accepts pipeline by property name' { $param = $command.Parameters['Id'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.ValueFromPipelineByPropertyName } | Should -Not -BeNullOrEmpty } } Context 'Requires Connection' { BeforeEach { Disconnect-JIM } It 'Should throw when not connected' { { Get-JIMDataGenerationTemplate } | Should -Throw '*Connect-JIM*' } } Context 'Help Documentation' { BeforeAll { $help = Get-Help Get-JIMDataGenerationTemplate -Full } It 'Should have a synopsis' { $help.Synopsis | Should -Not -BeNullOrEmpty } It 'Should have examples' { $help.Examples.Example.Count | Should -BeGreaterThan 0 } It 'Should have related links' { $help.RelatedLinks | Should -Not -BeNullOrEmpty } } } Describe 'Invoke-JIMDataGenerationTemplate' { Context 'Parameter Sets' { BeforeAll { $command = Get-Command Invoke-JIMDataGenerationTemplate } It 'Should have a ById parameter set as default' { $command.DefaultParameterSet | Should -Be 'ById' } It 'Should have a ByName parameter set' { $command.ParameterSets.Name | Should -Contain 'ByName' } } Context 'Parameter Validation' { BeforeAll { $command = Get-Command Invoke-JIMDataGenerationTemplate } It 'Should have a mandatory Id parameter' { $param = $command.Parameters['Id'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.Mandatory } | Should -Not -BeNullOrEmpty } It 'Should have a mandatory Name parameter' { $param = $command.Parameters['Name'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.Mandatory } | Should -Not -BeNullOrEmpty } It 'Should have Name parameter with validation' { $param = $command.Parameters['Name'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateNotNullOrEmptyAttribute] } | Should -Not -BeNullOrEmpty } It 'Should have Id parameter that accepts pipeline by property name' { $param = $command.Parameters['Id'] $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] -and $_.ValueFromPipelineByPropertyName } | Should -Not -BeNullOrEmpty } It 'Should have Wait switch parameter' { $command.Parameters['Wait'].SwitchParameter | Should -BeTrue } It 'Should have PassThru switch parameter' { $command.Parameters['PassThru'].SwitchParameter | Should -BeTrue } It 'Should support ShouldProcess' { $command.Parameters['WhatIf'] | Should -Not -BeNullOrEmpty $command.Parameters['Confirm'] | Should -Not -BeNullOrEmpty } } Context 'Requires Connection' { BeforeEach { Disconnect-JIM } It 'Should throw when not connected' { { Invoke-JIMDataGenerationTemplate -Id 1 -ErrorAction Stop } | Should -Throw '*Connect-JIM*' } } Context 'Help Documentation' { BeforeAll { $help = Get-Help Invoke-JIMDataGenerationTemplate -Full } It 'Should have a synopsis' { $help.Synopsis | Should -Not -BeNullOrEmpty } It 'Should have examples' { $help.Examples.Example.Count | Should -BeGreaterThan 0 } It 'Should have related links' { $help.RelatedLinks | Should -Not -BeNullOrEmpty } } } |