Skip to content

Commit c25588e

Browse files
authored
Add integration test for ConvertTo-SqlDscEditionName command (#2273)
1 parent 20fa89e commit c25588e

File tree

4 files changed

+163
-0
lines changed

4 files changed

+163
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Added integration tests for `Remove-SqlDscAudit` command to ensure it functions
1414
correctly in real environments
1515
[issue #2241](https://github.com/dsccommunity/SqlServerDsc/issues/2241).
16+
- Added integration test for `ConvertTo-SqlDscEditionName` command to ensure
17+
command reliability in real environments
18+
[issue #2208](https://github.com/dsccommunity/SqlServerDsc/issues/2208).
1619
- Added integration tests for `Import-SqlDscPreferredModule` command to ensure
1720
proper module import functionality in real environments
1821
[issue #2225](https://github.com/dsccommunity/SqlServerDsc/issues/2225).

azure-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ stages:
303303
'tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1'
304304
'tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1'
305305
'tests/Integration/Commands/Get-SqlDscServerProtocolName.Integration.Tests.ps1'
306+
'tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1'
306307
'tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1'
307308
'tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1'
308309
'tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1'
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
2+
param ()
3+
4+
BeforeDiscovery {
5+
try
6+
{
7+
if (-not (Get-Module -Name 'DscResource.Test'))
8+
{
9+
# Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
10+
if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
11+
{
12+
# Redirect all streams to $null, except the error stream (stream 2)
13+
& "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
14+
}
15+
16+
# If the dependencies have not been resolved, this will throw an error.
17+
Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
18+
}
19+
}
20+
catch [System.IO.FileNotFoundException]
21+
{
22+
throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks noop" first.'
23+
}
24+
}
25+
26+
BeforeAll {
27+
$script:moduleName = 'SqlServerDsc'
28+
29+
Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
30+
}
31+
32+
Describe 'ConvertTo-SqlDscEditionName' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') {
33+
BeforeAll {
34+
Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose
35+
36+
# Define expected edition mappings for validation
37+
$script:expectedEditionMappings = @{
38+
2176971986 = @{
39+
EditionId = 2176971986
40+
Edition = 'Developer'
41+
EditionName = 'SQL Server Developer'
42+
}
43+
2017617798 = @{
44+
EditionId = 2017617798
45+
Edition = 'Developer'
46+
EditionName = 'Power BI Report Server - Developer'
47+
}
48+
1369084056 = @{
49+
EditionId = 1369084056
50+
Edition = 'Evaluation'
51+
EditionName = 'Power BI Report Server - Evaluation'
52+
}
53+
}
54+
}
55+
56+
Context 'When converting known EditionId values' {
57+
It 'Should return correct mapping for SQL Server Developer edition ID (2176971986)' {
58+
$result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop'
59+
60+
$result | Should -Not -BeNullOrEmpty
61+
$result.EditionId | Should -Be $script:expectedEditionMappings[2176971986].EditionId
62+
$result.Edition | Should -Be $script:expectedEditionMappings[2176971986].Edition
63+
$result.EditionName | Should -Be $script:expectedEditionMappings[2176971986].EditionName
64+
}
65+
66+
It 'Should return correct mapping for Power BI Report Server Developer edition ID (2017617798)' {
67+
$result = ConvertTo-SqlDscEditionName -Id 2017617798 -ErrorAction 'Stop'
68+
69+
$result | Should -Not -BeNullOrEmpty
70+
$result.EditionId | Should -Be $script:expectedEditionMappings[2017617798].EditionId
71+
$result.Edition | Should -Be $script:expectedEditionMappings[2017617798].Edition
72+
$result.EditionName | Should -Be $script:expectedEditionMappings[2017617798].EditionName
73+
}
74+
75+
It 'Should return correct mapping for Power BI Report Server Evaluation edition ID (1369084056)' {
76+
$result = ConvertTo-SqlDscEditionName -Id 1369084056 -ErrorAction 'Stop'
77+
78+
$result | Should -Not -BeNullOrEmpty
79+
$result.EditionId | Should -Be $script:expectedEditionMappings[1369084056].EditionId
80+
$result.Edition | Should -Be $script:expectedEditionMappings[1369084056].Edition
81+
$result.EditionName | Should -Be $script:expectedEditionMappings[1369084056].EditionName
82+
}
83+
}
84+
85+
Context 'When converting unknown EditionId values' {
86+
It 'Should return Unknown for an unknown EditionId (99999)' {
87+
$result = ConvertTo-SqlDscEditionName -Id 99999 -ErrorAction 'Stop'
88+
89+
$result | Should -Not -BeNullOrEmpty
90+
$result.EditionId | Should -Be 99999
91+
$result.Edition | Should -Be 'Unknown'
92+
$result.EditionName | Should -Be 'Unknown'
93+
}
94+
95+
It 'Should return Unknown for another unknown EditionId (0)' {
96+
$result = ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop'
97+
98+
$result | Should -Not -BeNullOrEmpty
99+
$result.EditionId | Should -Be 0
100+
$result.Edition | Should -Be 'Unknown'
101+
$result.EditionName | Should -Be 'Unknown'
102+
}
103+
104+
It 'Should return Unknown for a large unknown EditionId (4294967295)' {
105+
$result = ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop'
106+
107+
$result | Should -Not -BeNullOrEmpty
108+
$result.EditionId | Should -Be 4294967295
109+
$result.Edition | Should -Be 'Unknown'
110+
$result.EditionName | Should -Be 'Unknown'
111+
}
112+
}
113+
114+
Context 'When validating output object properties' {
115+
It 'Should return PSCustomObject with correct properties' {
116+
$result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop'
117+
118+
$result | Should -BeOfType ([System.Management.Automation.PSCustomObject])
119+
$result.PSObject.Properties.Name | Should -Contain 'EditionId'
120+
$result.PSObject.Properties.Name | Should -Contain 'Edition'
121+
$result.PSObject.Properties.Name | Should -Contain 'EditionName'
122+
$result.PSObject.Properties.Name | Should -HaveCount 3
123+
}
124+
125+
It 'Should return consistent object types for all EditionId values' {
126+
$resultKnown = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop'
127+
$resultUnknown = ConvertTo-SqlDscEditionName -Id 99999 -ErrorAction 'Stop'
128+
129+
$resultKnown.GetType() | Should -Be $resultUnknown.GetType()
130+
131+
# Verify both have the same property structure
132+
$resultKnown.PSObject.Properties.Name | Should -Be $resultUnknown.PSObject.Properties.Name
133+
}
134+
135+
It 'Should return EditionId as UInt32 type' {
136+
$result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop'
137+
138+
$result.EditionId | Should -BeOfType ([System.UInt32])
139+
}
140+
141+
It 'Should return Edition and EditionName as String types' {
142+
$result = ConvertTo-SqlDscEditionName -Id 2176971986 -ErrorAction 'Stop'
143+
144+
$result.Edition | Should -BeOfType ([System.String])
145+
$result.EditionName | Should -BeOfType ([System.String])
146+
}
147+
}
148+
149+
Context 'When testing parameter validation' {
150+
It 'Should accept minimum UInt32 value (0)' {
151+
{ ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop' } | Should -Not -Throw
152+
}
153+
154+
It 'Should accept maximum UInt32 value (4294967295)' {
155+
{ ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' } | Should -Not -Throw
156+
}
157+
}
158+
}

tests/Integration/Commands/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ to each other. Dependencies are made to speed up the testing.**
4141
Command | Run order # | Depends on # | Use instance | Creates persistent objects
4242
--- | --- | --- | --- | ---
4343
Prerequisites | 0 | - | - | Sets up dependencies
44+
ConvertTo-SqlDscEditionName | 0 | - | - | -
4445
Import-SqlDscPreferredModule | 0 | - | - | -
4546
Install-SqlDscServer | 1 | 0 (Prerequisites) | - | DSCSQLTEST instance
4647
Connect-SqlDscDatabaseEngine | 1 | 0 (Prerequisites) | DSCSQLTEST | -

0 commit comments

Comments
 (0)