From e6fa1457867d637d2ad50bda00d04c13da3dfa74 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 11:56:19 +0200 Subject: [PATCH 1/9] Refactor integration tests to optimize SQL Server service management --- CHANGELOG.md | 2 ++ ...t-SqlDscAgentOperator.Integration.Tests.ps1 | 6 ++---- .../Assert-SqlDscLogin.Integration.Tests.ps1 | 6 ++---- ...-SqlDscDatabaseEngine.Integration.Tests.ps1 | 6 ++---- ...DscDatabasePermission.Integration.Tests.ps1 | 6 ++---- ...qlDscServerPermission.Integration.Tests.ps1 | 6 ++---- ...e-SqlDscAgentOperator.Integration.Tests.ps1 | 3 +-- .../Disable-SqlDscAudit.Integration.Tests.ps1 | 6 ++---- .../Disable-SqlDscLogin.Integration.Tests.ps1 | 6 ++---- ...e-SqlDscAgentOperator.Integration.Tests.ps1 | 3 +-- .../Enable-SqlDscLogin.Integration.Tests.ps1 | 6 ++---- .../Get-SqlDscAgentAlert.Integration.Tests.ps1 | 6 ++---- ...t-SqlDscAgentOperator.Integration.Tests.ps1 | 6 ++---- ...scConfigurationOption.Integration.Tests.ps1 | 6 ++---- .../Get-SqlDscDatabase.Integration.Tests.ps1 | 6 ++---- .../Get-SqlDscLogin.Integration.Tests.ps1 | 6 ++---- ...SqlDscManagedComputer.Integration.Tests.ps1 | 14 ++------------ ...nagedComputerInstance.Integration.Tests.ps1 | 6 ++---- ...anagedComputerService.Integration.Tests.ps1 | 6 ++---- .../Get-SqlDscRole.Integration.Tests.ps1 | 6 ++---- ...qlDscServerPermission.Integration.Tests.ps1 | 6 ++---- ...-SqlDscServerProtocol.Integration.Tests.ps1 | 6 ++---- ...qlDscServerPermission.Integration.Tests.ps1 | 6 ++---- .../Install-SqlDscServer.Integration.Tests.ps1 | 18 +++++++----------- .../New-SqlDscAgentAlert.Integration.Tests.ps1 | 6 ++---- ...w-SqlDscAgentOperator.Integration.Tests.ps1 | 6 ++---- .../New-SqlDscAudit.Integration.Tests.ps1 | 6 ++---- .../New-SqlDscDatabase.Integration.Tests.ps1 | 6 ++---- .../New-SqlDscLogin.Integration.Tests.ps1 | 6 ++---- .../New-SqlDscRole.Integration.Tests.ps1 | 6 ++---- ...move-SqlDscAgentAlert.Integration.Tests.ps1 | 6 ++---- ...e-SqlDscAgentOperator.Integration.Tests.ps1 | 3 +-- .../Remove-SqlDscAudit.Integration.Tests.ps1 | 6 ++---- ...Remove-SqlDscDatabase.Integration.Tests.ps1 | 6 ++---- .../Remove-SqlDscLogin.Integration.Tests.ps1 | 6 ++---- .../Remove-SqlDscRole.Integration.Tests.ps1 | 6 ++---- ...qlDscServerPermission.Integration.Tests.ps1 | 6 ++---- .../Set-SqlDscAgentAlert.Integration.Tests.ps1 | 6 ++---- ...t-SqlDscAgentOperator.Integration.Tests.ps1 | 3 +-- .../Set-SqlDscAudit.Integration.Tests.ps1 | 6 ++---- ...scConfigurationOption.Integration.Tests.ps1 | 6 ++---- .../Set-SqlDscDatabase.Integration.Tests.ps1 | 6 ++---- ...SqlDscDatabaseDefault.Integration.Tests.ps1 | 3 +-- ...DscDatabasePermission.Integration.Tests.ps1 | 6 ++---- ...qlDscServerPermission.Integration.Tests.ps1 | 6 ++---- ...qlDscStartupParameter.Integration.Tests.ps1 | 6 ++---- .../Set-SqlDscTraceFlag.Integration.Tests.ps1 | 6 ++---- ...DscAgentAlertProperty.Integration.Tests.ps1 | 6 ++---- ...scConfigurationOption.Integration.Tests.ps1 | 6 ++---- .../Test-SqlDscDatabase.Integration.Tests.ps1 | 6 ++---- ...st-SqlDscIsAgentAlert.Integration.Tests.ps1 | 6 ++---- ...SqlDscIsAgentOperator.Integration.Tests.ps1 | 3 +-- .../Test-SqlDscIsLogin.Integration.Tests.ps1 | 6 ++---- ...-SqlDscIsLoginEnabled.Integration.Tests.ps1 | 6 ++---- .../Test-SqlDscIsRole.Integration.Tests.ps1 | 6 ++---- ...qlDscServerPermission.Integration.Tests.ps1 | 6 ++---- ...ninstall-SqlDscServer.Integration.Tests.ps1 | 3 +-- 57 files changed, 112 insertions(+), 225 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3eb5e033ce..b8a017804d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -223,6 +223,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Optimized integration test performance by leaving the DSCSQLTEST service running + for subsequent tests, significantly improving CI build times. - Improved code quality by ensuring all function invocations in the private and public functions use named parameters instead of positional parameters. - SqlServerDsc diff --git a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 index 2454fdf707..d1556fbbdf 100644 --- a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -64,8 +63,7 @@ Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When operator exists' { diff --git a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 index 88e35ae40a..fd4c0671ee 100644 --- a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 @@ -31,16 +31,14 @@ BeforeAll { Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:instanceName = 'DSCSQLTEST' $script:computerName = Get-ComputerName } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When connecting to SQL Server instance' { diff --git a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 index 5a878651f8..4f1ed17d1a 100644 --- a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -85,13 +85,11 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integrati Context 'When connecting to a named instance' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should have the named instance SQL Server service started' { diff --git a/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 index 940dad3989..a595ab77da 100644 --- a/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -47,8 +46,7 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When converting empty collection of DatabasePermissionInfo' { diff --git a/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 index d659811579..c92ba128e9 100644 --- a/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -51,8 +50,7 @@ Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integratio AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When denying server permissions to login' { diff --git a/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 index 4e94a8362c..fd7de096cb 100644 --- a/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 index 6a78ce3f92..72f5abf75c 100644 --- a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -48,8 +47,7 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When disabling an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 index ea47f91d31..d823f522df 100644 --- a/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -50,8 +49,7 @@ Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When disabling a login using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 index 36c37da923..efb564ca1d 100644 --- a/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 index e834d5776e..014f88ee1d 100644 --- a/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -50,8 +49,7 @@ Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When enabling a login using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 index c9172260fe..eea7929504 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Get-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -76,8 +75,7 @@ END # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should get all alerts' { diff --git a/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 index 837f1c593d..46209da05c 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Get-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -66,8 +65,7 @@ Describe 'Get-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should get all operators' { diff --git a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 index 965e390f03..81c2baa187 100644 --- a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -47,8 +46,7 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When getting all configuration options' { diff --git a/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 index 52ed64dba9..7ce91cde75 100644 --- a/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Get-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -48,8 +47,7 @@ Describe 'Get-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When getting all SQL Server databases' { diff --git a/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 index f835934ae2..e2b4460e33 100644 --- a/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Get-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -45,8 +44,7 @@ Describe 'Get-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 index 74a2de8c5c..eedcf632bf 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 @@ -34,23 +34,13 @@ Describe 'Get-SqlDscManagedComputer' -Tag @('Integration_SQL2017', 'Integration_ BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - # Note: On Windows CI environment, this would start the SQL Server service - if (Get-Command -Name 'Start-Service' -ErrorAction 'SilentlyContinue') - { - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - } + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockServerName = Get-ComputerName } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - # Note: On Windows CI environment, this would stop the SQL Server service - if (Get-Command -Name 'Stop-Service' -ErrorAction 'SilentlyContinue') - { - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - } + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When using default parameters' { diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 index b755ccfc5e..5508b3c6ff 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 @@ -34,16 +34,14 @@ Describe 'Get-SqlDscManagedComputerInstance' -Tag @('Integration_SQL2017', 'Inte BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When using parameter set ByServerName' { diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 index b8a6bede72..95e3cd3d0b 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 @@ -34,16 +34,14 @@ Describe 'Get-SqlDscManagedComputerService' -Tag @('Integration_SQL2017', 'Integ BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When using parameter set ByServerName' { diff --git a/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 index c24529a9ba..38138dfac0 100644 --- a/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Get-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -51,8 +50,7 @@ Describe 'Get-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', ' AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When getting all SQL Server roles' { diff --git a/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 index c1990a51ac..906f382076 100644 --- a/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -47,8 +46,7 @@ Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When connecting to SQL Server instance' { diff --git a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 index 20bee68814..f8da6788c0 100644 --- a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 @@ -34,16 +34,14 @@ Describe 'Get-SqlDscServerProtocol' -Tag @('Integration_SQL2017', 'Integration_S BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When using parameter set ByServerName' { diff --git a/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 index 733b8ca238..d9bcee1e93 100644 --- a/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Grant-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -51,8 +50,7 @@ Describe 'Grant-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integrati AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When granting server permissions to login' { diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index 71482d7583..c12ac317c8 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -302,18 +302,14 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL20 $sqlServerService.Status | Should -Be 'Running' } - It 'Should stop the named instance SQL Server service' { - # Stop the named instance SQL Server service to save memory on the build worker. - $stopServiceResult = Stop-Service -Name 'MSSQL$DSCSQLTEST' -Force -PassThru -Verbose -ErrorAction 'Stop' + It 'Should leave the named instance SQL Server service running for subsequent tests' { + # Leave the named instance SQL Server service running to avoid start/stop overhead in subsequent tests. + # The service will be stopped later in the test pipeline after all tests that require it have completed. + $sqlServerService = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' - ( - <# - Filter services. This will also have stopped the dependent - service 'SQL Server Agent (DSCSQLTEST)'. - #> - $stopServiceResult | - Where-Object -FilterScript { $_.Name -eq 'MSSQL$DSCSQLTEST' } - ).Status | Should -Be 'Stopped' + $sqlServerService.Status | Should -Be 'Running' + + Write-Verbose -Message 'MSSQL$DSCSQLTEST service left running for subsequent integration tests to improve performance' -Verbose } } diff --git a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 index d3a91335b1..a443b38364 100644 --- a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'New-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -65,8 +64,7 @@ Describe 'New-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should create alert with severity' { diff --git a/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 index bc205726a4..2d864ec40e 100644 --- a/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'New-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -65,8 +64,7 @@ Describe 'New-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should create the persistent operator for other tests to use' { diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 95745c26b5..537ca86f77 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -77,8 +76,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', Remove-Item -Path $script:testAuditPath -Recurse -Force -ErrorAction 'SilentlyContinue' } - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When creating a new application log audit' { diff --git a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 index a9afedf4da..bdd85a829d 100644 --- a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -65,8 +64,7 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When creating a new database' { diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index f96973d15f..e6850cde6b 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:instanceName = 'DSCSQLTEST' $script:computerName = Get-ComputerName @@ -44,8 +43,7 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } AfterAll { - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When connecting to SQL Server instance' { diff --git a/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 index cfe2f388b5..6820eecb9d 100644 --- a/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'New-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -69,8 +68,7 @@ Describe 'New-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', ' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When creating a new SQL Server role' { diff --git a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 index 2a9e998f1b..a1451fcf2e 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -51,8 +50,7 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing by ServerObject' { diff --git a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 index 389cdec5e0..318dd0d0bf 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Remove-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 index 17b0c6fa7d..29fc981503 100644 --- a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -48,8 +47,7 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 index 4f564a6983..5f68acc7b1 100644 --- a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -48,8 +47,7 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing a database using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 index ad6d0f669f..386d5a170e 100644 --- a/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Remove-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -47,8 +46,7 @@ Describe 'Remove-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing a SQL Server login by ServerObject and Name' { diff --git a/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 index 6b4ebdc954..7d6ebfc2e5 100644 --- a/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Remove-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -69,8 +68,7 @@ Describe 'Remove-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing a SQL Server role by name' { diff --git a/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 index 7dc5edb629..dae6d8e858 100644 --- a/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Revoke-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -51,8 +50,7 @@ Describe 'Revoke-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integrat AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When revoking server permissions from login' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 index 712d1b8183..8a213c83a8 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Set-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -55,8 +54,7 @@ Describe 'Set-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should update alert severity using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 index 7664b668a3..17151838a5 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Set-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 index 3c9d43b4cb..7d67ca0c3f 100644 --- a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -48,8 +47,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When modifying an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 index 516ad49f8b..91589b9692 100644 --- a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -56,8 +55,7 @@ Describe 'Set-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting Agent XPs configuration option' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 index 2363c2ef05..f4180e61bb 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -69,8 +68,7 @@ Describe 'Set-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting database properties using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 index 34cab2cf13..aef686b3da 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscDatabaseDefault' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName diff --git a/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 index 3b1880f76a..778c3df22c 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -82,8 +81,7 @@ END Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting database permissions with Grant state' { diff --git a/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 index 9a40471da9..864d21b4bb 100644 --- a/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -65,8 +64,7 @@ Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting server permissions to Grant state for login' { diff --git a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 index 9e5f54eef1..deb45e446a 100644 --- a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName @@ -61,8 +60,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration } } - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When using parameter set ByServerName' { diff --git a/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 index 7bcecad821..9ffd0914b1 100644 --- a/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Set-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName @@ -53,8 +52,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 Set-SqlDscTraceFlag -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -TraceFlag @() -Force -ErrorAction 'SilentlyContinue' } - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting trace flags' { diff --git a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 index a61c2f9439..c033bfc41b 100644 --- a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -58,8 +57,7 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When checking severity' { diff --git a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 index b811d8692e..1e1ba92678 100644 --- a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Test-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -56,8 +55,7 @@ Describe 'Test-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integra Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing Agent XPs configuration option' { diff --git a/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 index c5cc235896..c876debf50 100644 --- a/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Test-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -48,8 +47,7 @@ Describe 'Test-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject -ErrorAction 'Stop' - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing database presence' { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 index be26d5723e..0fd49d4529 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -58,8 +57,7 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When checking existence only' { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 index e4fa394b8d..2bd7189c1f 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,7 @@ AfterAll { Describe 'Test-SqlDscIsAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 index 3ad1ea4c18..2f6b8bbc20 100644 --- a/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Test-SqlDscIsLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -50,8 +49,7 @@ Describe 'Test-SqlDscIsLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing login existence using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 index 83987ec851..ab5e4c1f22 100644 --- a/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Test-SqlDscIsLoginEnabled' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -50,8 +49,7 @@ Describe 'Test-SqlDscIsLoginEnabled' -Tag @('Integration_SQL2017', 'Integration_ AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing login state using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 index acd7a3bd70..c8c3e7d22e 100644 --- a/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Test-SqlDscIsRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -50,8 +49,7 @@ Describe 'Test-SqlDscIsRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019' AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing for existing system roles' { diff --git a/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 index 00cf5b1e66..bf0c5d37db 100644 --- a/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,7 @@ BeforeAll { Describe 'Test-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization $script:mockInstanceName = 'DSCSQLTEST' @@ -51,8 +50,7 @@ Describe 'Test-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integratio AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing server permissions for login' { diff --git a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 index 990cd08a71..87b2fd37dd 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 @@ -34,8 +34,7 @@ Describe 'Uninstall-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' + # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization } It 'Should have the named instance SQL Server service started' { From 2a5d1ce3f51072926dec27cf1d85f605e905175f Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 12:44:07 +0200 Subject: [PATCH 2/9] Refactor integration tests to remove unnecessary comments about SQL Server service state - Removed comments indicating that the SQL Server service is already running for performance optimization from multiple integration test files. - Cleaned up AfterAll sections to enhance readability and maintainability of the test scripts. --- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 4 ---- .../Assert-SqlDscLogin.Integration.Tests.ps1 | 6 ----- ...scDatabasePermission.Integration.Tests.ps1 | 23 ++++++++----------- ...lDscServerPermission.Integration.Tests.ps1 | 4 ---- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 5 ---- .../Disable-SqlDscAudit.Integration.Tests.ps1 | 6 +---- .../Disable-SqlDscLogin.Integration.Tests.ps1 | 4 ---- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 5 ---- .../Enable-SqlDscLogin.Integration.Tests.ps1 | 4 ---- ...Get-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 4 ---- ...cConfigurationOption.Integration.Tests.ps1 | 4 ---- .../Get-SqlDscDatabase.Integration.Tests.ps1 | 4 ---- .../Get-SqlDscLogin.Integration.Tests.ps1 | 7 ------ ...qlDscManagedComputer.Integration.Tests.ps1 | 4 ---- ...agedComputerInstance.Integration.Tests.ps1 | 4 ---- ...nagedComputerService.Integration.Tests.ps1 | 4 ---- .../Get-SqlDscRole.Integration.Tests.ps1 | 4 ---- ...lDscServerPermission.Integration.Tests.ps1 | 4 ---- ...SqlDscServerProtocol.Integration.Tests.ps1 | 4 ---- ...lDscServerPermission.Integration.Tests.ps1 | 4 ---- ...New-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 4 ---- .../New-SqlDscAudit.Integration.Tests.ps1 | 12 ++++------ .../New-SqlDscDatabase.Integration.Tests.ps1 | 4 ---- .../New-SqlDscLogin.Integration.Tests.ps1 | 6 ----- .../New-SqlDscRole.Integration.Tests.ps1 | 4 ---- ...ove-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 5 ---- .../Remove-SqlDscAudit.Integration.Tests.ps1 | 4 ---- ...emove-SqlDscDatabase.Integration.Tests.ps1 | 4 ---- .../Remove-SqlDscLogin.Integration.Tests.ps1 | 4 ---- .../Remove-SqlDscRole.Integration.Tests.ps1 | 4 ---- ...lDscServerPermission.Integration.Tests.ps1 | 4 ---- ...Set-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- ...-SqlDscAgentOperator.Integration.Tests.ps1 | 5 ---- .../Set-SqlDscAudit.Integration.Tests.ps1 | 4 ---- ...cConfigurationOption.Integration.Tests.ps1 | 4 ---- .../Set-SqlDscDatabase.Integration.Tests.ps1 | 4 ---- ...qlDscDatabaseDefault.Integration.Tests.ps1 | 5 ---- ...scDatabasePermission.Integration.Tests.ps1 | 10 +++----- ...lDscServerPermission.Integration.Tests.ps1 | 9 ++------ ...lDscStartupParameter.Integration.Tests.ps1 | 4 +--- .../Set-SqlDscTraceFlag.Integration.Tests.ps1 | 4 ---- ...scAgentAlertProperty.Integration.Tests.ps1 | 2 -- ...cConfigurationOption.Integration.Tests.ps1 | 4 ---- .../Test-SqlDscDatabase.Integration.Tests.ps1 | 4 ---- ...t-SqlDscIsAgentAlert.Integration.Tests.ps1 | 2 -- ...qlDscIsAgentOperator.Integration.Tests.ps1 | 5 ---- .../Test-SqlDscIsLogin.Integration.Tests.ps1 | 6 +---- ...SqlDscIsLoginEnabled.Integration.Tests.ps1 | 4 ---- .../Test-SqlDscIsRole.Integration.Tests.ps1 | 4 ---- ...lDscServerPermission.Integration.Tests.ps1 | 4 ---- 53 files changed, 21 insertions(+), 234 deletions(-) diff --git a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 index d1556fbbdf..d55ac7c122 100644 --- a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -62,8 +60,6 @@ Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When operator exists' { diff --git a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 index fd4c0671ee..1db9150763 100644 --- a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 @@ -31,16 +31,10 @@ BeforeAll { Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:instanceName = 'DSCSQLTEST' $script:computerName = Get-ComputerName } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - Context 'When connecting to SQL Server instance' { BeforeAll { $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. diff --git a/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 index a595ab77da..57264ee7af 100644 --- a/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/ConvertTo-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' @@ -45,14 +43,11 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } - Context 'When converting empty collection of DatabasePermissionInfo' { It 'Should return empty array for empty DatabasePermissionInfo collection' { $emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @() - + $result = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $emptyCollection $result | Should -BeNullOrEmpty @@ -60,7 +55,7 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int It 'Should accept empty collection through pipeline' { $emptyCollection = [Microsoft.SqlServer.Management.Smo.DatabasePermissionInfo[]] @() - + $result = $emptyCollection | ConvertTo-SqlDscDatabasePermission $result | Should -BeNullOrEmpty @@ -78,12 +73,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int # Validate the result structure $result | Should -Not -BeNullOrEmpty - + # Each result should have State and Permission properties foreach ($permission in $result) { $permission.State | Should -Not -BeNullOrEmpty $permission.Permission | Should -Not -BeNullOrEmpty - + # Validate that permission state is one of the expected values $permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant') } @@ -100,12 +95,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int # Validate the result structure $result | Should -Not -BeNullOrEmpty - + # Each result should have State and Permission properties foreach ($permission in $result) { $permission.State | Should -Not -BeNullOrEmpty $permission.Permission | Should -Not -BeNullOrEmpty - + # Validate that permission state is one of the expected values $permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant') } @@ -124,12 +119,12 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int # Validate the result structure $result | Should -Not -BeNullOrEmpty - + # Each result should have State and Permission properties foreach ($permission in $result) { $permission.State | Should -Not -BeNullOrEmpty $permission.Permission | Should -Not -BeNullOrEmpty - + # Validate that permission state is one of the expected values $permission.State | Should -BeIn @('Grant', 'Deny', 'GrantWithGrant') } @@ -149,7 +144,7 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Int if ($result) { # Validate that permissions are properly grouped by state $uniqueStates = $result.State | Sort-Object -Unique - + foreach ($state in $uniqueStates) { $permissionsForState = $result | Where-Object { $_.State -eq $state } $permissionsForState | Should -HaveCount 1 diff --git a/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 index c92ba128e9..6e84e499a8 100644 --- a/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Deny-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -49,8 +47,6 @@ Describe 'Deny-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integratio AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When denying server permissions to login' { diff --git a/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 index fd7de096cb..ce69ec373c 100644 --- a/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) @@ -60,9 +58,6 @@ Describe 'Disable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_ Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stopping the named instance SQL Server service after running tests. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When disabling an existing agent operator' { diff --git a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 index 72f5abf75c..87ee6ac36d 100644 --- a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -46,8 +44,6 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When disabling an audit using ServerObject parameter set' { @@ -204,7 +200,7 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 'SqlDscTestMultiDisable1_' + (Get-Random), 'SqlDscTestMultiDisable2_' + (Get-Random) ) - + foreach ($auditName in $script:testAuditNames) { $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop diff --git a/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 index d823f522df..c66194719c 100644 --- a/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -48,8 +46,6 @@ Describe 'Disable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When disabling a login using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 index efb564ca1d..e750e50ff3 100644 --- a/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) @@ -60,9 +58,6 @@ Describe 'Enable-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stopping the named instance SQL Server service after running tests. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When enabling an existing agent operator' { diff --git a/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 index 014f88ee1d..868600301e 100644 --- a/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -48,8 +46,6 @@ Describe 'Enable-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When enabling a login using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 index eea7929504..0fab0df64b 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 @@ -74,8 +74,6 @@ END # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should get all alerts' { diff --git a/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 index 46209da05c..37f7b5903d 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Get-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -64,8 +62,6 @@ Describe 'Get-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should get all operators' { diff --git a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 index 81c2baa187..cabb199c3e 100644 --- a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -45,8 +43,6 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When getting all configuration options' { diff --git a/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 index 7ce91cde75..01e619cdb2 100644 --- a/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Get-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -46,8 +44,6 @@ Describe 'Get-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When getting all SQL Server databases' { diff --git a/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 index e2b4460e33..24a8177b40 100644 --- a/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Get-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -43,11 +41,6 @@ Describe 'Get-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - - Context 'When getting all SQL Server logins' { It 'Should return an array of Login objects' { $result = Get-SqlDscLogin -ServerObject $script:serverObject diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 index eedcf632bf..3415722edd 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 @@ -39,10 +39,6 @@ Describe 'Get-SqlDscManagedComputer' -Tag @('Integration_SQL2017', 'Integration_ $script:mockServerName = Get-ComputerName } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - Context 'When using default parameters' { It 'Should return the managed computer object for the local computer' { $result = Get-SqlDscManagedComputer -ErrorAction 'Stop' diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 index 5508b3c6ff..4bb3662ecd 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 @@ -40,10 +40,6 @@ Describe 'Get-SqlDscManagedComputerInstance' -Tag @('Integration_SQL2017', 'Inte $script:mockServerName = Get-ComputerName } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - Context 'When using parameter set ByServerName' { Context 'When getting a specific instance' { It 'Should return the correct server instance' { diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 index 95e3cd3d0b..b124dc3316 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 @@ -40,10 +40,6 @@ Describe 'Get-SqlDscManagedComputerService' -Tag @('Integration_SQL2017', 'Integ $script:mockServerName = Get-ComputerName } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - Context 'When using parameter set ByServerName' { Context 'When getting all services on the current managed computer' { It 'Should return all available services' { diff --git a/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 index 38138dfac0..0bc417f2b4 100644 --- a/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscRole.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Get-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -49,8 +47,6 @@ Describe 'Get-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', ' AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When getting all SQL Server roles' { diff --git a/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 index 906f382076..f15bbb35d7 100644 --- a/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -45,8 +43,6 @@ Describe 'Get-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When connecting to SQL Server instance' { diff --git a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 index f8da6788c0..0b383940c6 100644 --- a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 @@ -40,10 +40,6 @@ Describe 'Get-SqlDscServerProtocol' -Tag @('Integration_SQL2017', 'Integration_S $script:mockServerName = Get-ComputerName } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - Context 'When using parameter set ByServerName' { Context 'When getting a specific protocol' { It 'Should return TcpIp protocol information' { diff --git a/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 index d9bcee1e93..657ebff9ab 100644 --- a/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Grant-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Grant-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -49,8 +47,6 @@ Describe 'Grant-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integrati AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When granting server permissions to login' { diff --git a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 index a443b38364..d8aca04ac1 100644 --- a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 @@ -63,8 +63,6 @@ Describe 'New-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should create alert with severity' { diff --git a/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 index 2d864ec40e..2c953c5446 100644 --- a/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'New-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force @@ -63,8 +61,6 @@ Describe 'New-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should create the persistent operator for other tests to use' { diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 537ca86f77..a612d5ab33 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -53,9 +51,9 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', AfterAll { # Clean up any test audits that might remain - $testAudits = Get-SqlDscAudit -ServerObject $script:serverObject -ErrorAction 'SilentlyContinue' | + $testAudits = Get-SqlDscAudit -ServerObject $script:serverObject -ErrorAction 'SilentlyContinue' | Where-Object { $_.Name -like 'SqlDscTestAudit*' } - + foreach ($audit in $testAudits) { try @@ -75,8 +73,6 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', { Remove-Item -Path $script:testAuditPath -Recurse -Force -ErrorAction 'SilentlyContinue' } - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When creating a new application log audit' { @@ -110,7 +106,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create a security log audit successfully' { $securityLogAuditName = 'SqlDscTestAudit_SecLog_' + (Get-Random) - + try { $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $securityLogAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop @@ -339,7 +335,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should throw error when path does not exist for file audit' { $nonExistentPath = Join-Path -Path $env:TEMP -ChildPath 'NonExistentPath' - + { New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $nonExistentPath -Force -ErrorAction Stop } | Should -Throw } diff --git a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 index bdd85a829d..3083c90b6f 100644 --- a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -63,8 +61,6 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When creating a new database' { diff --git a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 index e6850cde6b..df0473a833 100644 --- a/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:instanceName = 'DSCSQLTEST' $script:computerName = Get-ComputerName @@ -42,10 +40,6 @@ Describe 'New-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:testWindowsGroupName = '{0}\SqlIntegrationTestGroup' -f $script:computerName } - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - Context 'When connecting to SQL Server instance' { BeforeAll { $sqlAdministratorUserName = 'SqlAdmin' diff --git a/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 index 6820eecb9d..61f454bc9b 100644 --- a/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscRole.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'New-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -67,8 +65,6 @@ Describe 'New-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', ' } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When creating a new SQL Server role' { diff --git a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 index a1451fcf2e..b92c5282d7 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 @@ -49,8 +49,6 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ AfterAll { # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing by ServerObject' { diff --git a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 index 318dd0d0bf..e7b0e0127d 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Remove-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) @@ -54,9 +52,6 @@ Describe 'Remove-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stopping the named instance SQL Server service after running tests. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When removing test agent operators' { diff --git a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 index 29fc981503..5cffc100c2 100644 --- a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -46,8 +44,6 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 index 5f68acc7b1..3302c61c87 100644 --- a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -46,8 +44,6 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing a database using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 index 386d5a170e..6f27e80512 100644 --- a/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Remove-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -45,8 +43,6 @@ Describe 'Remove-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing a SQL Server login by ServerObject and Name' { diff --git a/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 index 7d6ebfc2e5..83f107a413 100644 --- a/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscRole.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Remove-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -67,8 +65,6 @@ Describe 'Remove-SqlDscRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019' } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When removing a SQL Server role by name' { diff --git a/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 index dae6d8e858..192ea8ab55 100644 --- a/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Revoke-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Revoke-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -49,8 +47,6 @@ Describe 'Revoke-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integrat AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When revoking server permissions from login' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 index 8a213c83a8..e5029d32b5 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 @@ -53,8 +53,6 @@ Describe 'Set-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } It 'Should update alert severity using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 index 17151838a5..32c48b57e8 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Set-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $mockSqlAdministratorCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAdministratorUserName, $mockSqlAdministratorPassword @@ -60,9 +58,6 @@ Describe 'Set-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2 Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value 0 -Force -Verbose -ErrorAction 'Stop' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stopping the named instance SQL Server service after running tests. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When updating an existing agent operator' { diff --git a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 index 7d67ca0c3f..8ce4488917 100644 --- a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -46,8 +44,6 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When modifying an audit using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 index 91589b9692..492683fa68 100644 --- a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -54,8 +52,6 @@ Describe 'Set-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting Agent XPs configuration option' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 index f4180e61bb..64b8b67e3f 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -67,8 +65,6 @@ Describe 'Set-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting database properties using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 index aef686b3da..b53bc56cfe 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscDatabaseDefault' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -65,9 +63,6 @@ Describe 'Set-SqlDscDatabaseDefault' -Tag @('Integration_SQL2017', 'Integration_ AfterAll { # Disconnect from the database engine. Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stopping the named instance SQL Server service after running tests. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When using the DatabaseObject parameter' { diff --git a/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 index 778c3df22c..13345ff84e 100644 --- a/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscDatabasePermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -44,14 +42,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag @('Integration_SQL2017', 'Integrati # Use existing persistent test database from New-SqlDscDatabase integration tests $script:testDatabaseName = 'SqlDscIntegrationTestDatabase' - + # Use existing persistent principals created by earlier integration tests $script:testLoginName = 'IntegrationTestSqlLogin' $script:testRoleName = 'SqlDscIntegrationTestRole_Persistent' # Ensure the test database exists $existingDatabase = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'SilentlyContinue' - + if (-not $existingDatabase) { $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' @@ -80,8 +78,6 @@ END $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $sqlQuery -Force -ErrorAction 'SilentlyContinue' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting database permissions with Grant state' { @@ -126,7 +122,7 @@ END $permissions = Get-SqlDscDatabasePermission -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Name $script:testLoginName -ErrorAction 'Stop' $permissions | Should -Not -BeNullOrEmpty - + $connectPermission = $permissions | Where-Object { $_.PermissionState -eq 'Grant' -and $_.PermissionType.Connect -eq $true } $connectPermission | Should -Not -BeNullOrEmpty $connectPermission.PermissionType.Connect | Should -BeTrue diff --git a/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 index 864d21b4bb..296f814865 100644 --- a/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -50,21 +48,19 @@ Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration AfterAll { # Restore the expected state for shared test login that other tests depend on $script:loginObject = Get-SqlDscLogin -ServerObject $script:serverObject -Name $script:testLoginName -ErrorAction 'Stop' - + # Revoke any permissions we may have set Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'ViewServerState' -Force -ErrorAction 'SilentlyContinue' Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'ViewAnyDatabase' -Force -ErrorAction 'SilentlyContinue' Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'ViewAnyDefinition' -Force -ErrorAction 'SilentlyContinue' Revoke-SqlDscServerPermission -Login $script:loginObject -Permission 'CreateAnyDatabase' -WithGrant -Force -ErrorAction 'SilentlyContinue' - + # Restore the expected permissions that other tests depend on # Based on Grant test setup and Test command ExactMatch test expectations Grant-SqlDscServerPermission -Login $script:loginObject -Permission @('ViewServerState') -Force -ErrorAction 'SilentlyContinue' Grant-SqlDscServerPermission -Login $script:loginObject -Permission @('ViewAnyDefinition') -Force -ErrorAction 'SilentlyContinue' Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting server permissions to Grant state for login' { @@ -237,4 +233,3 @@ Describe 'Set-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration } } } - diff --git a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 index deb45e446a..d6b1da7ea1 100644 --- a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 @@ -59,8 +59,6 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration Write-Warning -Message "Failed to restore original startup parameters: $($_.Exception.Message)" } } - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When using parameter set ByServerName' { @@ -181,7 +179,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration # Verify the parameters haven't changed $newParams = Get-SqlDscStartupParameter -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' - + # Compare arrays properly handling nulls/empty arrays if ($currentParams.TraceFlag -and $newParams.TraceFlag) { Compare-Object -ReferenceObject $currentParams.TraceFlag -DifferenceObject $newParams.TraceFlag | Should -BeNullOrEmpty diff --git a/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 index 9ffd0914b1..7df5f92a93 100644 --- a/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscTraceFlag.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Set-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName @@ -51,8 +49,6 @@ Describe 'Set-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 # Clear all trace flags if there were none originally Set-SqlDscTraceFlag -ServerName $script:mockServerName -InstanceName $script:mockInstanceName -TraceFlag @() -Force -ErrorAction 'SilentlyContinue' } - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When setting trace flags' { diff --git a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 index c033bfc41b..df792a2302 100644 --- a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 @@ -56,8 +56,6 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When checking severity' { diff --git a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 index 1e1ba92678..066e98b51a 100644 --- a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Test-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -54,8 +52,6 @@ Describe 'Test-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integra } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing Agent XPs configuration option' { diff --git a/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 index c876debf50..0f73093962 100644 --- a/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscDatabase.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Test-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -46,8 +44,6 @@ Describe 'Test-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL201 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject -ErrorAction 'Stop' - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing database presence' { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 index 0fd49d4529..04fc34836b 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 @@ -56,8 +56,6 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When checking existence only' { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 index 2bd7189c1f..044aa5b617 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentOperator.Integration.Tests.ps1 @@ -43,8 +43,6 @@ AfterAll { Describe 'Test-SqlDscIsAgentOperator' -Tag 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022' { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $mockSqlAdministratorCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $mockSqlAdministratorUserName, $mockSqlAdministratorPassword @@ -54,9 +52,6 @@ Describe 'Test-SqlDscIsAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stopping the named instance SQL Server service after running tests. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When testing for an existing agent operator' { diff --git a/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 index 2f6b8bbc20..861e1808c0 100644 --- a/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsLogin.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Test-SqlDscIsLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -48,8 +46,6 @@ Describe 'Test-SqlDscIsLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing login existence using ServerObject parameter set' { @@ -99,7 +95,7 @@ Describe 'Test-SqlDscIsLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 # Test with Windows login (using SqlAdmin which should exist) $computerName = Get-ComputerName $windowsLoginName = "$computerName\SqlAdmin" - + $result = Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $windowsLoginName $result | Should -BeOfType [System.Boolean] diff --git a/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 index ab5e4c1f22..bfc26dec12 100644 --- a/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsLoginEnabled.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Test-SqlDscIsLoginEnabled' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -48,8 +46,6 @@ Describe 'Test-SqlDscIsLoginEnabled' -Tag @('Integration_SQL2017', 'Integration_ AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing login state using ServerObject parameter set' { diff --git a/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 index c8c3e7d22e..648217fdd1 100644 --- a/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsRole.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Test-SqlDscIsRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -48,8 +46,6 @@ Describe 'Test-SqlDscIsRole' -Tag @('Integration_SQL2017', 'Integration_SQL2019' AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing for existing system roles' { diff --git a/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 index bf0c5d37db..a5a4d4c4c6 100644 --- a/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscServerPermission.Integration.Tests.ps1 @@ -31,8 +31,6 @@ BeforeAll { Describe 'Test-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. @@ -49,8 +47,6 @@ Describe 'Test-SqlDscServerPermission' -Tag @('Integration_SQL2017', 'Integratio AfterAll { Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Note: SQL Server service is left running for subsequent tests for performance optimization } Context 'When testing server permissions for login' { From 9ae2ca3cff060b90a9915d176f6635eb8bb59951 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 12:48:52 +0200 Subject: [PATCH 3/9] Refactor integration tests to remove service start/stop commands for SQL Server instance --- .../Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 b/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 index 7667790d9e..622769e1e9 100644 --- a/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 @@ -31,9 +31,6 @@ BeforeAll { Describe 'Invoke-SqlDscQuery' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { - # Starting the named instance SQL Server service prior to running tests. - Start-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' - $script:mockInstanceName = 'DSCSQLTEST' $script:mockComputerName = Get-ComputerName @@ -58,7 +55,7 @@ CREATE TABLE TestTable ( INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Test3', 300) "@ - + Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query $createTableQuery -Force -ErrorAction 'Stop' } @@ -77,9 +74,6 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject - - # Stop the named instance SQL Server service to save memory on the build worker. - Stop-Service -Name 'MSSQL$DSCSQLTEST' -Verbose -ErrorAction 'Stop' } Context 'When executing a query using ServerObject parameter set' { From f090d96ed66ae4205db1acd65fdec0f7acfcc7c5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 18:06:26 +0200 Subject: [PATCH 4/9] Refactor integration tests to check for null before restoring Agent XPs value --- .../Set-SqlDscConfigurationOption.Integration.Tests.ps1 | 2 +- .../Test-SqlDscConfigurationOption.Integration.Tests.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 index 492683fa68..49296567cf 100644 --- a/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -46,7 +46,7 @@ Describe 'Set-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat AfterAll { # Restore the original Agent XPs value - if ($script:originalAgentXPsValue) + if ($null -ne $script:originalAgentXPsValue) { Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value $script:originalAgentXPsValue.RunValue -Force -ErrorAction 'SilentlyContinue' } diff --git a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 index 066e98b51a..d9c89b7f98 100644 --- a/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -46,7 +46,7 @@ Describe 'Test-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integra AfterAll { # Restore the original Agent XPs value - if ($script:originalAgentXPsValue) + if ($null -ne $script:originalAgentXPsValue) { Set-SqlDscConfigurationOption -ServerObject $script:serverObject -Name 'Agent XPs' -Value $script:originalAgentXPsValue.RunValue -Force -ErrorAction 'SilentlyContinue' } From 9df2ef1319b3e9940597a3a0156f7c16825b9440 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 20:16:07 +0200 Subject: [PATCH 5/9] Update integration tests for Get-SqlDscConfigurationOption to assert correct values for Agent XPs configuration option --- ...t-SqlDscConfigurationOption.Integration.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 index cabb199c3e..36f9ed4845 100644 --- a/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscConfigurationOption.Integration.Tests.ps1 @@ -79,8 +79,8 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result | Should -BeOfType 'PSCustomObject' $result.PSTypeNames[0] | Should -Be 'SqlDsc.ConfigurationOption' $result.Name | Should -Be 'Agent XPs' - $result.RunValue | Should -Be 0 - $result.ConfigValue | Should -Be 0 + $result.RunValue | Should -Be 1 + $result.ConfigValue | Should -Be 1 $result.Minimum | Should -Be 0 $result.Maximum | Should -Be 1 $result.IsDynamic | Should -BeTrue @@ -103,7 +103,7 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result = Get-SqlDscConfigurationOption -ServerObject $script:serverObject -Name '*XP*' @($result).Count | Should -BeGreaterOrEqual 1 - $result | Where-Object { $_.Name -eq 'Agent XPs' } | Should -Not -BeNullOrEmpty + $result | Where-Object -FilterScript { $_.Name -eq 'Agent XPs' } | Should -Not -BeNullOrEmpty } } @@ -114,8 +114,8 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' $result.DisplayName | Should -Be 'Agent XPs' - $result.RunValue | Should -Be 0 - $result.ConfigValue | Should -Be 0 + $result.RunValue | Should -Be 1 + $result.ConfigValue | Should -Be 1 } } @@ -137,7 +137,7 @@ Describe 'Get-SqlDscConfigurationOption' -Tag @('Integration_SQL2017', 'Integrat $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType 'PSCustomObject' $result.Name | Should -Be 'Agent XPs' - $result.RunValue | Should -Be 0 + $result.RunValue | Should -Be 1 } } } From 1e8a028597d205dd7ae3f987754cb8d666d8286c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 21:09:27 +0200 Subject: [PATCH 6/9] Remove requirement to start/stop Windows service for integration tests --- .github/instructions/SqlServerDsc-guidelines.instructions.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/instructions/SqlServerDsc-guidelines.instructions.md b/.github/instructions/SqlServerDsc-guidelines.instructions.md index 12677a9144..c03e1d867c 100644 --- a/.github/instructions/SqlServerDsc-guidelines.instructions.md +++ b/.github/instructions/SqlServerDsc-guidelines.instructions.md @@ -37,7 +37,6 @@ applyTo: "**" ## Tests Requirements - Unit tests: Add `$env:SqlServerDscCI = $true` in `BeforeAll`, remove in `AfterAll` - Integration tests: - - If requiring SQL Server DB, start the Windows service in `BeforeAll`, stop it in `AfterAll`. - Use `Connect-SqlDscDatabaseEngine` for SQL Server DB session, and always with correct CI credentials - Use `Disconnect-SqlDscDatabaseEngine` after `Connect-SqlDscDatabaseEngine` - Test config: tests/Integration/Commands/README.md and tests/Integration/Resources/README.md From 06abf1e5c9497287c688dcce02b181c07394000e Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 21:19:25 +0200 Subject: [PATCH 7/9] Refactor integration tests to remove unnecessary comments about SQL Server service state for named instance context --- .../Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 index 4f1ed17d1a..cbc56489cc 100644 --- a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -84,14 +84,6 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integrati } Context 'When connecting to a named instance' { - BeforeAll { - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - } - - AfterAll { - # Note: SQL Server service is left running for subsequent tests for performance optimization - } - It 'Should have the named instance SQL Server service started' { $getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' From 415b9d2cb43c6985dc6c20b80d1f82b4397926ab Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 21:21:06 +0200 Subject: [PATCH 8/9] Remove unnecessary comment about SQL Server service state in Get-SqlDscAgentAlert integration tests --- .../Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 index 0fab0df64b..cbdb1ab0db 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Get-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force From 2a85fcf104480913fb6d28c34fb43f1fffc1f543 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 22 Sep 2025 21:23:45 +0200 Subject: [PATCH 9/9] Remove unnecessary comments about SQL Server service state from integration tests --- .../Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 | 2 -- .../Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 | 2 -- .../Get-SqlDscManagedComputerService.Integration.Tests.ps1 | 2 -- .../Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 | 2 -- .../Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- .../Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- .../Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 | 2 -- .../Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 | 2 -- .../Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 | 2 -- .../Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 | 2 -- .../Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 | 2 -- 11 files changed, 22 deletions(-) diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 index 3415722edd..68393b7d10 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputer.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Get-SqlDscManagedComputer' -Tag @('Integration_SQL2017', 'Integration_ BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockServerName = Get-ComputerName } diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 index 4bb3662ecd..2842dbbfae 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerInstance.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Get-SqlDscManagedComputerInstance' -Tag @('Integration_SQL2017', 'Inte BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName } diff --git a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 index b124dc3316..80f2953de1 100644 --- a/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscManagedComputerService.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Get-SqlDscManagedComputerService' -Tag @('Integration_SQL2017', 'Integ BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName } diff --git a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 index 0b383940c6..9a0632940a 100644 --- a/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscServerProtocol.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Get-SqlDscServerProtocol' -Tag @('Integration_SQL2017', 'Integration_S BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName } diff --git a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 index d8aca04ac1..9b0689fc0c 100644 --- a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'New-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 index b92c5282d7..35babc7248 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 index e5029d32b5..66d0b8f409 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Set-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 index d6b1da7ea1..72517f8be0 100644 --- a/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscStartupParameter.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Set-SqlDscStartupParameter' -Tag @('Integration_SQL2017', 'Integration BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $script:mockInstanceName = 'DSCSQLTEST' $script:mockServerName = Get-ComputerName diff --git a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 index df792a2302..bbec097631 100644 --- a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 index 04fc34836b..c4c9d5419c 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 @@ -34,8 +34,6 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ # Integration tests are run on the DSCSQLTEST instance $script:sqlServerInstance = 'DSCSQLTEST' - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization - $mockSqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force diff --git a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 index 87b2fd37dd..a290d7b07a 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 @@ -33,8 +33,6 @@ BeforeAll { Describe 'Uninstall-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { BeforeAll { Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - - # Note: SQL Server service is already running from Install-SqlDscServer test for performance optimization } It 'Should have the named instance SQL Server service started' {