From fd90eb3c7967e4d3fc0d673376c7ab9a098afe3b Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 5 Oct 2025 20:42:59 +0200 Subject: [PATCH 1/8] Improve integration and unit tests cleanup --- CHANGELOG.md | 16 +++ ...scDatabasePermission.Integration.Tests.ps1 | 48 ++++--- ...qlDscPreferredModule.Integration.Tests.ps1 | 23 ++-- .../New-SqlDscAudit.Integration.Tests.ps1 | 30 ++--- .../New-SqlDscDatabase.Integration.Tests.ps1 | 28 ++-- .../New-SqlDscLogin.Integration.Tests.ps1 | 127 +++++++----------- .../Get-SqlDscConfigurationOption.Tests.ps1 | 44 +++--- .../Set-SqlDscConfigurationOption.Tests.ps1 | 28 ++-- .../Test-SqlDscConfigurationOption.Tests.ps1 | 26 ++-- 9 files changed, 172 insertions(+), 198 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4500f7501..4065278375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Refactored integration tests to remove `finally` blocks from `It`-blocks and + use Pester `BeforeEach`/`AfterEach` blocks instead, following DSC Community + coding guidelines. This improves test cleanup reliability and maintainability + across the following test files ([issue #2288](https://github.com/dsccommunity/SqlServerDsc/issues/2288)): + - `New-SqlDscLogin.Integration.Tests.ps1` + - `New-SqlDscAudit.Integration.Tests.ps1` + - `Get-SqlDscDatabasePermission.Integration.Tests.ps1` + - `Get-SqlDscPreferredModule.Integration.Tests.ps1` + - `New-SqlDscDatabase.Integration.Tests.ps1` +- Refactored unit tests to remove `finally` blocks from `It`-blocks and + use Pester `AfterEach` blocks instead, following DSC Community coding + guidelines. This improves test cleanup reliability and maintainability + across the following test files ([issue #2288](https://github.com/dsccommunity/SqlServerDsc/issues/2288)): + - `Set-SqlDscConfigurationOption.Tests.ps1` + - `Get-SqlDscConfigurationOption.Tests.ps1` + - `Test-SqlDscConfigurationOption.Tests.ps1` - `Test-SqlDscIsDatabasePrincipal` and `Get-SqlDscDatabasePermission` - Added `Refresh` parameter to refresh SMO collections before checking database principals, addressing issues with custom database roles created diff --git a/tests/Integration/Commands/Get-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscDatabasePermission.Integration.Tests.ps1 index ee0a88e9e0..e643a54286 100644 --- a/tests/Integration/Commands/Get-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -163,6 +163,19 @@ Describe 'Get-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integrati } Context 'When working with built-in database roles' { + BeforeEach { + $script:customRoleName = $null + } + + AfterEach { + # Clean up the custom role if it was created + if ($script:customRoleName) + { + $dropRoleSql = "USE [$($script:testDatabaseName)]; DROP ROLE [$script:customRoleName];" + Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $dropRoleSql -Force -ErrorAction 'SilentlyContinue' + } + } + It 'Should return permissions for db_datareader role' { # Note: The command excludes fixed roles by default, so this should return null or empty $result = Get-SqlDscDatabasePermission -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Name 'db_datareader' -ErrorAction 'SilentlyContinue' @@ -173,33 +186,24 @@ Describe 'Get-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integrati It 'Should work with non-fixed database roles when they exist' { # Create a custom database role for testing - $customRoleName = 'TestRole_' + (Get-Random) - $createRoleSql = "USE [$($script:testDatabaseName)]; CREATE ROLE [$customRoleName];" + $script:customRoleName = 'TestRole_' + (Get-Random) + $createRoleSql = "USE [$($script:testDatabaseName)]; CREATE ROLE [$script:customRoleName];" Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $createRoleSql -Force -ErrorAction 'Stop' - try - { - # Grant a permission to the custom role - $grantRolePermissionSql = "USE [$($script:testDatabaseName)]; GRANT CONNECT TO [$customRoleName];" - Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $grantRolePermissionSql -Force -ErrorAction 'Stop' + # Grant a permission to the custom role + $grantRolePermissionSql = "USE [$($script:testDatabaseName)]; GRANT CONNECT TO [$script:customRoleName];" + Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $grantRolePermissionSql -Force -ErrorAction 'Stop' - # Test getting permissions for the custom role - $result = Get-SqlDscDatabasePermission -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Name $customRoleName -Refresh + # Test getting permissions for the custom role + $result = Get-SqlDscDatabasePermission -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Name $script:customRoleName -Refresh - $result | Should -Not -BeNullOrEmpty - $result | Should -BeOfType [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo] + $result | Should -Not -BeNullOrEmpty + $result | Should -BeOfType [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo] - # Verify the Connect permission we granted is present - $connectPermission = $result | Where-Object { $_.PermissionType.Connect -eq $true } - $connectPermission | Should -Not -BeNullOrEmpty - $connectPermission.PermissionState | Should -Be 'Grant' - } - finally - { - # Clean up the custom role - $dropRoleSql = "USE [$($script:testDatabaseName)]; DROP ROLE [$customRoleName];" - Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $dropRoleSql -Force -ErrorAction 'SilentlyContinue' - } + # Verify the Connect permission we granted is present + $connectPermission = $result | Where-Object { $_.PermissionType.Connect -eq $true } + $connectPermission | Should -Not -BeNullOrEmpty + $connectPermission.PermissionState | Should -Be 'Grant' } } } diff --git a/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 index 9ddb85d47d..de97595674 100644 --- a/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 @@ -212,22 +212,19 @@ Describe 'Get-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integration_ It 'Should throw an error when specified version does not exist' { # Backup original environment variable - $originalSMODefaultModuleVersion = $env:SMODefaultModuleVersion + $script:originalSMODefaultModuleVersion = $env:SMODefaultModuleVersion - try { - # Set to a non-existent version - $env:SMODefaultModuleVersion = '999.999.999' + # Set to a non-existent version + $env:SMODefaultModuleVersion = '999.999.999' + + { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ErrorId 'GSDPM0001,Get-SqlDscPreferredModule' - { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ErrorId 'GSDPM0001,Get-SqlDscPreferredModule' + # Restore original environment variable + if ($script:originalSMODefaultModuleVersion) { + $env:SMODefaultModuleVersion = $script:originalSMODefaultModuleVersion } - finally { - # Restore original environment variable - if ($originalSMODefaultModuleVersion) { - $env:SMODefaultModuleVersion = $originalSMODefaultModuleVersion - } - else { - Remove-Item -Path 'env:SMODefaultModuleVersion' -ErrorAction 'SilentlyContinue' - } + else { + Remove-Item -Path 'env:SMODefaultModuleVersion' -ErrorAction 'SilentlyContinue' } } } diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index a612d5ab33..5b163a8e85 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -105,30 +105,18 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a security log audit successfully' { - $securityLogAuditName = 'SqlDscTestAudit_SecLog_' + (Get-Random) + $script:testAuditName = 'SqlDscTestAudit_SecLog_' + (Get-Random) - try - { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $securityLogAuditName - $result.DestinationType | Should -Be 'SecurityLog' + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:testAuditName + $result.DestinationType | Should -Be 'SecurityLog' - # Verify the audit exists in the server - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -ErrorAction Stop - $createdAudit | Should -Not -BeNullOrEmpty - $createdAudit.DestinationType | Should -Be 'SecurityLog' - } - finally - { - # Clean up - $auditToRemove = Get-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -ErrorAction 'SilentlyContinue' - if ($auditToRemove) - { - Remove-SqlDscAudit -AuditObject $auditToRemove -Force -ErrorAction 'SilentlyContinue' - } - } + # Verify the audit exists in the server + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit | Should -Not -BeNullOrEmpty + $createdAudit.DestinationType | Should -Be 'SecurityLog' } It 'Should support PassThru parameter' { diff --git a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 index 3083c90b6f..c0146e2a32 100644 --- a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 @@ -96,25 +96,29 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } Context 'When using the Refresh parameter' { - It 'Should refresh the database collection before creating' { - $uniqueName = 'SqlDscTestRefresh_' + (Get-Random) - - try - { - $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $uniqueName -Refresh -Force -ErrorAction Stop + BeforeEach { + $script:refreshTestDbName = $null + } - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $uniqueName - } - finally + AfterEach { + # Clean up the refresh test database if it was created + if ($script:refreshTestDbName) { - # Clean up - $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $uniqueName -ErrorAction 'SilentlyContinue' + $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:refreshTestDbName -ErrorAction 'SilentlyContinue' if ($dbToRemove) { $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force } } } + + It 'Should refresh the database collection before creating' { + $script:refreshTestDbName = 'SqlDscTestRefresh_' + (Get-Random) + + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:refreshTestDbName -Refresh -Force -ErrorAction Stop + + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:refreshTestDbName + } } } diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index df0473a833..dc53808620 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -63,6 +63,18 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:testPassword = ConvertTo-SecureString -String 'P@ssw0rd123!' -AsPlainText -Force } + BeforeEach { + $script:testLoginName = $null + } + + AfterEach { + # Clean up any login created in the test + if ($script:testLoginName -and (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName)) + { + $script:serverObject.Logins[$script:testLoginName].Drop() + } + } + It 'Should create a SQL Server login without error' { $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testSqlLoginName -SqlLogin -SecurePassword $script:testPassword -Force } @@ -82,64 +94,31 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a SQL Server login with custom default database' { - $customLoginName = 'IntegrationTestCustomDb' + $script:testLoginName = 'IntegrationTestCustomDb' - try - { - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $customLoginName -SqlLogin -SecurePassword $script:testPassword -DefaultDatabase 'tempdb' -Force + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -DefaultDatabase 'tempdb' -Force - $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $customLoginName - $loginObject.DefaultDatabase | Should -Be 'tempdb' - } - finally - { - # Clean up - if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $customLoginName) - { - $script:serverObject.Logins[$customLoginName].Drop() - } - } + $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName + $loginObject.DefaultDatabase | Should -Be 'tempdb' } It 'Should create a SQL Server login with PassThru parameter' { - $passthroughLoginName = 'IntegrationTestPassThru' + $script:testLoginName = 'IntegrationTestPassThru' - try - { - $result = New-SqlDscLogin -ServerObject $script:serverObject -Name $passthroughLoginName -SqlLogin -SecurePassword $script:testPassword -PassThru -Force + $result = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -PassThru -Force - $result | Should -Not -BeNullOrEmpty - $result.Name | Should -Be $passthroughLoginName - $result.LoginType | Should -Be 'SqlLogin' - } - finally - { - # Clean up - if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $passthroughLoginName) - { - $script:serverObject.Logins[$passthroughLoginName].Drop() - } - } + $result | Should -Not -BeNullOrEmpty + $result.Name | Should -Be $script:testLoginName + $result.LoginType | Should -Be 'SqlLogin' } It 'Should create a disabled SQL Server login' { - $disabledLoginName = 'IntegrationTestDisabled' + $script:testLoginName = 'IntegrationTestDisabled' - try - { - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $disabledLoginName -SqlLogin -SecurePassword $script:testPassword -Disabled -Force + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Disabled -Force - $loginObject = $script:serverObject.Logins[$disabledLoginName] - $loginObject.IsDisabled | Should -BeTrue - } - finally - { - # Clean up - if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $disabledLoginName) - { - $script:serverObject.Logins[$disabledLoginName].Drop() - } - } + $loginObject = $script:serverObject.Logins[$script:testLoginName] + $loginObject.IsDisabled | Should -BeTrue } It 'Should throw an error when trying to create a login that already exists' { @@ -148,25 +127,22 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } Context 'When creating a Windows user login' { - It 'Should create a Windows user login without error' { - try + AfterEach { + # Clean up Windows user login + if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName) { - # Using the SqlIntegrationTest user created by Prerequisites integration test - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName -WindowsUser -Force + $script:serverObject.Logins[$script:testWindowsUserName].Drop() + } + } - Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName | Should -BeTrue + It 'Should create a Windows user login without error' { + # Using the SqlIntegrationTest user created by Prerequisites integration test + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName -WindowsUser -Force - $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName - $loginObject.LoginType | Should -Be 'WindowsUser' - } - finally - { - # Clean up - if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName) - { - $script:serverObject.Logins[$script:testWindowsUserName].Drop() - } - } + Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName | Should -BeTrue + + $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsUserName + $loginObject.LoginType | Should -Be 'WindowsUser' } } @@ -182,24 +158,23 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } Context 'When using Force parameter' { - It 'Should create a login with Force parameter without confirmation prompt' { - $forceLoginName = 'IntegrationTestForce' - - try - { - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $forceLoginName -SqlLogin -SecurePassword $script:testPassword -Force + BeforeEach { + $script:forceLoginName = 'IntegrationTestForce' + } - Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $forceLoginName | Should -BeTrue - } - finally + AfterEach { + # Clean up Force test login + if ($script:forceLoginName -and (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:forceLoginName)) { - # Clean up - if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $forceLoginName) - { - $script:serverObject.Logins[$forceLoginName].Drop() - } + $script:serverObject.Logins[$script:forceLoginName].Drop() } } + + It 'Should create a login with Force parameter without confirmation prompt' { + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:forceLoginName -SqlLogin -SecurePassword $script:testPassword -Force + + Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:forceLoginName | Should -BeTrue + } } Context 'When running with WhatIf' { diff --git a/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 b/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 index c0a0a9402e..1a3292080f 100644 --- a/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 @@ -416,20 +416,15 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { } -Force $global:BadTestServerObject = $badServer - try { - $inputScript = 'Get-SqlDscConfigurationOption -ServerObject $global:BadTestServerObject -Name test' - $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length - - <# - Should not throw an error and should return empty from argument completer, but then - TabExpansion2 itself returns some default completions (like filesystem paths). - #> - $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) - $result.CompletionMatches.ListItemText | Should -Be 'tests' - } - finally { - Remove-Variable -Name 'BadTestServerObject' -Scope Global -Force -ErrorAction SilentlyContinue - } + $inputScript = 'Get-SqlDscConfigurationOption -ServerObject $global:BadTestServerObject -Name test' + $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length + + <# + Should not throw an error and should return empty from argument completer, but then + TabExpansion2 itself returns some default completions (like filesystem paths). + #> + $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) + $result.CompletionMatches.ListItemText | Should -Be 'tests' } It 'Should handle missing ServerObject in tab completion gracefully' { @@ -450,20 +445,15 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { $invalidServer = 'Not a server object' $global:InvalidTestServerObject = $invalidServer - try { - $inputScript = 'Get-SqlDscConfigurationOption -ServerObject $global:InvalidTestServerObject -Name test' - $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length + $inputScript = 'Get-SqlDscConfigurationOption -ServerObject $global:InvalidTestServerObject -Name test' + $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length - <# - Should not throw an error and should return empty from argument completer, but then - TabExpansion2 itself returns some default completions (like filesystem paths). - #> - $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) - $result.CompletionMatches.ListItemText | Should -Be 'tests' - } - finally { - Remove-Variable -Name 'InvalidTestServerObject' -Scope Global -Force -ErrorAction SilentlyContinue - } + <# + Should not throw an error and should return empty from argument completer, but then + TabExpansion2 itself returns some default completions (like filesystem paths). + #> + $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) + $result.CompletionMatches.ListItemText | Should -Be 'tests' } } } diff --git a/tests/Unit/Public/Set-SqlDscConfigurationOption.Tests.ps1 b/tests/Unit/Public/Set-SqlDscConfigurationOption.Tests.ps1 index 1ac12c194c..15b98b18ed 100644 --- a/tests/Unit/Public/Set-SqlDscConfigurationOption.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscConfigurationOption.Tests.ps1 @@ -523,6 +523,11 @@ Describe 'Set-SqlDscConfigurationOption' -Tag 'Public' { } } + AfterEach { + # Clean up any global test variables created during tab completion tests + Remove-Variable -Name 'BadTestServerObject' -Scope Global -Force -ErrorAction SilentlyContinue + } + It 'Should provide Name parameter completions through TabExpansion2' { # This actually exercises the argument completer code through PowerShell's tab completion system $inputScript = 'Set-SqlDscConfigurationOption -ServerObject $global:TestServerObject -Name max' @@ -602,20 +607,15 @@ Describe 'Set-SqlDscConfigurationOption' -Tag 'Public' { } -Force $global:BadTestServerObject = $badServer - try { - $inputScript = 'Set-SqlDscConfigurationOption -ServerObject $global:BadTestServerObject -Name test' - $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length - - <# - Should not throw an error and should return empty from argument completer, but then - TabExpansion2 itself returns some default completions (like filesystem paths). - #> - $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) - $result.CompletionMatches.ListItemText | Should -Be 'tests' - } - finally { - Remove-Variable -Name 'BadTestServerObject' -Scope Global -Force -ErrorAction SilentlyContinue - } + $inputScript = 'Set-SqlDscConfigurationOption -ServerObject $global:BadTestServerObject -Name test' + $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length + + <# + Should not throw an error and should return empty from argument completer, but then + TabExpansion2 itself returns some default completions (like filesystem paths). + #> + $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) + $result.CompletionMatches.ListItemText | Should -Be 'tests' } It 'Should handle missing ServerObject in tab completion gracefully' { diff --git a/tests/Unit/Public/Test-SqlDscConfigurationOption.Tests.ps1 b/tests/Unit/Public/Test-SqlDscConfigurationOption.Tests.ps1 index 217dc2d7cb..49c4f77dba 100644 --- a/tests/Unit/Public/Test-SqlDscConfigurationOption.Tests.ps1 +++ b/tests/Unit/Public/Test-SqlDscConfigurationOption.Tests.ps1 @@ -339,6 +339,11 @@ Describe 'Test-SqlDscConfigurationOption' -Tag 'Public' { } } + AfterEach { + # Clean up any global test variables created during tab completion tests + Remove-Variable -Name 'BadTestServerObject' -Scope Global -Force -ErrorAction SilentlyContinue + } + It 'Should provide Name parameter completions through TabExpansion2' { # This actually exercises the argument completer code through PowerShell's tab completion system $inputScript = 'Test-SqlDscConfigurationOption -ServerObject $global:TestServerObject -Name max' @@ -418,20 +423,15 @@ Describe 'Test-SqlDscConfigurationOption' -Tag 'Public' { } -Force $global:BadTestServerObject = $badServer - try { - $inputScript = 'Test-SqlDscConfigurationOption -ServerObject $global:BadTestServerObject -Name test' - $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length + $inputScript = 'Test-SqlDscConfigurationOption -ServerObject $global:BadTestServerObject -Name test' + $result = TabExpansion2 -inputScript $inputScript -cursorColumn $inputScript.Length - <# - Should not throw an error and should return empty from argument completer, but then - TabExpansion2 itself returns some default completions (like filesystem paths). - #> - $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) - $result.CompletionMatches.ListItemText | Should -Be 'tests' - } - finally { - Remove-Variable -Name 'BadTestServerObject' -Scope Global -Force -ErrorAction SilentlyContinue - } + <# + Should not throw an error and should return empty from argument completer, but then + TabExpansion2 itself returns some default completions (like filesystem paths). + #> + $result | Should -BeOfType ([System.Management.Automation.CommandCompletion]) + $result.CompletionMatches.ListItemText | Should -Be 'tests' } It 'Should handle missing ServerObject in tab completion gracefully' { From 85507f0c79c1352f76d3b69a07198296961f75d7 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 6 Oct 2025 12:46:34 +0200 Subject: [PATCH 2/8] Refactor error handling tests in Get-SqlDscPreferredModule to improve clarity and maintainability --- ...qlDscPreferredModule.Integration.Tests.ps1 | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 index de97595674..6d1cab2e9e 100644 --- a/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscPreferredModule.Integration.Tests.ps1 @@ -210,21 +210,27 @@ Describe 'Get-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integration_ } } - It 'Should throw an error when specified version does not exist' { - # Backup original environment variable - $script:originalSMODefaultModuleVersion = $env:SMODefaultModuleVersion - - # Set to a non-existent version - $env:SMODefaultModuleVersion = '999.999.999' - - { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ErrorId 'GSDPM0001,Get-SqlDscPreferredModule' + Context 'When testing error handling' { + BeforeEach { + # Capture the current environment variable value + $script:originalSMODefaultModuleVersion = $env:SMODefaultModuleVersion + } - # Restore original environment variable - if ($script:originalSMODefaultModuleVersion) { - $env:SMODefaultModuleVersion = $script:originalSMODefaultModuleVersion + AfterEach { + # Restore the environment variable + if ($script:originalSMODefaultModuleVersion) { + $env:SMODefaultModuleVersion = $script:originalSMODefaultModuleVersion + } + else { + Remove-Item -Path 'env:SMODefaultModuleVersion' -ErrorAction 'SilentlyContinue' + } } - else { - Remove-Item -Path 'env:SMODefaultModuleVersion' -ErrorAction 'SilentlyContinue' + + It 'Should throw an error when specified version does not exist' { + # Set to a non-existent version + $env:SMODefaultModuleVersion = '999.999.999' + + { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ErrorId 'GSDPM0001,Get-SqlDscPreferredModule' } } } From b72f68cfc7ff7ca51c9d1714c6c39ed26d06b667 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 6 Oct 2025 12:46:43 +0200 Subject: [PATCH 3/8] Replace direct access to Logins property with Get-SqlDscLogin for improved test reliability --- .../Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index dc53808620..f1f5b1519f 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -117,7 +117,7 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Disabled -Force - $loginObject = $script:serverObject.Logins[$script:testLoginName] + $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName $loginObject.IsDisabled | Should -BeTrue } From 9ba44b901ba046c6eb38ee2f0e3fbb5ea861b6fc Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 6 Oct 2025 12:46:45 +0200 Subject: [PATCH 4/8] Add cleanup for global variables in error handling tests --- .../Public/Get-SqlDscConfigurationOption.Tests.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 b/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 index 1a3292080f..fd87d52910 100644 --- a/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 @@ -407,6 +407,19 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { $completions[1].CompletionText | Should -Be "'max degree of parallelism'" } + AfterAll { + # Clean up global variables created in error handling tests + if (Get-Variable -Name 'BadTestServerObject' -Scope Global -ErrorAction SilentlyContinue) + { + Remove-Variable -Name 'BadTestServerObject' -Scope Global -Force + } + + if (Get-Variable -Name 'InvalidTestServerObject' -Scope Global -ErrorAction SilentlyContinue) + { + Remove-Variable -Name 'InvalidTestServerObject' -Scope Global -Force + } + } + It 'Should handle tab completion errors gracefully' { # Create a server object that will cause an error $badServer = [Microsoft.SqlServer.Management.Smo.Server]::CreateTypeInstance() From 07fafcc02bb5ac8d290cd560a93f1ad2539e65c8 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 6 Oct 2025 15:27:59 +0200 Subject: [PATCH 5/8] Add cleanup for Windows group login in New-SqlDscLogin integration tests --- .../Commands/New-SqlDscLogin.Integration.Tests.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index f1f5b1519f..5a0521f3d1 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -147,6 +147,14 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } Context 'When creating a Windows group login' { + AfterEach { + # Clean up Windows group login + if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName) + { + $script:serverObject.Logins[$script:testWindowsGroupName].Drop() + } + } + It 'Should create a Windows group login without error' { $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName -WindowsGroup -Force From 4478d5a2c13bf3ec5a28cd574436f47fb4332057 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 6 Oct 2025 15:29:51 +0200 Subject: [PATCH 6/8] Refactor New-SqlDscLogin tests to use a consistent variable for test login name --- .../New-SqlDscLogin.Integration.Tests.ps1 | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index 5a0521f3d1..a7dd737181 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -76,20 +76,28 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a SQL Server login without error' { - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testSqlLoginName -SqlLogin -SecurePassword $script:testPassword -Force + $script:testLoginName = $script:testSqlLoginName + + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force } It 'Should verify the SQL Server login was created' { - Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testSqlLoginName | Should -BeTrue + $script:testLoginName = $script:testSqlLoginName + + Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName | Should -BeTrue } It 'Should verify the login type is SqlLogin' { - $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testSqlLoginName + $script:testLoginName = $script:testSqlLoginName + + $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName $loginObject.LoginType | Should -Be 'SqlLogin' } It 'Should verify the default database is set correctly' { - $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testSqlLoginName + $script:testLoginName = $script:testSqlLoginName + + $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName $loginObject.DefaultDatabase | Should -Be 'master' } @@ -122,7 +130,9 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should throw an error when trying to create a login that already exists' { - { New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testSqlLoginName -SqlLogin -SecurePassword $script:testPassword -Force } | Should -Throw + $script:testLoginName = $script:testSqlLoginName + + { New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force } | Should -Throw } } From fef26f055ddcab2e2fa66f631e4bf751a06123d7 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 6 Oct 2025 19:25:04 +0200 Subject: [PATCH 7/8] Enhance New-SqlDscLogin tests to verify login creation and properties in a single test case --- .../New-SqlDscLogin.Integration.Tests.ps1 | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index a7dd737181..fde57c4f74 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -75,29 +75,19 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } } - It 'Should create a SQL Server login without error' { + It 'Should create a SQL Server login and verify it was created with correct properties' { $script:testLoginName = $script:testSqlLoginName $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force - } - - It 'Should verify the SQL Server login was created' { - $script:testLoginName = $script:testSqlLoginName + # Verify the login was created Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName | Should -BeTrue - } - - It 'Should verify the login type is SqlLogin' { - $script:testLoginName = $script:testSqlLoginName + # Verify the login type $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName $loginObject.LoginType | Should -Be 'SqlLogin' - } - - It 'Should verify the default database is set correctly' { - $script:testLoginName = $script:testSqlLoginName - $loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName + # Verify the default database $loginObject.DefaultDatabase | Should -Be 'master' } @@ -132,6 +122,10 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should throw an error when trying to create a login that already exists' { $script:testLoginName = $script:testSqlLoginName + # First create the login + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force + + # Then try to create it again, which should throw { New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force } | Should -Throw } } From 82e1e4390f4e71bc73f962a1064390141ca3d868 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 7 Oct 2025 12:55:03 +0200 Subject: [PATCH 8/8] Refactor New-SqlDscLogin tests to handle persistent logins and improve cleanup logic --- .../New-SqlDscLogin.Integration.Tests.ps1 | 27 ++++++++++--------- tests/Integration/Commands/README.md | 22 +++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index fde57c4f74..877d2d00e0 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -65,11 +65,12 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', BeforeEach { $script:testLoginName = $null + $script:isPersistentLogin = $false } AfterEach { - # Clean up any login created in the test - if ($script:testLoginName -and (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName)) + # Clean up any login created in the test (but not persistent logins) + if ($script:testLoginName -and -not $script:isPersistentLogin -and (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName)) { $script:serverObject.Logins[$script:testLoginName].Drop() } @@ -77,8 +78,13 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create a SQL Server login and verify it was created with correct properties' { $script:testLoginName = $script:testSqlLoginName + $script:isPersistentLogin = $true # This is a persistent login for other tests - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force + # Only create if it doesn't already exist + if (-not (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName)) + { + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force + } # Verify the login was created Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName | Should -BeTrue @@ -120,7 +126,7 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should throw an error when trying to create a login that already exists' { - $script:testLoginName = $script:testSqlLoginName + $script:testLoginName = 'IntegrationTestDuplicate' # First create the login $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -SqlLogin -SecurePassword $script:testPassword -Force @@ -151,16 +157,13 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } Context 'When creating a Windows group login' { - AfterEach { - # Clean up Windows group login - if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName) + It 'Should create a Windows group login without error' { + # This is a persistent login for other tests + # Only create if it doesn't already exist + if (-not (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName)) { - $script:serverObject.Logins[$script:testWindowsGroupName].Drop() + $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName -WindowsGroup -Force } - } - - It 'Should create a Windows group login without error' { - $null = New-SqlDscLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName -WindowsGroup -Force Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testWindowsGroupName | Should -BeTrue diff --git a/tests/Integration/Commands/README.md b/tests/Integration/Commands/README.md index 3c8e88081f..ba1a27f433 100644 --- a/tests/Integration/Commands/README.md +++ b/tests/Integration/Commands/README.md @@ -63,23 +63,23 @@ Get-SqlDscTraceFlag | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTE Set-SqlDscConfigurationOption | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Set-SqlDscStartupParameter | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Set-SqlDscTraceFlag | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Disable-SqlDscLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Enable-SqlDscLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Disable-SqlDscLogin | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Enable-SqlDscLogin | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Enable-SqlDscAudit | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Test-SqlDscIsLogin | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Test-SqlDscIsLoginEnabled | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Test-SqlDscIsLogin | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Test-SqlDscIsLoginEnabled | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - New-SqlDscRole | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | SqlDscIntegrationTestRole_Persistent role Get-SqlDscRole | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Get-SqlDscStartupParameter | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Test-SqlDscIsRole | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Test-SqlDscIsDatabasePrincipal | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test database and database principals -Grant-SqlDscServerPermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Grants CreateEndpoint permission to role -Get-SqlDscServerPermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Set-SqlDscServerPermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Grant-SqlDscServerPermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Grants CreateEndpoint permission to role +Get-SqlDscServerPermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Set-SqlDscServerPermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - ConvertFrom-SqlDscServerPermission | 2 | 0 (Prerequisites) | - | - -Test-SqlDscServerPermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Deny-SqlDscServerPermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Denies AlterTrace permission to login (persistent) -Revoke-SqlDscServerPermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Test-SqlDscServerPermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Deny-SqlDscServerPermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Denies AlterTrace permission to login (persistent) +Revoke-SqlDscServerPermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Get-SqlDscDatabase | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - ConvertFrom-SqlDscDatabasePermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - New-SqlDscDatabase | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test databases @@ -88,7 +88,7 @@ Test-SqlDscDatabase | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTE Get-SqlDscDatabasePermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test database, Test user Invoke-SqlDscQuery | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test database and table ConvertTo-SqlDscDatabasePermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - -Set-SqlDscDatabasePermission | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - +Set-SqlDscDatabasePermission | 2 | 2 (New-SqlDscLogin), 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - Get-SqlDscAgentAlert | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | - New-SqlDscAgentAlert | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test alerts New-SqlDscAudit | 2 | 1 (Install-SqlDscServer), 0 (Prerequisites) | DSCSQLTEST | Test audits