diff --git a/.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md b/.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md index 57a9b5d89f..636e49f0e7 100644 --- a/.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md +++ b/.github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md @@ -14,7 +14,7 @@ applyTo: "tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1" - Avoid `ExpectedMessage` for `Should -Throw` assertions - Only run integration tests in CI unless explicitly instructed. - Call commands with `-Force` parameter where applicable (avoids prompting). -- Use `-ErrorAction Stop` on commands so failures surface immediately +- Use `-ErrorAction 'Stop'` on commands so failures surface immediately ## Required Setup Block diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml index 58539b5b76..1ea67657b2 100644 --- a/.github/workflows/copilot-setup-steps.yml +++ b/.github/workflows/copilot-setup-steps.yml @@ -215,7 +215,7 @@ jobs: Write-Host 'Resolving project dependencies...' # Run dependency resolution - ./build.ps1 -ResolveDependency -Tasks 'noop' -UseModuleFast -ErrorAction Stop + ./build.ps1 -ResolveDependency -Tasks 'noop' -UseModuleFast -ErrorAction 'Stop' Write-Host 'Dependencies resolved successfully.' @@ -225,7 +225,7 @@ jobs: Write-Host "Building $env:MODULE_NAME module..." # Build the module - ./build.ps1 -Tasks 'build' -ErrorAction Stop + ./build.ps1 -Tasks 'build' -ErrorAction 'Stop' # Verify build output $builtPath = "output/builtModule/$env:MODULE_NAME" diff --git a/CHANGELOG.md b/CHANGELOG.md index b7221dd799..48e592f709 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -317,6 +317,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 from managed computer and instance objects. - Enhanced to optionally return all protocols when ProtocolName parameter is not specified. +- All tests was changed to no longer use `Should -Not -Throw` for testing + that commands do not throw errors. Instead, tests now simply call the command + and will fail if an error is thrown, following best practices (follows + Pester 6 syntax). ### Changed diff --git a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 index b0296beda9..ad0458c359 100644 --- a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 +++ b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 @@ -294,7 +294,7 @@ function Set-TargetResource $script:localizedData.RemoveAvailabilityGroup -f $Name, $InstanceName ) - Remove-SqlAvailabilityGroup -InputObject $availabilityGroup -ErrorAction Stop + Remove-SqlAvailabilityGroup -InputObject $availabilityGroup -ErrorAction 'Stop' } catch { @@ -368,7 +368,7 @@ function Set-TargetResource $script:localizedData.CreateAvailabilityGroupReplica -f $newReplicaParams.Name, $Name, $InstanceName ) - $primaryReplica = New-SqlAvailabilityReplica @newReplicaParams -ErrorAction Stop + $primaryReplica = New-SqlAvailabilityReplica @newReplicaParams -ErrorAction 'Stop' } catch { @@ -412,7 +412,7 @@ function Set-TargetResource $script:localizedData.CreateAvailabilityGroup -f $Name, $InstanceName ) - New-SqlAvailabilityGroup @newAvailabilityGroupParams -ErrorAction Stop + New-SqlAvailabilityGroup @newAvailabilityGroupParams -ErrorAction 'Stop' } catch { diff --git a/source/DSCResources/DSC_SqlAGListener/DSC_SqlAGListener.psm1 b/source/DSCResources/DSC_SqlAGListener/DSC_SqlAGListener.psm1 index a77b0b72e4..17b74efb42 100644 --- a/source/DSCResources/DSC_SqlAGListener/DSC_SqlAGListener.psm1 +++ b/source/DSCResources/DSC_SqlAGListener/DSC_SqlAGListener.psm1 @@ -259,7 +259,7 @@ function Set-TargetResource Write-Verbose -Message $script:localizedData.SetAvailabilityGroupListenerDhcpDefaultSubnet } - New-SqlAvailabilityGroupListener @newListenerParams -ErrorAction Stop | Out-Null + New-SqlAvailabilityGroupListener @newListenerParams -ErrorAction 'Stop' | Out-Null } else { @@ -355,7 +355,7 @@ function Set-TargetResource Port = $Port } - Set-SqlAvailabilityGroupListener @setListenerParams -ErrorAction Stop | Out-Null + Set-SqlAvailabilityGroupListener @setListenerParams -ErrorAction 'Stop' | Out-Null } if (-not $ipAddressEqual) @@ -379,7 +379,7 @@ function Set-TargetResource StaticIp = $newIpAddress } - Add-SqlAvailabilityGroupListenerStaticIp @setListenerParams -ErrorAction Stop | Out-Null + Add-SqlAvailabilityGroupListenerStaticIp @setListenerParams -ErrorAction 'Stop' | Out-Null } } else diff --git a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 index b8faea5548..4d1fc067b3 100644 --- a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 +++ b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 @@ -312,7 +312,7 @@ function Set-TargetResource $script:localizedData.RemoveAvailabilityReplica -f $Name, $AvailabilityGroupName, $InstanceName ) - Remove-SqlAvailabilityReplica -InputObject $availabilityGroupReplica -Confirm:$false -ErrorAction Stop + Remove-SqlAvailabilityReplica -InputObject $availabilityGroupReplica -Confirm:$false -ErrorAction 'Stop' } catch { diff --git a/source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1 b/source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1 index f6cf48177f..ca450ab49d 100644 --- a/source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1 +++ b/source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1 @@ -319,7 +319,7 @@ function Set-TargetResource $LoginCreateOptions = [Microsoft.SqlServer.Management.Smo.LoginCreateOptions]::None } - New-SQLServerLogin -Login $login -LoginCreateOptions $LoginCreateOptions -SecureString $LoginCredential.Password -ErrorAction Stop + New-SQLServerLogin -Login $login -LoginCreateOptions $LoginCreateOptions -SecureString $LoginCredential.Password -ErrorAction 'Stop' } default @@ -674,7 +674,7 @@ function Update-SQLServerLogin The SecureString object that contains the password for a SQL login. .EXAMPLE - CreateLogin -Login $login -LoginCreateOptions $LoginCreateOptions -SecureString $LoginCredential.Password -ErrorAction Stop + CreateLogin -Login $login -LoginCreateOptions $LoginCreateOptions -SecureString $LoginCredential.Password -ErrorAction 'Stop' .EXAMPLE CreateLogin -Login $login diff --git a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index cbea18321b..54b26ed6e1 100644 --- a/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -32,7 +32,7 @@ function Copy-ItemWithRobocopy $quotedPath = '"{0}"' -f $Path $quotedDestinationPath = '"{0}"' -f $DestinationPath - $robocopyExecutable = Get-Command -Name 'Robocopy.exe' -ErrorAction Stop + $robocopyExecutable = Get-Command -Name 'Robocopy.exe' -ErrorAction 'Stop' $robocopyArgumentSilent = '/njh /njs /ndl /nc /ns /nfl' $robocopyArgumentCopySubDirectoriesIncludingEmpty = '/e' @@ -284,11 +284,11 @@ function Start-SqlSetupProcess ArgumentList = $ArgumentList } - $sqlSetupProcess = Start-Process @startProcessParameters -PassThru -NoNewWindow -ErrorAction Stop + $sqlSetupProcess = Start-Process @startProcessParameters -PassThru -NoNewWindow -ErrorAction 'Stop' Write-Verbose -Message ($script:localizedData.StartSetupProcess -f $sqlSetupProcess.Id, $startProcessParameters.FilePath, $Timeout) -Verbose - Wait-Process -InputObject $sqlSetupProcess -Timeout $Timeout -ErrorAction Stop + Wait-Process -InputObject $sqlSetupProcess -Timeout $Timeout -ErrorAction 'Stop' return $sqlSetupProcess.ExitCode } diff --git a/tests/Integration/Commands/Add-SqlDscTraceFlag.Integration.Tests.ps1 b/tests/Integration/Commands/Add-SqlDscTraceFlag.Integration.Tests.ps1 index bcc984ce1a..79275e6835 100644 --- a/tests/Integration/Commands/Add-SqlDscTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Add-SqlDscTraceFlag.Integration.Tests.ps1 @@ -63,9 +63,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should add a single trace flag without error' { # Act - Add the trace flag - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Assert - Verify the trace flag was added $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -74,9 +72,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should add multiple trace flags without error' { # Act - Add the trace flags - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' # Assert - Verify the trace flags were added $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -94,9 +90,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 $beforeCount = ($beforeAddTraceFlags | Where-Object { $_ -eq $script:singleTestTraceFlag }).Count # Act - Try to add the same trace flag again - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Assert - Verify no duplicate was created $afterAddTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -111,9 +105,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Act - Add additional trace flags - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:additionalTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:additionalTestTraceFlag -Force -ErrorAction 'Stop' # Assert - Verify both old and new trace flags exist $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -158,9 +150,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should add a single trace flag using ServiceObject parameter' { # Act - Add the trace flag - { - Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Assert - Verify the trace flag was added $currentTraceFlags = Get-SqlDscTraceFlag -ServiceObject $script:serviceObject -ErrorAction 'Stop' @@ -169,9 +159,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should add multiple trace flags using ServiceObject parameter' { # Act - Add the trace flags - { - Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' # Assert - Verify the trace flags were added $currentTraceFlags = Get-SqlDscTraceFlag -ServiceObject $script:serviceObject -ErrorAction 'Stop' diff --git a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 index d55ac7c122..4cb2e64446 100644 --- a/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscAgentOperator.Integration.Tests.ps1 @@ -35,7 +35,7 @@ BeforeAll { } AfterAll { - Remove-Item -Path 'Env:\SqlServerDscCI' -ErrorAction 'SilentlyContinue' + $null = Remove-Item -Path 'Env:\SqlServerDscCI' -ErrorAction 'Stop' # Unload the module being tested so that it doesn't impact any other tests. Get-Module -Name $script:moduleName -All | Remove-Module -Force @@ -52,11 +52,11 @@ Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S $script:sqlServerObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create a test operator for assertion tests - $script:sqlServerObject | New-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -EmailAddress 'assert@contoso.com' -ErrorAction Stop + $null = $script:sqlServerObject | New-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -EmailAddress 'assert@contoso.com' -ErrorAction 'Stop' } AfterAll { - $script:sqlServerObject | Remove-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -Force -ErrorAction 'SilentlyContinue' + $null = $script:sqlServerObject | Remove-SqlDscAgentOperator -Name 'IntegrationTest_AssertOperator' -Force -ErrorAction 'Stop' # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject @@ -64,22 +64,22 @@ Describe 'Assert-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S Context 'When operator exists' { It 'Should not throw when asserting existing operator' { - $null = Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'IntegrationTest_AssertOperator' -ErrorAction Stop + $null = Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'IntegrationTest_AssertOperator' -ErrorAction 'Stop' } It 'Should not throw when asserting persistent operator created by New-SqlDscAgentOperator' { - $null = Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'SqlDscIntegrationTestOperator_Persistent' -ErrorAction Stop + $null = Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'SqlDscIntegrationTestOperator_Persistent' -ErrorAction 'Stop' } It 'Should not return anything when operator exists' { - $result = Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'IntegrationTest_AssertOperator' -ErrorAction Stop + $result = Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'IntegrationTest_AssertOperator' -ErrorAction 'Stop' $result | Should -BeNullOrEmpty } } Context 'When operator does not exist' { It 'Should throw terminating error when operator does not exist' { - { Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'NonExistentOperator' -ErrorAction Stop } | Should -Throw + { Assert-SqlDscAgentOperator -ServerObject $script:sqlServerObject -Name 'NonExistentOperator' -ErrorAction 'Stop' } | Should -Throw } } diff --git a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 index 1db9150763..e9527018bd 100644 --- a/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Assert-SqlDscLogin.Integration.Tests.ps1 @@ -51,19 +51,19 @@ Describe 'Assert-SqlDscLogin' -Tag @('Integration_SQL2017', 'Integration_SQL2019 Context 'When a login exists' { It 'Should not throw an error for sa login' { - { Assert-SqlDscLogin -ServerObject $script:serverObject -Name 'sa' } | Should -Not -Throw + $null = Assert-SqlDscLogin -ServerObject $script:serverObject -Name 'sa' -ErrorAction 'Stop' } It 'Should not throw an error when using pipeline' { - { $script:serverObject | Assert-SqlDscLogin -Name 'sa' } | Should -Not -Throw + $null = $script:serverObject | Assert-SqlDscLogin -Name 'sa' -ErrorAction 'Stop' } It 'Should not throw an error for NT AUTHORITY\SYSTEM login' { - { Assert-SqlDscLogin -ServerObject $script:serverObject -Name 'NT AUTHORITY\SYSTEM' } | Should -Not -Throw + $null = Assert-SqlDscLogin -ServerObject $script:serverObject -Name 'NT AUTHORITY\SYSTEM' -ErrorAction 'Stop' } It 'Should not throw an error for SqlAdmin login' { - { Assert-SqlDscLogin -ServerObject $script:serverObject -Name ('{0}\SqlAdmin' -f $script:computerName) } | Should -Not -Throw + $null = Assert-SqlDscLogin -ServerObject $script:serverObject -Name ('{0}\SqlAdmin' -f $script:computerName) -ErrorAction 'Stop' } } diff --git a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 index cbc56489cc..5e5bb0a058 100644 --- a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -65,20 +65,18 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integrati Context 'When impersonating a Windows user' { It 'Should return the correct result' { - { - $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - $connectSqlDscDatabaseEngineParameters = @{ - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } + $connectSqlDscDatabaseEngineParameters = @{ + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - $sqlServerObject.Status.ToString() | Should -Match '^Online$' - } | Should -Not -Throw + $sqlServerObject.Status.ToString() | Should -Match '^Online$' } } } @@ -92,42 +90,38 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integrati Context 'When impersonating a Windows user' { It 'Should return the correct result' { - { - $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - $connectSqlDscDatabaseEngineParameters = @{ - InstanceName = 'DSCSQLTEST' - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } + $connectSqlDscDatabaseEngineParameters = @{ + InstanceName = 'DSCSQLTEST' + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - $sqlServerObject.Status.ToString() | Should -Match '^Online$' - } | Should -Not -Throw + $sqlServerObject.Status.ToString() | Should -Match '^Online$' } } Context 'When using a SQL login' { It 'Should return the correct result' { - { - $sqlAdministratorUserName = 'sa' - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - - $connectSqlDscDatabaseEngineParameters = @{ - InstanceName = 'DSCSQLTEST' # cSpell: disable-line - LoginType = 'SqlLogin' - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } - - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - - $sqlServerObject.Status.ToString() | Should -Match '^Online$' - } | Should -Not -Throw + $sqlAdministratorUserName = 'sa' + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + + $connectSqlDscDatabaseEngineParameters = @{ + InstanceName = 'DSCSQLTEST' # cSpell: disable-line + LoginType = 'SqlLogin' + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } + + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + + $sqlServerObject.Status.ToString() | Should -Match '^Online$' } } } diff --git a/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 b/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 index 178f7180ab..edc140f1da 100644 --- a/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 +++ b/tests/Integration/Commands/ConvertTo-SqlDscEditionName.Integration.Tests.ps1 @@ -148,11 +148,11 @@ Describe 'ConvertTo-SqlDscEditionName' -Tag @('Integration_SQL2017', 'Integratio Context 'When testing parameter validation' { It 'Should accept minimum UInt32 value (0)' { - { ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop' } | Should -Not -Throw + $null = ConvertTo-SqlDscEditionName -Id 0 -ErrorAction 'Stop' } It 'Should accept maximum UInt32 value (4294967295)' { - { ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' } | Should -Not -Throw + $null = ConvertTo-SqlDscEditionName -Id 4294967295 -ErrorAction 'Stop' } } } diff --git a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 index 87ee6ac36d..a6196ccd04 100644 --- a/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disable-SqlDscAudit.Integration.Tests.ps1 @@ -39,7 +39,7 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' } AfterAll { @@ -50,8 +50,8 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 BeforeEach { # Create and enable a test audit for each test $script:testAuditName = 'SqlDscTestDisableAudit_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction 'Stop' } AfterEach { @@ -70,35 +70,35 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should disable an enabled audit successfully' { # Verify audit exists and is enabled before disabling - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty $existingAudit.Enabled | Should -BeTrue # Disable the audit - $null = Disable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction Stop + $null = Disable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction 'Stop' # Verify audit is now disabled - $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $disabledAudit | Should -Not -BeNullOrEmpty $disabledAudit.Enabled | Should -BeFalse } It 'Should throw error when trying to disable non-existent audit' { - { Disable-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -Force -ErrorAction Stop } | + { Disable-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should support the Refresh parameter' { # Verify audit exists and is enabled before disabling - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty $existingAudit.Enabled | Should -BeTrue # Disable the audit with Refresh parameter - $null = Disable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Refresh -Force -ErrorAction Stop + $null = Disable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Refresh -Force -ErrorAction 'Stop' # Verify audit is now disabled - $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $disabledAudit | Should -Not -BeNullOrEmpty $disabledAudit.Enabled | Should -BeFalse } @@ -108,8 +108,8 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 BeforeEach { # Create and enable a test audit for each test $script:testAuditNameForObject = 'SqlDscTestDisableAuditObj_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction Stop - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -Force -ErrorAction 'Stop' } AfterEach { @@ -127,29 +127,29 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 } It 'Should disable an audit using audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $auditObject.Enabled | Should -BeTrue # Disable the audit using audit object - $null = Disable-SqlDscAudit -AuditObject $auditObject -Force -ErrorAction Stop + $null = Disable-SqlDscAudit -AuditObject $auditObject -Force -ErrorAction 'Stop' # Verify audit is now disabled - $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $disabledAudit | Should -Not -BeNullOrEmpty $disabledAudit.Enabled | Should -BeFalse } It 'Should support pipeline input with audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $auditObject.Enabled | Should -BeTrue # Disable the audit using pipeline - $auditObject | Disable-SqlDscAudit -Force -ErrorAction Stop + $auditObject | Disable-SqlDscAudit -Force -ErrorAction 'Stop' # Verify audit is now disabled - $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $disabledAudit | Should -Not -BeNullOrEmpty $disabledAudit.Enabled | Should -BeFalse } @@ -159,8 +159,8 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 BeforeEach { # Create and enable a test audit for each test $script:testAuditNameForPipeline = 'SqlDscTestDisableAuditPipe_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction Stop - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -Force -ErrorAction 'Stop' } AfterEach { @@ -179,15 +179,15 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should support pipeline input with server object' { # Verify audit exists and is enabled before disabling - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty $existingAudit.Enabled | Should -BeTrue # Disable the audit using pipeline with server object - $script:serverObject | Disable-SqlDscAudit -Name $script:testAuditNameForPipeline -Force -ErrorAction Stop + $script:serverObject | Disable-SqlDscAudit -Name $script:testAuditNameForPipeline -Force -ErrorAction 'Stop' # Verify audit is now disabled - $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $disabledAudit | Should -Not -BeNullOrEmpty $disabledAudit.Enabled | Should -BeFalse } @@ -203,8 +203,8 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 foreach ($auditName in $script:testAuditNames) { - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction 'Stop' } } @@ -229,7 +229,7 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 # Verify audits exist and are enabled before disabling foreach ($auditName in $script:testAuditNames) { - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty $existingAudit.Enabled | Should -BeTrue } @@ -237,13 +237,13 @@ Describe 'Disable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL201 # Disable the audits foreach ($auditName in $script:testAuditNames) { - $null = Disable-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction Stop + $null = Disable-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction 'Stop' } # Verify audits are now disabled foreach ($auditName in $script:testAuditNames) { - $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $disabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $disabledAudit | Should -Not -BeNullOrEmpty $disabledAudit.Enabled | Should -BeFalse } diff --git a/tests/Integration/Commands/Disconnect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Disconnect-SqlDscDatabaseEngine.Integration.Tests.ps1 index 60e9f3c5d0..c45966bcf3 100644 --- a/tests/Integration/Commands/Disconnect-SqlDscDatabaseEngine.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Disconnect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -54,51 +54,47 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integr Context 'When disconnecting using Force parameter' { It 'Should disconnect successfully without confirmation' { - { - $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - $connectSqlDscDatabaseEngineParameters = @{ - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } + $connectSqlDscDatabaseEngineParameters = @{ + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - $sqlServerObject.Status.ToString() | Should -Match '^Online$' + $sqlServerObject.Status.ToString() | Should -Match '^Online$' - # Test the disconnect functionality - Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -Force -ErrorAction 'Stop' + # Test the disconnect functionality + Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -Force -ErrorAction 'Stop' - # After disconnect, the connection should be closed - $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse - } | Should -Not -Throw + # After disconnect, the connection should be closed + $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse } } Context 'When disconnecting using pipeline input' { It 'Should disconnect successfully via pipeline' { - { - $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - $connectSqlDscDatabaseEngineParameters = @{ - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } + $connectSqlDscDatabaseEngineParameters = @{ + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - $sqlServerObject.Status.ToString() | Should -Match '^Online$' + $sqlServerObject.Status.ToString() | Should -Match '^Online$' - # Test the disconnect functionality via pipeline - $sqlServerObject | Disconnect-SqlDscDatabaseEngine -Force -ErrorAction 'Stop' + # Test the disconnect functionality via pipeline + $sqlServerObject | Disconnect-SqlDscDatabaseEngine -Force -ErrorAction 'Stop' - # After disconnect, the connection should be closed - $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse - } | Should -Not -Throw + # After disconnect, the connection should be closed + $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse } } } @@ -112,54 +108,50 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2017', 'Integr Context 'When disconnecting using Windows authentication' { It 'Should disconnect successfully from named instance' { - { - $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + $sqlAdministratorUserName = 'SqlAdmin' # Using computer name as NetBIOS name throw exception. + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - $connectSqlDscDatabaseEngineParameters = @{ - InstanceName = 'DSCSQLTEST' - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } + $connectSqlDscDatabaseEngineParameters = @{ + InstanceName = 'DSCSQLTEST' + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - $sqlServerObject.Status.ToString() | Should -Match '^Online$' + $sqlServerObject.Status.ToString() | Should -Match '^Online$' - # Test the disconnect functionality - Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -Force -ErrorAction 'Stop' + # Test the disconnect functionality + Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -Force -ErrorAction 'Stop' - # After disconnect, the connection should be closed - $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse - } | Should -Not -Throw + # After disconnect, the connection should be closed + $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse } } Context 'When disconnecting using SQL authentication' { It 'Should disconnect successfully from named instance with SQL login' { - { - $sqlAdministratorUserName = 'sa' - $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + $sqlAdministratorUserName = 'sa' + $sqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - $connectSqlDscDatabaseEngineParameters = @{ - InstanceName = 'DSCSQLTEST' # cSpell: disable-line - LoginType = 'SqlLogin' - Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) - Verbose = $true - ErrorAction = 'Stop' - } + $connectSqlDscDatabaseEngineParameters = @{ + InstanceName = 'DSCSQLTEST' # cSpell: disable-line + LoginType = 'SqlLogin' + Credential = [System.Management.Automation.PSCredential]::new($sqlAdministratorUserName, $sqlAdministratorPassword) + Verbose = $true + ErrorAction = 'Stop' + } - $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters + $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters - $sqlServerObject.Status.ToString() | Should -Match '^Online$' + $sqlServerObject.Status.ToString() | Should -Match '^Online$' - # Test the disconnect functionality - Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -Force -ErrorAction 'Stop' + # Test the disconnect functionality + Disconnect-SqlDscDatabaseEngine -ServerObject $sqlServerObject -Force -ErrorAction 'Stop' - # After disconnect, the connection should be closed - $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse - } | Should -Not -Throw + # After disconnect, the connection should be closed + $sqlServerObject.ConnectionContext.IsOpen | Should -BeFalse } } } diff --git a/tests/Integration/Commands/Enable-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Enable-SqlDscAudit.Integration.Tests.ps1 index 32a05a70f8..0c04a579a8 100644 --- a/tests/Integration/Commands/Enable-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Enable-SqlDscAudit.Integration.Tests.ps1 @@ -41,7 +41,7 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' } AfterAll { @@ -52,10 +52,10 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 BeforeEach { # Create a test audit for each test (disabled by default) $script:testAuditName = 'SqlDscTestEnableAudit_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop - + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + # Verify audit is created but disabled - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $auditObject.Enabled | Should -BeFalse } @@ -77,41 +77,40 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 It 'Should enable an audit successfully' { # Enable the audit - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction Stop + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction 'Stop' # Verify audit is now enabled - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue } It 'Should throw error when trying to enable non-existent audit' { - { Enable-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -Force -ErrorAction Stop } | + { Enable-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should support the Refresh parameter' { # Enable the audit with Refresh parameter - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Refresh -Force -ErrorAction Stop + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Refresh -Force -ErrorAction 'Stop' # Verify audit is now enabled - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue } It 'Should not fail when enabling an already enabled audit' { # Enable the audit first time - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction Stop + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction 'Stop' # Verify audit is enabled - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue # Enable the audit again - should not fail - { Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction Stop } | - Should -Not -Throw + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction 'Stop' # Verify audit is still enabled - $stillEnabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $stillEnabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $stillEnabledAudit.Enabled | Should -BeTrue } } @@ -120,10 +119,10 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 BeforeEach { # Create a test audit for each test (disabled by default) $script:testAuditNameForObject = 'SqlDscTestEnableAuditObj_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction Stop - + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + # Verify audit is created but disabled - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject.Enabled | Should -BeFalse } @@ -144,28 +143,28 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } It 'Should enable an audit using audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $auditObject.Enabled | Should -BeFalse # Enable the audit using audit object - $null = Enable-SqlDscAudit -AuditObject $auditObject -Force -ErrorAction Stop + $null = Enable-SqlDscAudit -AuditObject $auditObject -Force -ErrorAction 'Stop' # Verify audit is now enabled - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue } It 'Should support pipeline input with audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $auditObject.Enabled | Should -BeFalse # Enable the audit using pipeline - $auditObject | Enable-SqlDscAudit -Force -ErrorAction Stop + $auditObject | Enable-SqlDscAudit -Force -ErrorAction 'Stop' # Verify audit is now enabled - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue } } @@ -174,10 +173,10 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 BeforeEach { # Create a test audit for each test (disabled by default) $script:testAuditNameForPipeline = 'SqlDscTestEnableAuditPipe_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction Stop - + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + # Verify audit is created but disabled - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $auditObject.Enabled | Should -BeFalse } @@ -199,10 +198,10 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 It 'Should support pipeline input with server object' { # Enable the audit using pipeline with server object - $script:serverObject | Enable-SqlDscAudit -Name $script:testAuditNameForPipeline -Force -ErrorAction Stop + $script:serverObject | Enable-SqlDscAudit -Name $script:testAuditNameForPipeline -Force -ErrorAction 'Stop' # Verify audit is now enabled - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue } } @@ -214,13 +213,13 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 'SqlDscTestMultiEnable1_' + (Get-Random), 'SqlDscTestMultiEnable2_' + (Get-Random) ) - + foreach ($auditName in $script:testAuditNames) { - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop - + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + # Verify audit is created but disabled - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $auditObject.Enabled | Should -BeFalse } } @@ -248,13 +247,13 @@ Describe 'Enable-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 # Enable the audits foreach ($auditName in $script:testAuditNames) { - $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction Stop + $null = Enable-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction 'Stop' } # Verify audits are now enabled foreach ($auditName in $script:testAuditNames) { - $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $enabledAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $enabledAudit.Enabled | Should -BeTrue } } diff --git a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 index cbdb1ab0db..bacca6befe 100644 --- a/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAgentAlert.Integration.Tests.ps1 @@ -55,8 +55,8 @@ END $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $addMessageQuery -Verbose -Force -ErrorAction 'Stop' # Create test alerts for getting - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Severity 16 -ErrorAction Stop - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -MessageId 50001 -ErrorAction Stop + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert1' -Severity 16 -ErrorAction 'Stop' + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_GetAlert2' -MessageId 50001 -ErrorAction 'Stop' } AfterAll { diff --git a/tests/Integration/Commands/Get-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscAudit.Integration.Tests.ps1 index 011dbd5b4e..7c32e15b7d 100644 --- a/tests/Integration/Commands/Get-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscAudit.Integration.Tests.ps1 @@ -39,14 +39,14 @@ Describe 'Get-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create test audits for the tests $script:testAuditName1 = 'SqlDscTestGetAudit1_' + (Get-Random) $script:testAuditName2 = 'SqlDscTestGetAudit2_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName1 -LogType 'ApplicationLog' -Force -ErrorAction Stop - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName2 -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName1 -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName2 -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } AfterAll { diff --git a/tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1 index bfa6babd92..61c388f466 100644 --- a/tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscInstalledInstance.Integration.Tests.ps1 @@ -32,7 +32,7 @@ BeforeAll { Describe 'Get-SqlDscInstalledInstance' { Context 'When getting all SQL Server instances' -Tag @('Integration_PowerBI') { It 'Should not throw an exception' { - { Get-SqlDscInstalledInstance } | Should -Not -Throw + $null = Get-SqlDscInstalledInstance -ErrorAction 'Stop' } It 'Should return an array of objects' { diff --git a/tests/Integration/Commands/Get-SqlDscTraceFlag.Integration.Tests.ps1 b/tests/Integration/Commands/Get-SqlDscTraceFlag.Integration.Tests.ps1 index c07413ef17..6615f0192e 100644 --- a/tests/Integration/Commands/Get-SqlDscTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Get-SqlDscTraceFlag.Integration.Tests.ps1 @@ -97,8 +97,7 @@ Describe 'Get-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL201 It 'Should return empty result when no trace flags are set' { # This test validates the command works when no trace flags are configured # We cannot control the trace flag state in CI, so we just verify the command executes without error - { Get-SqlDscTraceFlag -InstanceName $script:mockInstanceName -ErrorAction 'Stop' } | - Should -Not -Throw + $null = Get-SqlDscTraceFlag -InstanceName $script:mockInstanceName -ErrorAction 'Stop' } } diff --git a/tests/Integration/Commands/Import-SqlDscPreferredModule.Integration.Tests.ps1 b/tests/Integration/Commands/Import-SqlDscPreferredModule.Integration.Tests.ps1 index ae855aa19d..4df0a87d19 100644 --- a/tests/Integration/Commands/Import-SqlDscPreferredModule.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Import-SqlDscPreferredModule.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integrati } It 'Should import a module without throwing' { - { Import-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -ErrorAction 'Stop' } It 'Should import SqlServer module when available' { @@ -86,7 +86,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integrati } It 'Should import a module without throwing when using Force' { - { Import-SqlDscPreferredModule -Force -ErrorAction 'Stop' } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -Force -ErrorAction 'Stop' } It 'Should reload module when Force is used' { @@ -118,7 +118,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integrati return } - { Import-SqlDscPreferredModule -Name 'SQLPS' -ErrorAction 'Stop' } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -Name 'SQLPS' -ErrorAction 'Stop' $importedModule = Get-Module -Name 'SQLPS' $importedModule | Should -Not -BeNullOrEmpty @@ -134,7 +134,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integrati return } - { Import-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'Stop' } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'Stop' $importedModule = Get-Module -Name 'SqlServer' $importedModule | Should -Not -BeNullOrEmpty @@ -164,7 +164,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag @('Integration_SQL2017', 'Integrati $env:SMODefaultModuleName = 'SqlServer' - { Import-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -ErrorAction 'Stop' $importedModule = Get-Module -Name @('SqlServer', 'SQLPS') | Select-Object -First 1 $importedModule | Should -Not -BeNullOrEmpty diff --git a/tests/Integration/Commands/Install-SqlDscBIReportServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscBIReportServer.Integration.Tests.ps1 index 74a3f97296..82562bcb2b 100644 --- a/tests/Integration/Commands/Install-SqlDscBIReportServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscBIReportServer.Integration.Tests.ps1 @@ -42,21 +42,19 @@ Describe 'Install-SqlDscBIReportServer' -Tag @('Integration_PowerBI') { Context 'When installing Power BI Report Server' { # cSpell: ignore PBIRS It 'Should run the command without throwing' { - { - # Set splatting parameters for Install-SqlDscBIReportServer - $installSqlDscBIReportServerParameters = @{ - AcceptLicensingTerms = $true - MediaPath = $powerBIReportServerExecutable - InstallFolder = 'C:\Program Files\PBIRS' - Edition = 'Developer' - LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'PowerBIReportServer_Install.log' - SuppressRestart = $true - Verbose = $true - Force = $true - } + # Set splatting parameters for Install-SqlDscBIReportServer + $installSqlDscBIReportServerParameters = @{ + AcceptLicensingTerms = $true + MediaPath = $powerBIReportServerExecutable + InstallFolder = 'C:\Program Files\PBIRS' + Edition = 'Developer' + LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'PowerBIReportServer_Install.log' + SuppressRestart = $true + Verbose = $true + Force = $true + } - Install-SqlDscBIReportServer @installSqlDscBIReportServerParameters -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Install-SqlDscBIReportServer @installSqlDscBIReportServerParameters -ErrorAction 'Stop' } It 'Should have installed Power BI Report Server' { diff --git a/tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1 index a25817d2d4..8b56dbffd8 100644 --- a/tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscReportingService.Integration.Tests.ps1 @@ -41,21 +41,19 @@ Describe 'Install-SqlDscReportingService' -Tag @('Integration_SQL2017_RS', 'Inte Context 'When installing Reporting Services' { It 'Should run the command without throwing' { - { - # Set splatting parameters for Install-SqlDscReportingService - $installSqlDscReportingServicesParameters = @{ - AcceptLicensingTerms = $true - MediaPath = $reportingServicesExecutable - InstallFolder = 'C:\Program Files\SSRS' - Edition = 'Developer' - LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Install.log' - SuppressRestart = $true - Verbose = $true - Force = $true - } + # Set splatting parameters for Install-SqlDscReportingService + $installSqlDscReportingServicesParameters = @{ + AcceptLicensingTerms = $true + MediaPath = $reportingServicesExecutable + InstallFolder = 'C:\Program Files\SSRS' + Edition = 'Developer' + LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Install.log' + SuppressRestart = $true + Verbose = $true + Force = $true + } - Install-SqlDscReportingService @installSqlDscReportingServicesParameters -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Install-SqlDscReportingService @installSqlDscReportingServicesParameters -ErrorAction 'Stop' } It 'Should have installed Reporting Services' { diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index c12ac317c8..c2204ef85d 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -40,114 +40,112 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL20 Context 'When using Install parameter set' { Context 'When installing database engine default instance' { It 'Should run the command without throwing' { - { - # Set splatting parameters for Install-SqlDscServer - $installSqlDscServerParameters = @{ - Install = $true - AcceptLicensingTerms = $true - InstanceName = 'MSSQLSERVER' - Features = 'SQLENGINE' - SqlSysAdminAccounts = @( - ('{0}\SqlAdmin' -f $computerName) - ) - SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName - SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - SqlSvcStartupType = 'Automatic' - AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $computerName - AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - AgtSvcStartupType = 'Automatic' - BrowserSvcStartupType = 'Automatic' - SecurityMode = 'SQL' - SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - SqlCollation = 'Finnish_Swedish_CI_AS' - InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' - InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' - NpEnabled = $true - TcpEnabled = $true - MediaPath = $env:IsoDrivePath - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } - - Install-SqlDscServer @installSqlDscServerParameters - - # <# - # Fails with the following error message: - - # VERBOSE: Exit code (Decimal): -2068774911 - # VERBOSE: Exit facility code: 1201 - # VERBOSE: Exit error code: 1 - # VERBOSE: Exit message: There was an error generating the XML document. - - # Searches points to a permission issue, but the user has been - # granted the local administrator permissions. But code be - # Searches also points to user right SeEnableDelegationPrivilege - # which was not evaluated if it was set correctly or even needed. - # #> - # $installScriptBlock = { - # param - # ( - # [Parameter(Mandatory = $true)] - # [System.String] - # $IsoDrivePath, - - # [Parameter(Mandatory = $true)] - # [System.String] - # $ComputerName, - - # [Parameter(Mandatory = $true)] - # [System.String] - # $ModulePath - # ) - - # Write-Verbose -Message ('Running install as user ''{0}''.' -f $env:UserName) -Verbose - - # Import-Module -Name $ModulePath -Force -ErrorAction 'Stop' - - # # Set splatting parameters for Install-SqlDscServer - # $installSqlDscServerParameters = @{ - # Install = $true - # AcceptLicensingTerms = $true - # InstanceName = 'MSSQLSERVER' - # Features = 'SQLENGINE' - # SqlSysAdminAccounts = @( - # ('{0}\SqlAdmin' -f $ComputerName) - # ) - # SqlSvcAccount = '{0}\svc-SqlPrimary' -f $ComputerName - # SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - # SqlSvcStartupType = 'Automatic' - # AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $ComputerName - # AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - # AgtSvcStartupType = 'Automatic' - # BrowserSvcStartupType = 'Automatic' - # SecurityMode = 'SQL' - # SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - # SqlCollation = 'Finnish_Swedish_CI_AS' - # InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' - # InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' - # NpEnabled = $true - # TcpEnabled = $true - # MediaPath = $IsoDrivePath - # Verbose = $true - # ErrorAction = 'Stop' - # Force = $true - # } - - # Install-SqlDscServer @installSqlDscServerParameters - # } - - # $invokeCommandUsername = '{0}\SqlInstall' -f $ComputerName - # $invokeCommandPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - # $invokeCommandCredential = New-Object System.Management.Automation.PSCredential ($invokeCommandUsername, $invokeCommandPassword) - - # # Runs command as SqlInstall user. - # Invoke-Command -ComputerName 'localhost' -Credential $invokeCommandCredential -ScriptBlock $installScriptBlock -ArgumentList @( - # $env:IsoDrivePath, # Already set by the prerequisites tests - # (Get-ComputerName), - # $modulePath - # ) - } | Should -Not -Throw + # Set splatting parameters for Install-SqlDscServer + $installSqlDscServerParameters = @{ + Install = $true + AcceptLicensingTerms = $true + InstanceName = 'MSSQLSERVER' + Features = 'SQLENGINE' + SqlSysAdminAccounts = @( + ('{0}\SqlAdmin' -f $computerName) + ) + SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName + SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + SqlSvcStartupType = 'Automatic' + AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $computerName + AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + AgtSvcStartupType = 'Automatic' + BrowserSvcStartupType = 'Automatic' + SecurityMode = 'SQL' + SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + SqlCollation = 'Finnish_Swedish_CI_AS' + InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' + InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' + NpEnabled = $true + TcpEnabled = $true + MediaPath = $env:IsoDrivePath + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } + + $null = Install-SqlDscServer @installSqlDscServerParameters + + # <# + # Fails with the following error message: + + # VERBOSE: Exit code (Decimal): -2068774911 + # VERBOSE: Exit facility code: 1201 + # VERBOSE: Exit error code: 1 + # VERBOSE: Exit message: There was an error generating the XML document. + + # Searches points to a permission issue, but the user has been + # granted the local administrator permissions. But code be + # Searches also points to user right SeEnableDelegationPrivilege + # which was not evaluated if it was set correctly or even needed. + # #> + # $installScriptBlock = { + # param + # ( + # [Parameter(Mandatory = $true)] + # [System.String] + # $IsoDrivePath, + + # [Parameter(Mandatory = $true)] + # [System.String] + # $ComputerName, + + # [Parameter(Mandatory = $true)] + # [System.String] + # $ModulePath + # ) + + # Write-Verbose -Message ('Running install as user ''{0}''.' -f $env:UserName) -Verbose + + # Import-Module -Name $ModulePath -Force -ErrorAction 'Stop' + + # # Set splatting parameters for Install-SqlDscServer + # $installSqlDscServerParameters = @{ + # Install = $true + # AcceptLicensingTerms = $true + # InstanceName = 'MSSQLSERVER' + # Features = 'SQLENGINE' + # SqlSysAdminAccounts = @( + # ('{0}\SqlAdmin' -f $ComputerName) + # ) + # SqlSvcAccount = '{0}\svc-SqlPrimary' -f $ComputerName + # SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + # SqlSvcStartupType = 'Automatic' + # AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $ComputerName + # AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + # AgtSvcStartupType = 'Automatic' + # BrowserSvcStartupType = 'Automatic' + # SecurityMode = 'SQL' + # SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + # SqlCollation = 'Finnish_Swedish_CI_AS' + # InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' + # InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' + # NpEnabled = $true + # TcpEnabled = $true + # MediaPath = $IsoDrivePath + # Verbose = $true + # ErrorAction = 'Stop' + # Force = $true + # } + + # Install-SqlDscServer @installSqlDscServerParameters + # } + + # $invokeCommandUsername = '{0}\SqlInstall' -f $ComputerName + # $invokeCommandPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + # $invokeCommandCredential = New-Object System.Management.Automation.PSCredential ($invokeCommandUsername, $invokeCommandPassword) + + # # Runs command as SqlInstall user. + # Invoke-Command -ComputerName 'localhost' -Credential $invokeCommandCredential -ScriptBlock $installScriptBlock -ArgumentList @( + # $env:IsoDrivePath, # Already set by the prerequisites tests + # (Get-ComputerName), + # $modulePath + # ) } It 'Should have installed the SQL Server database engine' { @@ -182,116 +180,114 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL20 # } It 'Should run the command without throwing' { - { - # Set splatting parameters for Install-SqlDscServer - $installSqlDscServerParameters = @{ - Install = $true - AcceptLicensingTerms = $true - InstanceName = 'DSCSQLTEST' - Features = 'SQLENGINE' - SqlSysAdminAccounts = @( - ('{0}\SqlAdmin' -f $computerName) - ) - SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName - SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - SqlSvcStartupType = 'Automatic' - AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $computerName - AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - AgtSvcStartupType = 'Automatic' - BrowserSvcStartupType = 'Automatic' - SecurityMode = 'SQL' - SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - SqlCollation = 'Finnish_Swedish_CI_AS' - InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' - InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' - NpEnabled = $true - TcpEnabled = $true - MediaPath = $env:IsoDrivePath - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } - - Install-SqlDscServer @installSqlDscServerParameters - - # { - # <# - # Fails with the following error message: - - # VERBOSE: Exit code (Decimal): -2068774911 - # VERBOSE: Exit facility code: 1201 - # VERBOSE: Exit error code: 1 - # VERBOSE: Exit message: There was an error generating the XML document. - - # Searches points to a permission issue, but the user has been - # granted the local administrator permissions. But code be - # Searches also points to user right SeEnableDelegationPrivilege - # which was not evaluated if it was set correctly or even needed. - # #> - # $installScriptBlock = { - # param - # ( - # [Parameter(Mandatory = $true)] - # [System.String] - # $IsoDrivePath, - - # [Parameter(Mandatory = $true)] - # [System.String] - # $ComputerName, - - # [Parameter(Mandatory = $true)] - # [System.String] - # $ModulePath - # ) - - # Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose - - # Import-Module -Name $ModulePath -Force -ErrorAction 'Stop' - - # # Set splatting parameters for Install-SqlDscServer - # $installSqlDscServerParameters = @{ - # Install = $true - # AcceptLicensingTerms = $true - # InstanceName = 'DSCSQLTEST' # cSpell: disable-line - # Features = 'SQLENGINE' - # SqlSysAdminAccounts = @( - # ('{0}\SqlAdmin' -f $ComputerName) - # ) - # SqlSvcAccount = '{0}\svc-SqlPrimary' -f $ComputerName - # SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - # SqlSvcStartupType = 'Automatic' - # AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $ComputerName - # AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force - # AgtSvcStartupType = 'Automatic' - # BrowserSvcStartupType = 'Automatic' - # SecurityMode = 'SQL' - # SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - # SqlCollation = 'Finnish_Swedish_CI_AS' - # InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' - # InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' - # NpEnabled = $true - # TcpEnabled = $true - # MediaPath = $IsoDrivePath - # Verbose = $true - # ErrorAction = 'Stop' - # Force = $true - # } - - # Install-SqlDscServer @installSqlDscServerParameters - # } - - # $invokeCommandUsername = 'SqlInstall' # Using computer name as NetBIOS name throw exception. - # $invokeCommandPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force - # $invokeCommandCredential = New-Object System.Management.Automation.PSCredential ($invokeCommandUsername, $invokeCommandPassword) - - # # Runs command as SqlInstall user. - # Invoke-Command -ComputerName 'localhost' -Credential $invokeCommandCredential -ScriptBlock $installScriptBlock -ArgumentList @( - # $env:IsoDrivePath, # Already set by the prerequisites tests - # (Get-ComputerName), - # $modulePath - # ) - # } | Should -Not -Throw - } | Should -Not -Throw + # Set splatting parameters for Install-SqlDscServer + $installSqlDscServerParameters = @{ + Install = $true + AcceptLicensingTerms = $true + InstanceName = 'DSCSQLTEST' + Features = 'SQLENGINE' + SqlSysAdminAccounts = @( + ('{0}\SqlAdmin' -f $computerName) + ) + SqlSvcAccount = '{0}\svc-SqlPrimary' -f $computerName + SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + SqlSvcStartupType = 'Automatic' + AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $computerName + AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + AgtSvcStartupType = 'Automatic' + BrowserSvcStartupType = 'Automatic' + SecurityMode = 'SQL' + SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + SqlCollation = 'Finnish_Swedish_CI_AS' + InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' + InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' + NpEnabled = $true + TcpEnabled = $true + MediaPath = $env:IsoDrivePath + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } + + $null = Install-SqlDscServer @installSqlDscServerParameters + + # { + # <# + # Fails with the following error message: + + # VERBOSE: Exit code (Decimal): -2068774911 + # VERBOSE: Exit facility code: 1201 + # VERBOSE: Exit error code: 1 + # VERBOSE: Exit message: There was an error generating the XML document. + + # Searches points to a permission issue, but the user has been + # granted the local administrator permissions. But code be + # Searches also points to user right SeEnableDelegationPrivilege + # which was not evaluated if it was set correctly or even needed. + # #> + # $installScriptBlock = { + # param + # ( + # [Parameter(Mandatory = $true)] + # [System.String] + # $IsoDrivePath, + + # [Parameter(Mandatory = $true)] + # [System.String] + # $ComputerName, + + # [Parameter(Mandatory = $true)] + # [System.String] + # $ModulePath + # ) + + # Write-Verbose -Message ('Running integration test as user ''{0}''.' -f $env:UserName) -Verbose + + # Import-Module -Name $ModulePath -Force -ErrorAction 'Stop' + + # # Set splatting parameters for Install-SqlDscServer + # $installSqlDscServerParameters = @{ + # Install = $true + # AcceptLicensingTerms = $true + # InstanceName = 'DSCSQLTEST' # cSpell: disable-line + # Features = 'SQLENGINE' + # SqlSysAdminAccounts = @( + # ('{0}\SqlAdmin' -f $ComputerName) + # ) + # SqlSvcAccount = '{0}\svc-SqlPrimary' -f $ComputerName + # SqlSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + # SqlSvcStartupType = 'Automatic' + # AgtSvcAccount = '{0}\svc-SqlAgentPri' -f $ComputerName + # AgtSvcPassword = ConvertTo-SecureString -String 'yig-C^Equ3' -AsPlainText -Force + # AgtSvcStartupType = 'Automatic' + # BrowserSvcStartupType = 'Automatic' + # SecurityMode = 'SQL' + # SAPwd = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + # SqlCollation = 'Finnish_Swedish_CI_AS' + # InstallSharedDir = 'C:\Program Files\Microsoft SQL Server' + # InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server' + # NpEnabled = $true + # TcpEnabled = $true + # MediaPath = $IsoDrivePath + # Verbose = $true + # ErrorAction = 'Stop' + # Force = $true + # } + + # Install-SqlDscServer @installSqlDscServerParameters + # } + + # $invokeCommandUsername = 'SqlInstall' # Using computer name as NetBIOS name throw exception. + # $invokeCommandPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force + # $invokeCommandCredential = New-Object System.Management.Automation.PSCredential ($invokeCommandUsername, $invokeCommandPassword) + + # # Runs command as SqlInstall user. + # Invoke-Command -ComputerName 'localhost' -Credential $invokeCommandCredential -ScriptBlock $installScriptBlock -ArgumentList @( + # $env:IsoDrivePath, # Already set by the prerequisites tests + # (Get-ComputerName), + # $modulePath + # ) + # } | Should -Not -Throw } It 'Should have installed the SQL Server database engine' { @@ -308,7 +304,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL20 $sqlServerService = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' $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/Invoke-SqlDscQuery.Integration.Tests.ps1 b/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 index a4f46ff582..4389feb941 100644 --- a/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Invoke-SqlDscQuery.Integration.Tests.ps1 @@ -79,15 +79,11 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes Context 'When executing a query using ServerObject parameter set' { Context 'When executing a query without returning results' { It 'Should execute the query without throwing (using Force parameter)' { - { - Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'UPDATE TestTable SET Value = 500 WHERE ID = 1' -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'UPDATE TestTable SET Value = 500 WHERE ID = 1' -Force -ErrorAction 'Stop' } It 'Should execute the query without throwing (using Confirm:$false parameter)' { - { - Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'UPDATE TestTable SET Value = 600 WHERE ID = 2' -Confirm:$false -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'UPDATE TestTable SET Value = 600 WHERE ID = 2' -Confirm:$false -ErrorAction 'Stop' } } @@ -112,15 +108,11 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes Context 'When using optional parameters with ServerObject parameter set' { It 'Should execute query with custom StatementTimeout' { - { - Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'SELECT COUNT(*) FROM TestTable' -StatementTimeout 30 -PassThru -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query 'SELECT COUNT(*) FROM TestTable' -StatementTimeout 30 -PassThru -Force -ErrorAction 'Stop' } It 'Should execute query with RedactText parameter' { - { - Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query "SELECT * FROM TestTable WHERE Name = 'SensitiveData'" -RedactText @('SensitiveData') -PassThru -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerObject $script:serverObject -DatabaseName $script:testDatabaseName -Query "SELECT * FROM TestTable WHERE Name = 'SensitiveData'" -RedactText @('SensitiveData') -PassThru -Force -ErrorAction 'Stop' } } @@ -138,9 +130,7 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes Context 'When executing a query using ByServerName parameter set' { Context 'When executing a query without returning results' { It 'Should execute the query without throwing' { - { - Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'UPDATE TestTable SET Value = 700 WHERE ID = 3' -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'UPDATE TestTable SET Value = 700 WHERE ID = 3' -Force -ErrorAction 'Stop' } } @@ -157,9 +147,7 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes Context 'When using optional parameters with ByServerName parameter set' { # Using Encrypt in the CI is not possible until we add the required support (certificate) in the CI. It 'Should execute query with Encrypt parameter' -Skip { - { - Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -Encrypt -PassThru -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -Encrypt -PassThru -Force -ErrorAction 'Stop' } It 'Should execute query with LoginType parameter' { @@ -167,15 +155,11 @@ INSERT INTO TestTable (Name, Value) VALUES ('Test1', 100), ('Test2', 200), ('Tes $sqlLoginPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $sqlLoginCredential = [System.Management.Automation.PSCredential]::new('sa', $sqlLoginPassword) - { - Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $sqlLoginCredential -LoginType 'SqlLogin' -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -PassThru -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $sqlLoginCredential -LoginType 'SqlLogin' -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -PassThru -Force -ErrorAction 'Stop' } It 'Should execute query with custom StatementTimeout' { - { - Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -StatementTimeout 60 -PassThru -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Invoke-SqlDscQuery -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -DatabaseName $script:testDatabaseName -Query 'SELECT 1 as TestValue' -StatementTimeout 60 -PassThru -Force -ErrorAction 'Stop' } } } diff --git a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 index 9b0689fc0c..7a9cb764c6 100644 --- a/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAgentAlert.Integration.Tests.ps1 @@ -64,7 +64,7 @@ Describe 'New-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 } It 'Should create alert with severity' { - $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 14 -ErrorAction Stop + $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 14 -ErrorAction 'Stop' $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' $alert | Should -Not -BeNullOrEmpty @@ -84,7 +84,7 @@ END '@ $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $addMessageQuery -Verbose -Force -ErrorAction 'Stop' - $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50002 -ErrorAction Stop + $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50002 -ErrorAction 'Stop' $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' $alert | Should -Not -BeNullOrEmpty @@ -93,7 +93,7 @@ END } It 'Should return alert object when PassThru is specified' { - $result = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_PassThruAlert' -Severity 16 -PassThru -ErrorAction Stop + $result = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_PassThruAlert' -Severity 16 -PassThru -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be 'IntegrationTest_PassThruAlert' @@ -102,15 +102,15 @@ END It 'Should throw error when alert already exists' { # First create the alert - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 15 -ErrorAction Stop + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 15 -ErrorAction 'Stop' # Try to create it again - should throw - { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 14 -ErrorAction Stop } | + { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_DuplicateAlert' -Severity 14 -ErrorAction 'Stop' } | Should -Throw } It 'Should throw error when both Severity and MessageId are specified' { - { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_InvalidAlert' -Severity 16 -MessageId 50001 -ErrorAction Stop } | + { $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_InvalidAlert' -Severity 16 -MessageId 50001 -ErrorAction 'Stop' } | Should -Throw } } diff --git a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 index 5b163a8e85..78de6c53ba 100644 --- a/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscAudit.Integration.Tests.ps1 @@ -39,7 +39,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create a temporary directory for file audits if it doesn't exist $script:testAuditPath = 'C:\Temp\SqlDscTestAudits' @@ -56,14 +56,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', foreach ($audit in $testAudits) { - try - { - Remove-SqlDscAudit -AuditObject $audit -Force -ErrorAction 'SilentlyContinue' - } - catch - { - # Ignore cleanup errors - } + $null = Remove-SqlDscAudit -AuditObject $audit -Force -ErrorAction 'SilentlyContinue' } Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject @@ -90,7 +83,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create an application log audit successfully' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName @@ -98,7 +91,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' # Verify the audit exists in the server - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit | Should -Not -BeNullOrEmpty $createdAudit.Name | Should -Be $script:testAuditName $createdAudit.DestinationType | Should -Be 'ApplicationLog' @@ -107,20 +100,20 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should create a security log audit successfully' { $script:testAuditName = 'SqlDscTestAudit_SecLog_' + (Get-Random) - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName $result.DestinationType | Should -Be 'SecurityLog' # Verify the audit exists in the server - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit | Should -Not -BeNullOrEmpty $createdAudit.DestinationType | Should -Be 'SecurityLog' } It 'Should support PassThru parameter' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' @@ -143,7 +136,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit successfully' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName @@ -151,27 +144,27 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $result.FilePath.TrimEnd('\', '/') | Should -Be $script:testAuditPath.TrimEnd('\', '/') # Verify the audit exists in the server - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit | Should -Not -BeNullOrEmpty $createdAudit.DestinationType | Should -Be 'File' $createdAudit.FilePath.TrimEnd('\', '/') | Should -Be $script:testAuditPath.TrimEnd('\', '/') } It 'Should create a file audit with maximum file size' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.MaximumFileSize | Should -Be 100 $result.MaximumFileSizeUnit | Should -Be 'MB' # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.MaximumFileSize | Should -Be 100 $createdAudit.MaximumFileSizeUnit | Should -Be 'MB' } It 'Should create a file audit with maximum files and reserve disk space' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -MaximumFileSize 50 -MaximumFileSizeUnit 'Megabyte' -ReserveDiskSpace -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 5 -MaximumFileSize 50 -MaximumFileSizeUnit 'Megabyte' -ReserveDiskSpace -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.MaximumFiles | Should -Be 5 @@ -180,7 +173,7 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $result.ReserveDiskSpace | Should -BeTrue # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.MaximumFiles | Should -Be 5 $createdAudit.MaximumFileSize | Should -Be 50 $createdAudit.MaximumFileSizeUnit | Should -Be 'MB' @@ -188,13 +181,13 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create a file audit with maximum rollover files' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 10 -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 10 -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.MaximumRolloverFiles | Should -Be 10 # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.MaximumRolloverFiles | Should -Be 10 } } @@ -214,60 +207,60 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should create an audit with OnFailure setting' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'Continue' -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'Continue' -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.OnFailure | Should -Be 'Continue' # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.OnFailure | Should -Be 'Continue' } It 'Should create an audit with QueueDelay setting' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 5000 -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 5000 -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.QueueDelay | Should -Be 5000 # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.QueueDelay | Should -Be 5000 } It 'Should create an audit with AuditGuid setting' { $testGuid = [System.Guid]::NewGuid().ToString() - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $testGuid -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $testGuid -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Guid | Should -Be $testGuid # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.Guid | Should -Be $testGuid } It 'Should create an audit with AuditFilter setting' { $testFilter = "([database_name] = 'master')" $expectedFilter = "([database_name]='master')" # SQL Server normalizes the filter by removing spaces - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $testFilter -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $testFilter -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Filter | Should -Be $expectedFilter # Verify the audit exists with correct properties - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit.Filter | Should -Be $expectedFilter } It 'Should support Refresh parameter' { - $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Refresh -PassThru -Force -ErrorAction Stop + $result = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Refresh -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName # Verify the audit exists - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit | Should -Not -BeNullOrEmpty } } @@ -287,13 +280,13 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should support pipeline input with server object' { - $result = $script:serverObject | New-SqlDscAudit -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop + $result = $script:serverObject | New-SqlDscAudit -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testAuditName # Verify the audit exists - $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $createdAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $createdAudit | Should -Not -BeNullOrEmpty } } @@ -314,17 +307,17 @@ Describe 'New-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should throw error when trying to create an audit that already exists' { # First, create an audit - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' # Then try to create another audit with the same name - { New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop } | + { New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } | Should -Throw } 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 } | + { 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 c0146e2a32..4f471d8765 100644 --- a/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1 @@ -39,7 +39,7 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Test database names $script:testDatabaseName = 'SqlDscTestDatabase_' + (Get-Random) @@ -65,32 +65,32 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 Context 'When creating a new database' { It 'Should create a database successfully with minimal parameters' { - $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction Stop + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testDatabaseName $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Database' # Verify the database exists - $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction Stop + $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'Stop' $createdDb | Should -Not -BeNullOrEmpty } It 'Should create a database with specified properties' { - $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameWithProperties -RecoveryModel 'Simple' -Force -ErrorAction Stop + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameWithProperties -RecoveryModel 'Simple' -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:testDatabaseNameWithProperties $result.RecoveryModel | Should -Be 'Simple' # Verify the database exists with correct properties - $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameWithProperties -ErrorAction Stop + $createdDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameWithProperties -ErrorAction 'Stop' $createdDb | Should -Not -BeNullOrEmpty $createdDb.RecoveryModel | Should -Be 'Simple' } It 'Should throw error when trying to create a database that already exists' { - { New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction Stop } | + { New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' } | Should -Throw } } @@ -107,7 +107,7 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 $dbToRemove = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:refreshTestDbName -ErrorAction 'SilentlyContinue' if ($dbToRemove) { - $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force + $null = Remove-SqlDscDatabase -DatabaseObject $dbToRemove -Force -ErrorAction 'Stop' } } } @@ -115,7 +115,7 @@ Describe 'New-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2019 It 'Should refresh the database collection before creating' { $script:refreshTestDbName = 'SqlDscTestRefresh_' + (Get-Random) - $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:refreshTestDbName -Refresh -Force -ErrorAction Stop + $result = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:refreshTestDbName -Refresh -Force -ErrorAction 'Stop' $result | Should -Not -BeNullOrEmpty $result.Name | Should -Be $script:refreshTestDbName diff --git a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 index 35babc7248..a1f16969c0 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentAlert.Integration.Tests.ps1 @@ -52,9 +52,9 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ Context 'When removing by ServerObject' { It 'Should remove alert' { # Create alert for this test - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert' -Severity 16 -ErrorAction Stop + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert' -Severity 16 -ErrorAction 'Stop' - $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert' -Force -ErrorAction Stop + $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert' -Force -ErrorAction 'Stop' $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert' $alert | Should -BeNull @@ -64,10 +64,10 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ Context 'When removing by AlertObject' { It 'Should remove alert' { # Create a new alert for this test - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert2' -Severity 16 -ErrorAction Stop + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert2' -Severity 16 -ErrorAction 'Stop' $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert2' - $null = $alert | Remove-SqlDscAgentAlert -Force -ErrorAction Stop + $null = $alert | Remove-SqlDscAgentAlert -Force -ErrorAction 'Stop' $removedAlert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_RemoveAlert2' $removedAlert | Should -BeNull @@ -76,7 +76,7 @@ Describe 'Remove-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ Context 'When alert does not exist' { It 'Should not throw error' { - $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'NonExistentAlert' -Force -ErrorAction Stop + $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'NonExistentAlert' -Force -ErrorAction 'Stop' } } } diff --git a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 index e7b0e0127d..0ddbe76390 100644 --- a/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAgentOperator.Integration.Tests.ps1 @@ -47,7 +47,7 @@ Describe 'Remove-SqlDscAgentOperator' -Tag 'Integration_SQL2017', 'Integration_S $mockSqlAdministratorPassword = ConvertTo-SecureString -String 'P@ssw0rd1' -AsPlainText -Force $mockSqlAdministratorCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $mockSqlAdministratorCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $mockSqlAdministratorCredential -ErrorAction 'Stop' } AfterAll { diff --git a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 index 5cffc100c2..332b3472e2 100644 --- a/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscAudit.Integration.Tests.ps1 @@ -39,7 +39,7 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' } AfterAll { @@ -50,16 +50,16 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 BeforeEach { # Create a test audit for each test $script:testAuditName = 'SqlDscTestRemoveAudit_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } It 'Should remove an audit successfully' { # Verify audit exists before removal - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty # Remove the audit - $null = Remove-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction Stop + $null = Remove-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Force -ErrorAction 'Stop' # Verify audit no longer exists $removedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' @@ -67,17 +67,17 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } It 'Should throw error when trying to remove non-existent audit' { - { Remove-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -Force -ErrorAction Stop } | + { Remove-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should support the Refresh parameter' { # Verify audit exists before removal - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty # Remove the audit with Refresh parameter - $null = Remove-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Refresh -Force -ErrorAction Stop + $null = Remove-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Refresh -Force -ErrorAction 'Stop' # Verify audit no longer exists $removedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'SilentlyContinue' @@ -89,15 +89,15 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 BeforeEach { # Create a test audit for each test $script:testAuditNameForObject = 'SqlDscTestRemoveAuditObj_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } It 'Should remove an audit using audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty # Remove the audit using audit object - $null = Remove-SqlDscAudit -AuditObject $auditObject -Force -ErrorAction Stop + $null = Remove-SqlDscAudit -AuditObject $auditObject -Force -ErrorAction 'Stop' # Verify audit no longer exists $removedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'SilentlyContinue' @@ -105,11 +105,11 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 } It 'Should support pipeline input with audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty # Remove the audit using pipeline - $auditObject | Remove-SqlDscAudit -Force -ErrorAction Stop + $auditObject | Remove-SqlDscAudit -Force -ErrorAction 'Stop' # Verify audit no longer exists $removedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'SilentlyContinue' @@ -121,16 +121,16 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 BeforeEach { # Create a test audit for each test $script:testAuditNameForPipeline = 'SqlDscTestRemoveAuditPipe_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } It 'Should support pipeline input with server object' { # Verify audit exists before removal - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty # Remove the audit using pipeline with server object - $script:serverObject | Remove-SqlDscAudit -Name $script:testAuditNameForPipeline -Force -ErrorAction Stop + $script:serverObject | Remove-SqlDscAudit -Name $script:testAuditNameForPipeline -Force -ErrorAction 'Stop' # Verify audit no longer exists $removedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'SilentlyContinue' @@ -148,7 +148,7 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 foreach ($auditName in $script:testAuditNames) { - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } } @@ -156,14 +156,14 @@ Describe 'Remove-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019 # Verify audits exist before removal foreach ($auditName in $script:testAuditNames) { - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty } # Remove the audits foreach ($auditName in $script:testAuditNames) { - $null = Remove-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction Stop + $null = Remove-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -Force -ErrorAction 'Stop' } # Verify audits no longer exist diff --git a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 index 3302c61c87..162fdbb865 100644 --- a/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscDatabase.Integration.Tests.ps1 @@ -39,7 +39,7 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' } AfterAll { @@ -50,16 +50,16 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 BeforeEach { # Create a test database for each test $script:testDatabaseName = 'SqlDscTestRemoveDatabase_' + (Get-Random) - $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction Stop + $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' } It 'Should remove a database successfully' { # Verify database exists before removal - $existingDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction Stop + $existingDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'Stop' $existingDb | Should -Not -BeNullOrEmpty # Remove the database - $null = Remove-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction Stop + $null = Remove-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop' # Verify database no longer exists $removedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -ErrorAction 'SilentlyContinue' @@ -67,7 +67,7 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 } It 'Should throw error when trying to remove non-existent database' { - { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'NonExistentDatabase' -Force -ErrorAction Stop } | + { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'NonExistentDatabase' -Force -ErrorAction 'Stop' } | Should -Throw } } @@ -76,15 +76,15 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 BeforeEach { # Create a test database for each test $script:testDatabaseNameForObject = 'SqlDscTestRemoveDatabaseObj_' + (Get-Random) - $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -Force -ErrorAction Stop + $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -Force -ErrorAction 'Stop' } It 'Should remove a database using database object' { - $databaseObject = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction Stop + $databaseObject = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction 'Stop' $databaseObject | Should -Not -BeNullOrEmpty # Remove the database using database object - $null = Remove-SqlDscDatabase -DatabaseObject $databaseObject -Force -ErrorAction Stop + $null = Remove-SqlDscDatabase -DatabaseObject $databaseObject -Force -ErrorAction 'Stop' # Verify database no longer exists $removedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction 'SilentlyContinue' @@ -92,11 +92,11 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 } It 'Should support pipeline input with database object' { - $databaseObject = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction Stop + $databaseObject = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction 'Stop' $databaseObject | Should -Not -BeNullOrEmpty # Remove the database using pipeline - $databaseObject | Remove-SqlDscDatabase -Force -ErrorAction Stop + $databaseObject | Remove-SqlDscDatabase -Force -ErrorAction 'Stop' # Verify database no longer exists $removedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameForObject -ErrorAction 'SilentlyContinue' @@ -106,22 +106,22 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 Context 'When attempting to remove system databases' { It 'Should throw error when trying to remove master database' { - { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'master' -Force -ErrorAction Stop } | + { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'master' -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should throw error when trying to remove model database' { - { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'model' -Force -ErrorAction Stop } | + { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'model' -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should throw error when trying to remove msdb database' { - { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'msdb' -Force -ErrorAction Stop } | + { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'msdb' -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should throw error when trying to remove tempdb database' { - { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'tempdb' -Force -ErrorAction Stop } | + { Remove-SqlDscDatabase -ServerObject $script:serverObject -Name 'tempdb' -Force -ErrorAction 'Stop' } | Should -Throw } } @@ -130,12 +130,12 @@ Describe 'Remove-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL2 BeforeEach { # Create a test database for each test $script:testDatabaseNameRefresh = 'SqlDscTestRemoveDatabaseRefresh_' + (Get-Random) - $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameRefresh -Force -ErrorAction Stop + $null = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameRefresh -Force -ErrorAction 'Stop' } It 'Should refresh the database collection before removing' { # Remove the database with refresh - $null = Remove-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameRefresh -Refresh -Force -ErrorAction Stop + $null = Remove-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameRefresh -Refresh -Force -ErrorAction 'Stop' # Verify database no longer exists $removedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseNameRefresh -ErrorAction 'SilentlyContinue' diff --git a/tests/Integration/Commands/Remove-SqlDscTraceFlag.Integration.Tests.ps1 b/tests/Integration/Commands/Remove-SqlDscTraceFlag.Integration.Tests.ps1 index eac60e9d4a..865b2585d2 100644 --- a/tests/Integration/Commands/Remove-SqlDscTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Remove-SqlDscTraceFlag.Integration.Tests.ps1 @@ -42,14 +42,10 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL Context 'When removing trace flags using ServerName and InstanceName parameters' { It 'Should remove a single trace flag without error' { # Arrange - Add a test trace flag first - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Act - Remove the trace flag - { - Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Assert - Verify the trace flag was removed $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -58,14 +54,10 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL It 'Should remove multiple trace flags without error' { # Arrange - Add test trace flags first - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' # Act - Remove the trace flags - { - Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' # Assert - Verify the trace flags were removed $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -77,9 +69,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL It 'Should not error when removing non-existent trace flags' { # Act & Assert - Removing a trace flag that doesn't exist should not throw - { - Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag 9999 -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag 9999 -Force -ErrorAction 'Stop' } It 'Should preserve other existing trace flags when removing specific ones' { @@ -88,14 +78,10 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL $flagsToRemove = @(4199, 1118) $flagsToKeep = @(3226, 2544) - { - Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $allTestFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $allTestFlags -Force -ErrorAction 'Stop' # Act - Remove only some of the trace flags - { - Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $flagsToRemove -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $flagsToRemove -Force -ErrorAction 'Stop' # Assert - Verify correct flags were removed and others preserved $currentTraceFlags = Get-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -ErrorAction 'Stop' @@ -111,7 +97,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL } # Clean up - Remove remaining test flags - Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $flagsToKeep -Force -ErrorAction 'SilentlyContinue' + $null = Remove-SqlDscTraceFlag -ServerName $script:mockComputerName -InstanceName $script:mockInstanceName -TraceFlag $flagsToKeep -Force -ErrorAction 'Stop' } } @@ -123,14 +109,10 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL It 'Should remove a single trace flag using ServiceObject parameter' { # Arrange - Add a test trace flag first - { - Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Act - Remove the trace flag - { - Remove-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:singleTestTraceFlag -Force -ErrorAction 'Stop' # Assert - Verify the trace flag was removed $currentTraceFlags = Get-SqlDscTraceFlag -ServiceObject $script:serviceObject -ErrorAction 'Stop' @@ -139,14 +121,10 @@ Describe 'Remove-SqlDscTraceFlag' -Tag @('Integration_SQL2017', 'Integration_SQL It 'Should remove multiple trace flags using ServiceObject parameter' { # Arrange - Add test trace flags first - { - Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' # Act - Remove the trace flags - { - Remove-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' - } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $script:serviceObject -TraceFlag $script:testTraceFlags -Force -ErrorAction 'Stop' # Assert - Verify the trace flags were removed $currentTraceFlags = Get-SqlDscTraceFlag -ServiceObject $script:serviceObject -ErrorAction 'Stop' diff --git a/tests/Integration/Commands/Repair-SqlDscBIReportServer.Integration.Tests.ps1 b/tests/Integration/Commands/Repair-SqlDscBIReportServer.Integration.Tests.ps1 index 85a08bbae2..69f87f63ca 100644 --- a/tests/Integration/Commands/Repair-SqlDscBIReportServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Repair-SqlDscBIReportServer.Integration.Tests.ps1 @@ -50,20 +50,18 @@ Describe 'Repair-SqlDscBIReportServer' -Tag @('Integration_PowerBI') { Context 'When repairing BI Report Server' { It 'Should run the command without throwing' { - { - # Set splatting parameters for Repair-SqlDscBIReportServer - $repairSqlDscBIReportServerParameters = @{ - AcceptLicensingTerms = $true - MediaPath = $powerBIReportServerExecutable - LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Repair.log' - SuppressRestart = $true - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } + # Set splatting parameters for Repair-SqlDscBIReportServer + $repairSqlDscBIReportServerParameters = @{ + AcceptLicensingTerms = $true + MediaPath = $powerBIReportServerExecutable + LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Repair.log' + SuppressRestart = $true + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } - Repair-SqlDscBIReportServer @repairSqlDscBIReportServerParameters - } | Should -Not -Throw + $null = Repair-SqlDscBIReportServer @repairSqlDscBIReportServerParameters } It 'Should still have a Power BI Report Server service running after repair' { diff --git a/tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1 b/tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1 index 1c452e0557..36dc75f12b 100644 --- a/tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1 @@ -50,20 +50,18 @@ Describe 'Repair-SqlDscReportingService' -Tag @('Integration_SQL2017', 'Integrat Context 'When repairing Reporting Services' { It 'Should run the repair command without throwing' { - { - # Set splatting parameters for Repair-SqlDscReportingService - $repairSqlDscReportingServiceParameters = @{ - AcceptLicensingTerms = $true - MediaPath = $reportingServicesExecutable - LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Repair.log' - SuppressRestart = $true - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } + # Set splatting parameters for Repair-SqlDscReportingService + $repairSqlDscReportingServiceParameters = @{ + AcceptLicensingTerms = $true + MediaPath = $reportingServicesExecutable + LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Repair.log' + SuppressRestart = $true + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } - Repair-SqlDscReportingService @repairSqlDscReportingServiceParameters - } | Should -Not -Throw + $null = Repair-SqlDscReportingService @repairSqlDscReportingServiceParameters } It 'Should still have the SQL Server Reporting Services service running after repair' { diff --git a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 index 66d0b8f409..e525b28693 100644 --- a/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAgentAlert.Integration.Tests.ps1 @@ -43,11 +43,11 @@ Describe 'Set-SqlDscAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQL20 $script:sqlServerObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create a test alert for updating - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction Stop + $null = $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop' } AfterAll { - $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Force -ErrorAction 'SilentlyContinue' + $null = $script:sqlServerObject | Remove-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Force -ErrorAction 'Stop' # Disconnect from the SQL Server Disconnect-SqlDscDatabaseEngine -ServerObject $script:sqlServerObject @@ -72,7 +72,7 @@ BEGIN N'Mock message 50003'; END '@ - $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $addMessageQuery -Verbose -Force -ErrorAction 'Stop' + $null = $script:sqlServerObject | Invoke-SqlDscQuery -DatabaseName 'master' -Query $addMessageQuery -Verbose -Force -ErrorAction 'Stop' $null = $script:sqlServerObject | Set-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -MessageId 50003 -ErrorAction 'Stop' -Force @@ -84,7 +84,7 @@ END It 'Should update alert using AlertObject parameter set' { # First reset to severity for this test - $script:sqlServerObject | Set-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop' -Force + $null = $script:sqlServerObject | Set-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' -Severity 14 -ErrorAction 'Stop' -Force $alert = $script:sqlServerObject | Get-SqlDscAgentAlert -Name 'IntegrationTest_UpdateAlert' diff --git a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 index cc60f09b15..bd15e073ac 100644 --- a/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Set-SqlDscAudit.Integration.Tests.ps1 @@ -39,7 +39,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' } AfterAll { @@ -50,7 +50,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', BeforeEach { # Create a test audit for each test $script:testAuditName = 'SqlDscTestSetAudit_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } AfterEach { @@ -60,85 +60,85 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should modify audit QueueDelay property successfully' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $originalQueueDelay = $originalAudit.QueueDelay $newQueueDelay = 5000 # Modify the audit - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay $modifiedAudit.QueueDelay | Should -Not -Be $originalQueueDelay } It 'Should modify audit OnFailure property successfully' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $originalOnFailure = $originalAudit.OnFailure $newOnFailure = 'FailOperation' # Modify the audit - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -OnFailure $newOnFailure -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -OnFailure $newOnFailure -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $modifiedAudit.OnFailure | Should -Be $newOnFailure $modifiedAudit.OnFailure | Should -Not -Be $originalOnFailure } It 'Should modify audit AuditFilter property successfully' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $newAuditFilter = "([server_principal_name] like '%test%')" # Modify the audit - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -AuditFilter $newAuditFilter -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -AuditFilter $newAuditFilter -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $modifiedAudit.Filter | Should -Be $newAuditFilter } It 'Should modify audit AuditGuid property when AllowAuditGuidChange is specified' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $originalGuid = $originalAudit.Guid $newGuid = [System.Guid]::NewGuid().ToString() # Modify the audit with AllowAuditGuidChange parameter - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -AuditGuid $newGuid -AllowAuditGuidChange -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -AuditGuid $newGuid -AllowAuditGuidChange -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $modifiedAudit.Guid | Should -Be $newGuid $modifiedAudit.Guid | Should -Not -Be $originalGuid } It 'Should throw an error when trying to change AuditGuid without AllowAuditGuidChange parameter' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $newGuid = [System.Guid]::NewGuid().ToString() # Attempt to modify the audit GUID without AllowAuditGuidChange should throw an error - { Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -AuditGuid $newGuid -Force -ErrorAction Stop } | + { Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -AuditGuid $newGuid -Force -ErrorAction 'Stop' } | Should -Throw } It 'Should support multiple property modifications in one call' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $newQueueDelay = 3000 @@ -146,10 +146,10 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', $newAuditFilter = "([server_principal_name] like '%integration%')" # Modify multiple properties - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -OnFailure $newOnFailure -AuditFilter $newAuditFilter -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -OnFailure $newOnFailure -AuditFilter $newAuditFilter -Force -ErrorAction 'Stop' # Verify all properties were modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay $modifiedAudit.OnFailure | Should -Be $newOnFailure $modifiedAudit.Filter | Should -Be $newAuditFilter @@ -157,28 +157,28 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should support the Refresh parameter' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $newQueueDelay = 4000 # Modify the audit with Refresh parameter - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -Refresh -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -Refresh -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay } It 'Should support the PassThru parameter' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $newQueueDelay = 6000 # Modify the audit with PassThru parameter - $result = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -PassThru -Force -ErrorAction Stop + $result = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -QueueDelay $newQueueDelay -PassThru -Force -ErrorAction 'Stop' # Verify PassThru returns the audit object $result | Should -Not -BeNullOrEmpty @@ -188,7 +188,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should throw error when trying to modify non-existent audit' { - { Set-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -QueueDelay 5000 -Force -ErrorAction Stop } | + { Set-SqlDscAudit -ServerObject $script:serverObject -Name 'NonExistentAudit' -QueueDelay 5000 -Force -ErrorAction 'Stop' } | Should -Throw } } @@ -197,7 +197,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', BeforeEach { # Create a test audit for each test $script:testAuditNameForObject = 'SqlDscTestSetAuditObj_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } AfterEach { @@ -206,45 +206,45 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } It 'Should modify audit using audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $originalQueueDelay = $auditObject.QueueDelay $newQueueDelay = 7000 # Modify the audit using audit object - $null = Set-SqlDscAudit -AuditObject $auditObject -QueueDelay $newQueueDelay -Force -ErrorAction Stop + $null = Set-SqlDscAudit -AuditObject $auditObject -QueueDelay $newQueueDelay -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay $modifiedAudit.QueueDelay | Should -Not -Be $originalQueueDelay } It 'Should support pipeline input with audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $originalQueueDelay = $auditObject.QueueDelay $newQueueDelay = 8000 # Modify the audit using pipeline - $auditObject | Set-SqlDscAudit -QueueDelay $newQueueDelay -Force -ErrorAction Stop + $auditObject | Set-SqlDscAudit -QueueDelay $newQueueDelay -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay $modifiedAudit.QueueDelay | Should -Not -Be $originalQueueDelay } It 'Should support PassThru with audit object' { - $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction Stop + $auditObject = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForObject -ErrorAction 'Stop' $auditObject | Should -Not -BeNullOrEmpty $newQueueDelay = 9000 # Modify the audit using audit object with PassThru - $result = Set-SqlDscAudit -AuditObject $auditObject -QueueDelay $newQueueDelay -PassThru -Force -ErrorAction Stop + $result = Set-SqlDscAudit -AuditObject $auditObject -QueueDelay $newQueueDelay -PassThru -Force -ErrorAction 'Stop' # Verify PassThru returns the audit object $result | Should -Not -BeNullOrEmpty @@ -258,7 +258,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', BeforeEach { # Create a test audit for each test $script:testAuditNameForPipeline = 'SqlDscTestSetAuditPipe_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } AfterEach { @@ -268,17 +268,17 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', It 'Should support pipeline input with server object' { # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $originalQueueDelay = $originalAudit.QueueDelay $newQueueDelay = 10000 # Modify the audit using pipeline with server object - $script:serverObject | Set-SqlDscAudit -Name $script:testAuditNameForPipeline -QueueDelay $newQueueDelay -Force -ErrorAction Stop + $script:serverObject | Set-SqlDscAudit -Name $script:testAuditNameForPipeline -QueueDelay $newQueueDelay -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditNameForPipeline -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay $modifiedAudit.QueueDelay | Should -Not -Be $originalQueueDelay } @@ -297,7 +297,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', BeforeEach { # Create a test file audit for each test $script:testFileAuditName = 'SqlDscTestFileAudit_' + (Get-Random) - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -Path $script:tempAuditPath -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -Path $script:tempAuditPath -Force -ErrorAction 'Stop' } AfterEach { @@ -322,17 +322,17 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', } # Verify audit exists before modification - $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -ErrorAction Stop + $originalAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -ErrorAction 'Stop' $originalAudit | Should -Not -BeNullOrEmpty $originalAudit.DestinationType | Should -Be 'File' $originalPath = $originalAudit.FilePath # Modify the audit path - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -Path $newTempPath -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -Path $newTempPath -Force -ErrorAction 'Stop' # Verify audit was modified - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $script:testFileAuditName -ErrorAction 'Stop' $modifiedAudit.FilePath | Should -Be $newTempPath $modifiedAudit.FilePath | Should -Not -Be $originalPath @@ -354,7 +354,7 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', foreach ($auditName in $script:testAuditNames) { - $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction Stop + $null = New-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -LogType 'ApplicationLog' -Force -ErrorAction 'Stop' } } @@ -372,20 +372,20 @@ Describe 'Set-SqlDscAudit' -Tag @('Integration_SQL2017', 'Integration_SQL2019', # Verify audits exist before modification foreach ($auditName in $script:testAuditNames) { - $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $existingAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $existingAudit | Should -Not -BeNullOrEmpty } # Modify the audits foreach ($auditName in $script:testAuditNames) { - $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -QueueDelay $newQueueDelay -Force -ErrorAction Stop + $null = Set-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -QueueDelay $newQueueDelay -Force -ErrorAction 'Stop' } # Verify audits were modified foreach ($auditName in $script:testAuditNames) { - $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction Stop + $modifiedAudit = Get-SqlDscAudit -ServerObject $script:serverObject -Name $auditName -ErrorAction 'Stop' $modifiedAudit.QueueDelay | Should -Be $newQueueDelay } } diff --git a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 index bbec097631..ef8c083208 100644 --- a/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscAgentAlertProperty.Integration.Tests.ps1 @@ -43,8 +43,8 @@ Describe 'Test-SqlDscAgentAlertProperty' -Tag @('Integration_SQL2017', 'Integrat $script:sqlServerObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create test alerts for testing - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 16 -ErrorAction Stop - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50001 -ErrorAction Stop + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 16 -ErrorAction 'Stop' + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50001 -ErrorAction 'Stop' } AfterAll { diff --git a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 index c4c9d5419c..caf44ce2b3 100644 --- a/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Test-SqlDscIsAgentAlert.Integration.Tests.ps1 @@ -43,8 +43,8 @@ Describe 'Test-SqlDscIsAgentAlert' -Tag @('Integration_SQL2017', 'Integration_SQ $script:sqlServerObject = Connect-SqlDscDatabaseEngine -InstanceName $script:sqlServerInstance -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create test alerts for testing - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 16 -ErrorAction Stop - $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50001 -ErrorAction Stop + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_SeverityAlert' -Severity 16 -ErrorAction 'Stop' + $script:sqlServerObject | New-SqlDscAgentAlert -Name 'IntegrationTest_MessageIdAlert' -MessageId 50001 -ErrorAction 'Stop' } AfterAll { diff --git a/tests/Integration/Commands/Uninstall-SqlDscBIReportServer.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscBIReportServer.Integration.Tests.ps1 index 57fae5e921..7135552c56 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscBIReportServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscBIReportServer.Integration.Tests.ps1 @@ -50,19 +50,17 @@ Describe 'Uninstall-SqlDscBIReportServer' -Tag @('Integration_PowerBI') { Context 'When uninstalling BI Report Server' { It 'Should run the command without throwing' { - { - # Set splatting parameters for Uninstall-SqlDscBIReportServer - $uninstallSqlDscBIReportServerParameters = @{ - MediaPath = $powerBIReportServerExecutable - LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Uninstall.log' - SuppressRestart = $true - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } + # Set splatting parameters for Uninstall-SqlDscBIReportServer + $uninstallSqlDscBIReportServerParameters = @{ + MediaPath = $powerBIReportServerExecutable + LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Uninstall.log' + SuppressRestart = $true + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } - Uninstall-SqlDscBIReportServer @uninstallSqlDscBIReportServerParameters - } | Should -Not -Throw + $null = Uninstall-SqlDscBIReportServer @uninstallSqlDscBIReportServerParameters } It 'Should not have a Power BI Report Server service' { diff --git a/tests/Integration/Commands/Uninstall-SqlDscReportingService.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscReportingService.Integration.Tests.ps1 index cbac6079dc..25c424988b 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscReportingService.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscReportingService.Integration.Tests.ps1 @@ -50,19 +50,17 @@ Describe 'Uninstall-SqlDscReportingService' -Tag @('Integration_SQL2017', 'Integ Context 'When uninstalling Reporting Services' { It 'Should run the command without throwing' { - { - # Set splatting parameters for Uninstall-SqlDscReportingService - $uninstallSqlDscReportingServiceParameters = @{ - MediaPath = $reportingServicesExecutable - LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Uninstall.log' - SuppressRestart = $true - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } + # Set splatting parameters for Uninstall-SqlDscReportingService + $uninstallSqlDscReportingServiceParameters = @{ + MediaPath = $reportingServicesExecutable + LogPath = Join-Path -Path $script:temporaryFolder -ChildPath 'SSRS_Uninstall.log' + SuppressRestart = $true + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } - Uninstall-SqlDscReportingService @uninstallSqlDscReportingServiceParameters - } | Should -Not -Throw + $null = Uninstall-SqlDscReportingService @uninstallSqlDscReportingServiceParameters } It 'Should not have a SQL Server Reporting Services service' { diff --git a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 index a290d7b07a..e789a3e4db 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 @@ -43,19 +43,17 @@ Describe 'Uninstall-SqlDscServer' -Tag @('Integration_SQL2017', 'Integration_SQL Context 'When uninstalling a named instance' { It 'Should run the command without throwing' { - { - # Set splatting parameters for Uninstall-SqlDscServer - $uninstallSqlDscServerParameters = @{ - InstanceName = 'DSCSQLTEST' - Features = 'SQLENGINE' - MediaPath = $env:IsoDrivePath - Verbose = $true - ErrorAction = 'Stop' - Force = $true - } + # Set splatting parameters for Uninstall-SqlDscServer + $uninstallSqlDscServerParameters = @{ + InstanceName = 'DSCSQLTEST' + Features = 'SQLENGINE' + MediaPath = $env:IsoDrivePath + Verbose = $true + ErrorAction = 'Stop' + Force = $true + } - Uninstall-SqlDscServer @uninstallSqlDscServerParameters - } | Should -Not -Throw + $null = Uninstall-SqlDscServer @uninstallSqlDscServerParameters } It 'Should not have a named instance SQL Server service' { diff --git a/tests/Integration/Private/ConvertTo-AuditNewParameterSet.Integration.Tests.ps1 b/tests/Integration/Private/ConvertTo-AuditNewParameterSet.Integration.Tests.ps1 index 0a211a324c..b772ba2c51 100644 --- a/tests/Integration/Private/ConvertTo-AuditNewParameterSet.Integration.Tests.ps1 +++ b/tests/Integration/Private/ConvertTo-AuditNewParameterSet.Integration.Tests.ps1 @@ -45,7 +45,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra $script:mockSqlAdminCredential = [System.Management.Automation.PSCredential]::new($mockSqlAdministratorUserName, $mockSqlAdministratorPassword) - $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction Stop + $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop' # Create a temporary directory for file audits if it doesn't exist $script:testAuditPath = 'C:\Temp\SqlDscTestAudits' @@ -84,7 +84,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting an ApplicationLog audit' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_AppLog_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -126,7 +126,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting a SecurityLog audit' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_SecLog_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'SecurityLog' -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -150,7 +150,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting a File audit with basic properties' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_File_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -191,7 +191,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting a File audit with MaximumFileSize' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_FileSize_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFileSize 100 -MaximumFileSizeUnit 'Megabyte' -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -231,7 +231,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting a File audit with MaximumFiles and ReserveDiskSpace' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_MaxFiles_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 10 -MaximumFileSize 50 -MaximumFileSizeUnit 'Megabyte' -ReserveDiskSpace -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumFiles 10 -MaximumFileSize 50 -MaximumFileSizeUnit 'Megabyte' -ReserveDiskSpace -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -275,7 +275,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting a File audit with MaximumRolloverFiles' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_Rollover_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 15 -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -Path $script:testAuditPath -MaximumRolloverFiles 15 -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -315,7 +315,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting an audit with OnFailure setting' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_OnFailure_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'FailOperation' -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -OnFailure 'FailOperation' -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -353,7 +353,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra Context 'When converting an audit with QueueDelay setting' { BeforeAll { $script:testAuditName = 'SqlDscTestConvert_QueueDelay_' + (Get-Random) - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 3000 -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -QueueDelay 3000 -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -392,7 +392,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra BeforeAll { $script:testAuditName = 'SqlDscTestConvert_Guid_' + (Get-Random) $script:testGuid = [System.Guid]::NewGuid().ToString() - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $script:testGuid -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditGuid $script:testGuid -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -446,7 +446,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra $script:testAuditName = 'SqlDscTestConvert_Filter_' + (Get-Random) $script:testFilter = "([database_name] = 'master')" $script:expectedFilter = "([database_name]='master')" # SQL Server normalizes the filter - $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $script:testFilter -PassThru -Force -ErrorAction Stop + $script:testAudit = New-SqlDscAudit -ServerObject $script:serverObject -Name $script:testAuditName -LogType 'ApplicationLog' -AuditFilter $script:testFilter -PassThru -Force -ErrorAction 'Stop' } AfterAll { @@ -501,7 +501,7 @@ Describe 'ConvertTo-AuditNewParameterSet' -Tag @('Integration_SQL2017', 'Integra -AuditFilter $script:testFilter ` -PassThru ` -Force ` - -ErrorAction Stop + -ErrorAction 'Stop' } AfterAll { diff --git a/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 index 3c71fd4649..8046b82763 100644 --- a/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 @@ -68,32 +68,28 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -132,32 +128,28 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 index 3bfb498111..2aecba5e9d 100644 --- a/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -123,32 +119,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 index ccd267b269..ca79582a30 100644 --- a/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -123,32 +119,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -179,32 +171,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -235,32 +223,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 index 1b705ea867..54d6c8c76f 100644 --- a/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 @@ -87,26 +87,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -122,32 +120,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -176,32 +170,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -230,26 +220,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 index eba3346c2b..f0f405d005 100644 --- a/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 @@ -67,26 +67,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -102,32 +100,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -163,32 +157,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -222,32 +212,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -281,32 +267,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -342,32 +324,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 index de653c0e55..af5f63a27f 100644 --- a/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -128,32 +124,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -186,32 +178,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -244,32 +232,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -302,32 +286,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -360,32 +340,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -421,26 +397,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 index afff0eabc4..596dd67591 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -122,32 +118,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -177,32 +169,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 index 3782ad0a1f..9010d7de00 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -130,32 +126,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should return $true when Test-DscConfiguration is run' { @@ -175,32 +167,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 index 2e83c3200b..d74b952b15 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 @@ -67,26 +67,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -102,26 +100,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -137,26 +133,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -176,32 +170,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -251,32 +241,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -321,32 +307,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -390,32 +372,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -472,32 +450,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 index 0405748a87..6c781ab0da 100644 --- a/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 @@ -68,32 +68,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -134,32 +130,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -200,32 +192,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -271,32 +259,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -346,32 +330,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -411,32 +391,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -476,32 +452,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -541,32 +513,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -692,14 +660,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -728,27 +694,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -756,14 +718,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -792,14 +752,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -818,14 +776,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -866,14 +822,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -904,27 +858,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -932,14 +882,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -968,14 +916,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -994,14 +940,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1040,14 +984,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1078,27 +1020,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1106,14 +1044,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1141,14 +1077,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1167,14 +1101,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1209,14 +1141,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1246,27 +1176,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1274,14 +1200,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1308,14 +1232,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1334,14 +1256,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1391,14 +1311,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1441,27 +1359,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1469,14 +1383,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1523,14 +1435,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1549,14 +1459,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1603,14 +1511,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1656,27 +1562,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1684,14 +1586,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1735,14 +1635,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1761,14 +1659,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } diff --git a/tests/Integration/Resources/DSC_SqlDatabaseUser.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseUser.Integration.Tests.ps1 index 49faa0d323..d1c49c1c9a 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseUser.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseUser.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -131,32 +127,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -195,32 +187,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -259,32 +247,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -323,32 +307,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -387,32 +367,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -451,32 +427,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -515,32 +487,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 index 742ef0fa87..485b56da87 100644 --- a/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 @@ -67,31 +67,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -126,31 +122,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -181,31 +173,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -243,31 +231,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 index 015d3a281e..4cb2758a8f 100644 --- a/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 @@ -72,26 +72,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -107,32 +105,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -164,32 +158,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -222,32 +212,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -279,32 +265,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -335,11 +317,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName - { - $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString - $sqlConnection.Open() - $sqlConnection.Close() - } | Should -Not -Throw + $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString + $sqlConnection.Open() + $sqlConnection.Close() } It 'Should allow SQL Server, login username and password to connect to correct, SQL instance, default database' { @@ -352,20 +332,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;' -f $serverName, $instanceName, $userName, $password # Note: Not providing a database name - { - $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString - $sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection) + $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString + $sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection) - $sqlConnection.Open() - $sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $sqlCommand - $sqlDataSet = New-Object System.Data.DataSet - $sqlDataAdapter.Fill($sqlDataSet) | Out-Null - $sqlConnection.Close() + $sqlConnection.Open() + $sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $sqlCommand + $sqlDataSet = New-Object System.Data.DataSet + $sqlDataAdapter.Fill($sqlDataSet) | Out-Null + $sqlConnection.Close() - $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName + $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName - $script:CurrentDatabaseName = $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName - } | Should -Not -Throw + $script:CurrentDatabaseName = $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName $script:CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName @@ -385,32 +363,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -441,11 +415,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName - { - $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString - $sqlConnection.Open() - $sqlConnection.Close() - } | Should -Not -Throw + $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString + $sqlConnection.Open() + $sqlConnection.Close() } It 'Should allow SQL Server, login username and (changed) password to connect to correct, SQL instance, default database' { @@ -458,20 +430,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;' -f $serverName, $instanceName, $userName, $password # Note: Not providing a database name - { - $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString - $sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection) + $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString + $sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection) - $sqlConnection.Open() - $sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $sqlCommand - $sqlDataSet = New-Object System.Data.DataSet - $sqlDataAdapter.Fill($sqlDataSet) | Out-Null - $sqlConnection.Close() + $sqlConnection.Open() + $sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $sqlCommand + $sqlDataSet = New-Object System.Data.DataSet + $sqlDataAdapter.Fill($sqlDataSet) | Out-Null + $sqlConnection.Close() - $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName + $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName - $script:CurrentDatabaseName = $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName - } | Should -Not -Throw + $script:CurrentDatabaseName = $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName $script:CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName @@ -495,32 +465,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should re-compile and re-apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should return $true when Test-DscConfiguration is run' { @@ -536,11 +502,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName - { - $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString - $sqlConnection.Open() - $sqlConnection.Close() - } | Should -Not -Throw + $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString + $sqlConnection.Open() + $sqlConnection.Close() } } @@ -556,32 +520,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -621,26 +581,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should return $true when Test-DscConfiguration is run' { @@ -660,32 +618,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -725,26 +679,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should return $true when Test-DscConfiguration is run' { @@ -771,7 +723,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', ConfigurationData = $ConfigurationData } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters $startDscConfigurationParameters = @{ Path = $TestDrive @@ -804,32 +756,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -864,32 +812,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -925,32 +869,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -985,32 +925,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -1042,32 +978,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -1098,32 +1030,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -1154,16 +1082,14 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', # Uses the variable from the BeforeAll-block to fill the default database name. It ('Should be able to take the "" database offline without throwing') { - { - # Take database offline (closing any existing connections and transactions) before it is dropped in subsequent, 'CleanupDependencies' configuration/test - $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database=master;' -f $serverName, $instanceName, $userName, $password - $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString - $sqlStatement = 'ALTER DATABASE [{0}] SET OFFLINE WITH ROLLBACK IMMEDIATE' -f $defaultDbName - $sqlCommand = New-Object System.Data.SqlClient.SqlCommand($sqlStatement, $sqlConnection) - $sqlConnection.Open() - $sqlCommand.ExecuteNonQuery() - $sqlConnection.Close() - } | Should -Not -Throw + # Take database offline (closing any existing connections and transactions) before it is dropped in subsequent, 'CleanupDependencies' configuration/test + $sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database=master;' -f $serverName, $instanceName, $userName, $password + $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString + $sqlStatement = 'ALTER DATABASE [{0}] SET OFFLINE WITH ROLLBACK IMMEDIATE' -f $defaultDbName + $sqlCommand = New-Object System.Data.SqlClient.SqlCommand($sqlStatement, $sqlConnection) + $sqlConnection.Open() + $sqlCommand.ExecuteNonQuery() + $sqlConnection.Close() } } @@ -1179,26 +1105,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 index fbb3a51ff5..a342290d6f 100644 --- a/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 @@ -68,32 +68,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -133,32 +129,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -198,32 +190,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -268,32 +256,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -429,14 +413,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -464,27 +447,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -492,14 +472,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -527,14 +505,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -553,14 +529,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -601,14 +575,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -638,27 +610,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -666,14 +634,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -701,14 +667,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -727,14 +691,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -774,14 +736,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -811,27 +771,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -839,14 +795,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -873,14 +827,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -899,14 +851,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -942,14 +892,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -978,27 +926,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1006,14 +950,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1039,14 +981,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1065,14 +1005,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1122,14 +1060,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1171,27 +1107,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1199,14 +1131,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1252,14 +1182,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1278,14 +1206,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1332,14 +1258,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is not in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1384,27 +1308,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $false' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } @@ -1412,14 +1332,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Get' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Get' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -1462,14 +1380,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should run method Test() and return the state as $true' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Test' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Test' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.InDesiredState | Should -BeTrue } @@ -1488,14 +1404,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { - $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() + $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() - $mockInvokeDscResourceParameters.Method = 'Set' - $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty + $mockInvokeDscResourceParameters.Method = 'Set' + $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty - $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters $resourceCurrentState.RebootRequired | Should -BeFalse } diff --git a/tests/Integration/Resources/DSC_SqlProtocol.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlProtocol.Integration.Tests.ps1 index 9db1c5fcd9..ee14d06d4c 100644 --- a/tests/Integration/Resources/DSC_SqlProtocol.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlProtocol.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -123,32 +119,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 index f74db6d3a2..e96a41faae 100644 --- a/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 index 258b128374..b57087921f 100644 --- a/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 @@ -96,26 +96,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -131,32 +129,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -253,26 +247,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 index 451894b403..d0d3b71656 100644 --- a/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 @@ -144,32 +144,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -202,26 +198,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 index a70c86b756..1bfac3f322 100644 --- a/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 @@ -96,26 +96,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -131,38 +129,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName @@ -252,38 +246,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.UseSsl | Should -BeTrue @@ -326,38 +316,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.UseSsl | Should -BeFalse @@ -440,26 +426,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 index 17cdd868f9..c54d8e108f 100644 --- a/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 @@ -67,26 +67,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -102,32 +100,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -161,32 +155,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -220,32 +210,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -279,32 +265,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -338,26 +320,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 index 87111f8846..35f2a06a4f 100644 --- a/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 @@ -67,34 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -127,34 +121,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -187,34 +175,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -250,34 +232,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -315,34 +291,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -381,34 +351,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -441,34 +405,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -501,33 +459,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing an exception' { - { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | - Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It "Should have set the resource and all values should match for $($ConfigurationData.AllNodes.Role4Name)." { @@ -574,34 +527,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters - } | Should -Not -Throw + $null = & $configurationName @configurationParameters - { - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing an exception' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It "Should have set the resource and all values should match for $($ConfigurationData.AllNodes.Role5Name)." { diff --git a/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 index 6081d038a0..e544aad1d9 100644 --- a/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 @@ -67,31 +67,29 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - <# - The Script resource generate _a lot_ of verbose output - which slows down the build worker. Verbose is turned - off for this particular test. - #> - Verbose = $false - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + <# + The Script resource generate _a lot_ of verbose output + which slows down the build worker. Verbose is turned + off for this particular test. + #> + Verbose = $false + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -107,32 +105,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -204,32 +198,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -263,32 +253,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -360,26 +346,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 index 91a59f8765..3e5e00bb32 100644 --- a/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -164,32 +160,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -223,32 +215,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -320,26 +308,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 index 28409ef735..c057f88f2a 100644 --- a/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 @@ -81,32 +81,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -137,32 +133,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 index 28bffab4a3..90052dca0a 100644 --- a/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 @@ -76,26 +76,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -111,38 +109,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine @@ -166,38 +160,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent @@ -221,38 +211,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine @@ -276,38 +262,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent @@ -331,26 +313,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -366,38 +346,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine @@ -421,38 +397,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent @@ -476,38 +448,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine @@ -531,38 +499,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent diff --git a/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 index 42599adf64..54938c6104 100644 --- a/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 @@ -191,26 +191,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -226,26 +224,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } # Make sure the module was installed. @@ -276,32 +272,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -396,26 +388,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -441,32 +431,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -556,26 +542,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -601,32 +585,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -722,26 +702,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -767,32 +745,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -888,26 +862,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -923,26 +895,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } } diff --git a/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 index 402c635269..34a76fbb76 100644 --- a/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 @@ -67,32 +67,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -128,32 +124,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -190,32 +182,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -251,32 +239,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -313,32 +297,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -374,32 +354,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -435,32 +411,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { @@ -496,32 +468,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } - & $configurationName @configurationParameters + $null = & $configurationName @configurationParameters - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { diff --git a/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 index 5cc5e42a2d..f8fd36da01 100644 --- a/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 @@ -67,26 +67,24 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } } @@ -102,38 +100,34 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { - $configurationParameters = @{ - OutputPath = $TestDrive - # The variable $ConfigurationData was dot-sourced above. - ConfigurationData = $ConfigurationData - } - - & $configurationName @configurationParameters - - $startDscConfigurationParameters = @{ - Path = $TestDrive - ComputerName = 'localhost' - Wait = $true - Verbose = $true - Force = $true - ErrorAction = 'Stop' - } - - Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + $configurationParameters = @{ + OutputPath = $TestDrive + # The variable $ConfigurationData was dot-sourced above. + ConfigurationData = $ConfigurationData + } + + $null = & $configurationName @configurationParameters + + $startDscConfigurationParameters = @{ + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true + ErrorAction = 'Stop' + } + + $null = Start-DscConfiguration @startDscConfigurationParameters } It 'Should be able to call Get-DscConfiguration without throwing' { - { - $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction 'Stop' } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` - -and $_.ResourceId -eq $resourceId + -and $_.ResourceId -eq $resourceId } $resourceCurrentState.Features | Should -Be 'SQLENGINE' diff --git a/tests/QA/module.tests.ps1 b/tests/QA/module.tests.ps1 index d63bcadfa9..463822a9cb 100644 --- a/tests/QA/module.tests.ps1 +++ b/tests/QA/module.tests.ps1 @@ -40,7 +40,7 @@ BeforeDiscovery { $mut = Get-Module -Name $script:moduleName -ListAvailable | Select-Object -First 1 | - Import-Module -Force -ErrorAction Stop -PassThru + Import-Module -Force -ErrorAction 'Stop' -PassThru } BeforeAll { @@ -66,7 +66,7 @@ BeforeAll { -and $( try { - Test-ModuleManifest -Path $_.FullName -ErrorAction Stop + Test-ModuleManifest -Path $_.FullName -ErrorAction 'Stop' } catch { @@ -98,23 +98,23 @@ Describe 'Changelog Management' -Tag 'Changelog' { } It 'Changelog format compliant with keepachangelog format' -Skip:(![bool](Get-Command git -EA SilentlyContinue)) { - { Get-ChangelogData -Path (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction Stop } | Should -Not -Throw + $null = Get-ChangelogData -Path (Join-Path $ProjectPath 'CHANGELOG.md') -ErrorAction 'Stop' } It 'Changelog should have an Unreleased header' -Skip:$skipTest { - (Get-ChangelogData -Path (Join-Path -Path $ProjectPath -ChildPath 'CHANGELOG.md') -ErrorAction Stop).Unreleased | Should -Not -BeNullOrEmpty + (Get-ChangelogData -Path (Join-Path -Path $ProjectPath -ChildPath 'CHANGELOG.md') -ErrorAction 'Stop').Unreleased | Should -Not -BeNullOrEmpty } } Describe 'General module control' -Tags 'FunctionalQuality' { It 'Should import without errors' { - { Import-Module -Name $script:moduleName -Force -ErrorAction Stop } | Should -Not -Throw + $null = Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop' Get-Module -Name $script:moduleName | Should -Not -BeNullOrEmpty } It 'Should remove without error' { - { Remove-Module -Name $script:moduleName -ErrorAction Stop } | Should -Not -Throw + $null = Remove-Module -Name $script:moduleName -ErrorAction 'Stop' Get-Module $script:moduleName | Should -BeNullOrEmpty } diff --git a/tests/Unit/Classes/SqlAudit.Tests.ps1 b/tests/Unit/Classes/SqlAudit.Tests.ps1 index 70ea05d305..ba581c9611 100644 --- a/tests/Unit/Classes/SqlAudit.Tests.ps1 +++ b/tests/Unit/Classes/SqlAudit.Tests.ps1 @@ -70,7 +70,7 @@ Describe 'SqlAudit' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlAudit]::new() } | Should -Not -Throw + $null = [SqlAudit]::new() } } diff --git a/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 b/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 index 478072827d..5e6b7f0c3a 100644 --- a/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 +++ b/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 @@ -70,7 +70,7 @@ Describe 'SqlDatabasePermission' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlDatabasePermission]::new() } | Should -Not -Throw + $null = [SqlDatabasePermission]::new() } } @@ -1111,7 +1111,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { InModuleScope -ScriptBlock { { # This test does not pass any properties to set as it is not necessary for this test. - $mockSqlDatabasePermissionInstance.Modify(@{ + $null = $mockSqlDatabasePermissionInstance.Modify(@{ Permission = [DatabasePermission[]] @() }) } | Should -Throw -ExpectedMessage $mockErrorRecord @@ -1178,24 +1178,22 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlDatabasePermissionInstance.Modify(@{ - Permission = [DatabasePermission[]] @( - [DatabasePermission] @{ - State = 'Grant' - Permission = @('Connect') - } - [DatabasePermission] @{ - State = 'GrantWithGrant' - Permission = @('Update') - } - [DatabasePermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlDatabasePermissionInstance.Modify(@{ + Permission = [DatabasePermission[]] @( + [DatabasePermission] @{ + State = 'Grant' + Permission = @('Connect') + } + [DatabasePermission] @{ + State = 'GrantWithGrant' + Permission = @('Update') + } + [DatabasePermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Grants @@ -1268,24 +1266,22 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlDatabasePermissionInstance.Modify(@{ - Permission = [DatabasePermission[]] @( - [DatabasePermission] @{ - State = 'Grant' - Permission = @('Connect') - } - [DatabasePermission] @{ - State = 'GrantWithGrant' - Permission = @() - } - [DatabasePermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlDatabasePermissionInstance.Modify(@{ + Permission = [DatabasePermission[]] @( + [DatabasePermission] @{ + State = 'Grant' + Permission = @('Connect') + } + [DatabasePermission] @{ + State = 'GrantWithGrant' + Permission = @() + } + [DatabasePermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Revoking Grants @@ -1370,24 +1366,22 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlDatabasePermissionInstance.Modify(@{ - PermissionToInclude = [DatabasePermission[]] @( - [DatabasePermission] @{ - State = 'Grant' - Permission = @('Connect') - } - [DatabasePermission] @{ - State = 'GrantWithGrant' - Permission = @('Update') - } - [DatabasePermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlDatabasePermissionInstance.Modify(@{ + PermissionToInclude = [DatabasePermission[]] @( + [DatabasePermission] @{ + State = 'Grant' + Permission = @('Connect') + } + [DatabasePermission] @{ + State = 'GrantWithGrant' + Permission = @('Update') + } + [DatabasePermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Grants @@ -1462,24 +1456,22 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlDatabasePermissionInstance.Modify(@{ - PermissionToExclude = [DatabasePermission[]] @( - [DatabasePermission] @{ - State = 'Grant' - Permission = @('Connect') - } - [DatabasePermission] @{ - State = 'GrantWithGrant' - Permission = @('Update') - } - [DatabasePermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlDatabasePermissionInstance.Modify(@{ + PermissionToExclude = [DatabasePermission[]] @( + [DatabasePermission] @{ + State = 'Grant' + Permission = @('Connect') + } + [DatabasePermission] @{ + State = 'GrantWithGrant' + Permission = @('Update') + } + [DatabasePermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Revoking Grants @@ -1568,7 +1560,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { InModuleScope -ScriptBlock { { - $mockSqlDatabasePermissionInstance.Modify(@{ + $null = $mockSqlDatabasePermissionInstance.Modify(@{ Permission = [DatabasePermission[]] @( [DatabasePermission] @{ State = 'Grant' @@ -1661,7 +1653,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { InModuleScope -ScriptBlock { { - $mockSqlDatabasePermissionInstance.Modify(@{ + $null = $mockSqlDatabasePermissionInstance.Modify(@{ Permission = [DatabasePermission[]] @( [DatabasePermission] @{ State = 'Grant' diff --git a/tests/Unit/Classes/SqlPermission.Tests.ps1 b/tests/Unit/Classes/SqlPermission.Tests.ps1 index 939a87863b..8d3229430c 100644 --- a/tests/Unit/Classes/SqlPermission.Tests.ps1 +++ b/tests/Unit/Classes/SqlPermission.Tests.ps1 @@ -70,7 +70,7 @@ Describe 'SqlPermission' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlPermission]::new() } | Should -Not -Throw + $null = [SqlPermission]::new() } } @@ -1152,24 +1152,22 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlPermissionInstance.Modify(@{ - Permission = [ServerPermission[]] @( - [ServerPermission] @{ - State = 'Grant' - Permission = @('ConnectSql') - } - [ServerPermission] @{ - State = 'GrantWithGrant' - Permission = @('AlterAnyEndpoint') - } - [ServerPermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlPermissionInstance.Modify(@{ + Permission = [ServerPermission[]] @( + [ServerPermission] @{ + State = 'Grant' + Permission = @('ConnectSql') + } + [ServerPermission] @{ + State = 'GrantWithGrant' + Permission = @('AlterAnyEndpoint') + } + [ServerPermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Grants @@ -1241,24 +1239,22 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlPermissionInstance.Modify(@{ - Permission = [ServerPermission[]] @( - [ServerPermission] @{ - State = 'Grant' - Permission = @('ConnectSql') - } - [ServerPermission] @{ - State = 'GrantWithGrant' - Permission = @() - } - [ServerPermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlPermissionInstance.Modify(@{ + Permission = [ServerPermission[]] @( + [ServerPermission] @{ + State = 'Grant' + Permission = @('ConnectSql') + } + [ServerPermission] @{ + State = 'GrantWithGrant' + Permission = @() + } + [ServerPermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Revoking Grants @@ -1342,24 +1338,22 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlPermissionInstance.Modify(@{ - PermissionToInclude = [ServerPermission[]] @( - [ServerPermission] @{ - State = 'Grant' - Permission = @('ConnectSql') - } - [ServerPermission] @{ - State = 'GrantWithGrant' - Permission = @('AlterAnyEndpoint') - } - [ServerPermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlPermissionInstance.Modify(@{ + PermissionToInclude = [ServerPermission[]] @( + [ServerPermission] @{ + State = 'Grant' + Permission = @('ConnectSql') + } + [ServerPermission] @{ + State = 'GrantWithGrant' + Permission = @('AlterAnyEndpoint') + } + [ServerPermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Grants @@ -1433,24 +1427,22 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { - $mockSqlPermissionInstance.Modify(@{ - PermissionToExclude = [ServerPermission[]] @( - [ServerPermission] @{ - State = 'Grant' - Permission = @('ConnectSql') - } - [ServerPermission] @{ - State = 'GrantWithGrant' - Permission = @('AlterAnyEndpoint') - } - [ServerPermission] @{ - State = 'Deny' - Permission = @() - } - ) - }) - } | Should -Not -Throw + $null = $mockSqlPermissionInstance.Modify(@{ + PermissionToExclude = [ServerPermission[]] @( + [ServerPermission] @{ + State = 'Grant' + Permission = @('ConnectSql') + } + [ServerPermission] @{ + State = 'GrantWithGrant' + Permission = @('AlterAnyEndpoint') + } + [ServerPermission] @{ + State = 'Deny' + Permission = @() + } + ) + }) } # Revoking Grants diff --git a/tests/Unit/Classes/SqlRSSetup.Tests.ps1 b/tests/Unit/Classes/SqlRSSetup.Tests.ps1 index 159dc9406a..7eb1830785 100644 --- a/tests/Unit/Classes/SqlRSSetup.Tests.ps1 +++ b/tests/Unit/Classes/SqlRSSetup.Tests.ps1 @@ -58,7 +58,7 @@ Describe 'SqlRSSetup' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { [SqlRSSetup]::new() } | Should -Not -Throw + $null = [SqlRSSetup]::new() } } diff --git a/tests/Unit/Classes/SqlResourceBase.Tests.ps1 b/tests/Unit/Classes/SqlResourceBase.Tests.ps1 index f952c165c4..71ed9937d0 100644 --- a/tests/Unit/Classes/SqlResourceBase.Tests.ps1 +++ b/tests/Unit/Classes/SqlResourceBase.Tests.ps1 @@ -58,7 +58,7 @@ Describe 'SqlResourceBase' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlResourceBase]::new() } | Should -Not -Throw + $null = [SqlResourceBase]::new() } } diff --git a/tests/Unit/DSC_SqlAG.Tests.ps1 b/tests/Unit/DSC_SqlAG.Tests.ps1 index e7b5c36e17..a8516fd209 100644 --- a/tests/Unit/DSC_SqlAG.Tests.ps1 +++ b/tests/Unit/DSC_SqlAG.Tests.ps1 @@ -529,7 +529,7 @@ Describe 'SqlAG\Set-TargetResource' { Ensure = 'Absent' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -722,7 +722,7 @@ Describe 'SqlAG\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -765,7 +765,7 @@ Describe 'SqlAG\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -956,7 +956,7 @@ Describe 'SqlAG\Set-TargetResource' { $setTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -1041,7 +1041,7 @@ Describe 'SqlAG\Set-TargetResource' { $setTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -1122,7 +1122,7 @@ Describe 'SqlAG\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It @@ -1181,7 +1181,7 @@ Describe 'SqlAG\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 b/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 index 900d15c2c0..fd5b84860d 100644 --- a/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 +++ b/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 @@ -809,7 +809,7 @@ REVERT' Context 'When Ensure is Present' { It 'Should add the specified databases to the availability group' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -836,7 +836,7 @@ REVERT' It 'Should add the specified databases to the availability group when the primary replica is on another server' { $mockSetTargetResourceParameters.AvailabilityGroupName = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServerName - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -863,7 +863,7 @@ REVERT' It 'Should not do anything if no databases were found to add' { $mockSetTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -890,7 +890,7 @@ REVERT' It 'Should add the specified databases to the availability group when "MatchDatabaseOwner" is $false' { $mockSetTargetResourceParameters.MatchDatabaseOwner = $false - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -918,7 +918,7 @@ REVERT' $mockSetTargetResourceParameters.DatabaseName = 'DB1' $mockSetTargetResourceParameters.ReplaceExisting = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1217,7 +1217,7 @@ REVERT' It 'Should add the specified databases to the availability group when the database has not been previously backed up' { $mockServerObject.Databases['DB1'].LastBackupDate = 0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1357,7 +1357,7 @@ REVERT' } It 'Should ensure the database membership of the availability group is exactly as specified' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1470,7 +1470,7 @@ REVERT' } It 'Should remove the specified database from the availability group(s)' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Import-SqlDscPreferredModule -Scope It -Times 1 -Exactly Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly @@ -1869,7 +1869,7 @@ REVERT' Context 'When Ensure is Present' { It 'Should add the specified databases to the availability group.' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1896,7 +1896,7 @@ REVERT' It 'Should add the specified databases to the availability group when the primary replica is on another server' { $mockSetTargetResourceParameters.AvailabilityGroupName = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServerName - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1923,7 +1923,7 @@ REVERT' It 'Should not do anything if no databases were found to add' { $mockSetTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1950,7 +1950,7 @@ REVERT' It 'Should add the specified databases to the availability group when "MatchDatabaseOwner" is $false' { $mockSetTargetResourceParameters.MatchDatabaseOwner = $false - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1978,7 +1978,7 @@ REVERT' $mockSetTargetResourceParameters.DatabaseName = 'DB1' $mockSetTargetResourceParameters.ReplaceExisting = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -2278,7 +2278,7 @@ REVERT' $mockServerObject.Databases['DB1'].CreateDate = '2020-10-20 10:00:00' $mockServerObject.Databases['DB1'].LastBackupDate = '2020-10-10 10:00:00' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -2368,7 +2368,7 @@ REVERT' } It 'Should ensure the database membership of the availability group is exactly as specified' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } Assert-MockCalled -CommandName Add-SqlAvailabilityDatabase -Scope It -Times 1 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } diff --git a/tests/Unit/DSC_SqlAGListener.Tests.ps1 b/tests/Unit/DSC_SqlAGListener.Tests.ps1 index d8410eafb7..8673be770c 100644 --- a/tests/Unit/DSC_SqlAGListener.Tests.ps1 +++ b/tests/Unit/DSC_SqlAGListener.Tests.ps1 @@ -154,7 +154,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It @@ -241,7 +241,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It @@ -315,7 +315,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It @@ -389,7 +389,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It @@ -744,7 +744,7 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -791,7 +791,7 @@ Describe 'SqlAGListener\Set-TargetResource' { It 'Should not throw and call the correct mocks' { InModuleScope -ScriptBlock { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -868,7 +868,7 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -Parameters $_ -ScriptBlock { $mockSetTargetResourceParameters.$MockPropertyName = $MockExpectedValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1099,7 +1099,7 @@ Describe 'SqlAGListener\Set-TargetResource' { It 'Should not throw and call the correct mocks' { InModuleScope -ScriptBlock { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1134,7 +1134,7 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockSetTargetResourceParameters.DHCP = $true $mockSetTargetResourceParameters.IpAddress = '192.168.10.45/255.255.252.0' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1170,7 +1170,7 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Port = 5031 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1206,7 +1206,7 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.IpAddress = '192.168.10.45/255.255.252.0' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1259,7 +1259,7 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' $mockMethodDropWasRunCount | Should -Be 1 } @@ -1303,7 +1303,7 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Port = 5030 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1384,7 +1384,7 @@ Describe 'SqlAGListener\Set-TargetResource' { '192.168.0.1/255.255.252.0' ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlAGReplica.Tests.ps1 b/tests/Unit/DSC_SqlAGReplica.Tests.ps1 index 240ecf869d..8983b096e3 100644 --- a/tests/Unit/DSC_SqlAGReplica.Tests.ps1 +++ b/tests/Unit/DSC_SqlAGReplica.Tests.ps1 @@ -520,7 +520,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { Ensure = 'Absent' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -719,7 +719,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -776,7 +776,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -834,7 +834,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -1200,7 +1200,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { $setTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { @@ -1290,7 +1290,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It @@ -1323,7 +1323,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It @@ -1382,7 +1382,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It @@ -1441,7 +1441,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 b/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 index 0cf742bc67..fcf4fe57dd 100644 --- a/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 +++ b/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 @@ -158,7 +158,7 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Get-TargetResource @mockTestParameters -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It } @@ -207,7 +207,7 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Get-TargetResource @mockTestParameters -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It } @@ -512,7 +512,7 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { Ensure = 'Present' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -530,7 +530,7 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { NotificationMethod = 'Pager' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -603,7 +603,7 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { Ensure = 'Absent' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 b/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 index 3f928c8227..6eabeb2589 100644 --- a/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 +++ b/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 @@ -502,7 +502,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { } Context 'When creating the sql agent operator' { - It 'Should not throw' { + It 'Should create the sql agent operator' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -512,7 +512,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Ensure = 'Present' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = Set-TargetResource @setParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -535,7 +535,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { } } - It 'Should return the state as true' { + It 'Should create the sql agent operator with email address' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -546,13 +546,13 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Ensure = 'Present' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = Set-TargetResource @setParameters -ErrorAction 'Stop' } } } Context 'When changing the email address' { - It 'Should not throw' { + It 'Should update the email address' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -563,7 +563,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { EmailAddress = 'newemail@contoso.com' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = Set-TargetResource @setParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -575,7 +575,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable } - It 'Should not throw' { + It 'Should drop the sql agent operator' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -585,7 +585,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Ensure = 'Absent' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = Set-TargetResource @setParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlAlias.Tests.ps1 b/tests/Unit/DSC_SqlAlias.Tests.ps1 index 5702be0c7b..ce30cbb5c4 100644 --- a/tests/Unit/DSC_SqlAlias.Tests.ps1 +++ b/tests/Unit/DSC_SqlAlias.Tests.ps1 @@ -1124,7 +1124,7 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.TcpPort = 1433 $script:mockSetTargetResourceParameters.ServerName = 'SqlNode.company.local' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } } @@ -1164,7 +1164,7 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.UseDynamicTcpPort = $true $script:mockSetTargetResourceParameters.ServerName = 'SqlNode.company.local' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } } @@ -1203,7 +1203,7 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.Protocol = 'NP' $script:mockSetTargetResourceParameters.ServerName = 'SqlNode.company.local' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } } @@ -1248,7 +1248,7 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.Ensure = 'Absent' $script:mockSetTargetResourceParameters.Name = 'MyAlias' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } } diff --git a/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 b/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 index f27e9f1cd6..50fc518296 100644 --- a/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 +++ b/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 @@ -221,7 +221,7 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw 'Index operation failed; the array index evaluated to null' + $null = Get-TargetResource @mockGetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly @@ -446,7 +446,7 @@ Describe 'SqlAlwaysOnService\Set-TargetResource' { $script:mockSetTargetResourceParameters['Ensure'] = 'Absent' $script:mockSetTargetResourceParameters['InstanceName'] = $MockInstanceName - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Import-SqlDscPreferredModule -Scope It -Times 1 -Exactly @@ -470,7 +470,7 @@ Describe 'SqlAlwaysOnService\Set-TargetResource' { $script:mockSetTargetResourceParameters['Ensure'] = 'Present' $script:mockSetTargetResourceParameters['InstanceName'] = $MockInstanceName - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Import-SqlDscPreferredModule -Scope It -Times 1 -Exactly diff --git a/tests/Unit/DSC_SqlConfiguration.Tests.ps1 b/tests/Unit/DSC_SqlConfiguration.Tests.ps1 index 96c10bc2e9..da24a6953d 100644 --- a/tests/Unit/DSC_SqlConfiguration.Tests.ps1 +++ b/tests/Unit/DSC_SqlConfiguration.Tests.ps1 @@ -258,7 +258,7 @@ Describe 'SqlConfiguration\Set-TargetResource' { RestartTimeout = 120 } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' $script:mockAlterMethodCallCount | Should -Be 1 } @@ -289,7 +289,7 @@ Describe 'SqlConfiguration\Set-TargetResource' { RestartTimeout = 120 } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } if ($IsDynamic) diff --git a/tests/Unit/DSC_SqlDatabase.Tests.ps1 b/tests/Unit/DSC_SqlDatabase.Tests.ps1 index c473c0c404..16a1f4652c 100644 --- a/tests/Unit/DSC_SqlDatabase.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabase.Tests.ps1 @@ -592,7 +592,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $script:mockSetTargetResourceParameters['Ensure'] = 'Present' $script:mockSetTargetResourceParameters['Name'] = 'NewDatabase' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:newObjectMethodCreateWasCalled | Should -Be 1 } @@ -628,7 +628,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $script:mockSetTargetResourceParameters['Name'] = 'NewDatabase' $script:mockSetTargetResourceParameters[$PropertyName] = $PropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:newObjectMethodCreateWasCalled | Should -Be 1 @@ -672,7 +672,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $script:mockSetTargetResourceParameters['Ensure'] = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:methodDropWasCalled | Should -Be 1 } @@ -723,7 +723,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $script:mockSetTargetResourceParameters[$PropertyName] = $PropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:methodAlterWasCalled | Should -Be 1 } diff --git a/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 index b47f5b2e18..e690a780f1 100644 --- a/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 @@ -401,7 +401,7 @@ Describe 'SqlDatabaseDefaultLocation\Set-TargetResource' { InModuleScope -Parameters $_ -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockGetTargetResourceParameters -Type $Type -Path $Path } | Should -Not -Throw + $null = Set-TargetResource @mockGetTargetResourceParameters -Type $Type -Path $Path -ErrorAction 'Stop' $script:methodAlterWasCalled | Should -Be 1 } @@ -443,7 +443,7 @@ Describe 'SqlDatabaseDefaultLocation\Set-TargetResource' { $mockGetTargetResourceParameters.Path = 'C:\AnyPath' $mockGetTargetResourceParameters.RestartService = $true - { Set-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockGetTargetResourceParameters -ErrorAction 'Stop' $script:methodAlterWasCalled | Should -Be 1 } diff --git a/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 index 33feb8c2ce..ae4f4c13d4 100644 --- a/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 @@ -861,7 +861,7 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters.AccountName = 'MissingAccount' $setTargetResourceParameters.ProfileName = 'MissingProfile' - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:MailAccountCreateMethodCallCount | Should -Be 0 $script:MailServerRenameMethodCallCount | Should -Be 0 @@ -905,7 +905,7 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters['TcpPort'] = $MockTcpPort $setTargetResourceParameters['UseDefaultCredentials'] = $MockUseDefaultCredentials - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:MailAccountCreateMethodCallCount | Should -Be 0 $script:MailServerRenameMethodCallCount | Should -Be 0 @@ -937,7 +937,7 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters = $mockDefaultParameters.Clone() $setTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:JobServerAlterMethodCallCount | Should -Be 1 $script:MailProfileDropMethodCallCount | Should -Be 1 @@ -995,7 +995,7 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters['TcpPort'] = 2525 $setTargetResourceParameters['UseDefaultCredentials'] = $true - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:MailAccountCreateMethodCallCount | Should -Be 1 $script:MailServerRenameMethodCallCount | Should -Be 1 @@ -1070,7 +1070,7 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters.$Property = $PropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:MailAccountCreateMethodCallCount | Should -Be 0 diff --git a/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 index 11a1a524f9..4bb3f1277e 100644 --- a/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 @@ -2008,7 +2008,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should not try to set any values and should not throw an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 0 -Scope It } @@ -2168,7 +2168,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should set the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2225,7 +2225,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should set the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2293,7 +2293,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should set the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2358,7 +2358,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should set the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2436,7 +2436,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should set the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2529,7 +2529,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should revoke the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2582,7 +2582,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should revoke the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It @@ -2635,7 +2635,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { } It 'Should revoke the permissions without throwing an exception' { - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 index ad7e45601c..8363d25664 100644 --- a/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 @@ -999,7 +999,7 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Name = 'MyRole' $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodDropWasCalled | Should -Be 1 } @@ -1041,7 +1041,7 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Name = 'DatabaseRoleToAdd' $mockSetTargetResourceParameters.Ensure = 'Present' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodCreateWasCalled | Should -Be 1 } @@ -1141,7 +1141,7 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { #> $mockSetTargetResourceParameters.Members = @('John', 'CONTOSO\SQLAdmin') - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1175,7 +1175,7 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { #> $mockSetTargetResourceParameters.MembersToInclude = @('CONTOSO\SQLAdmin') - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1207,7 +1207,7 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { #> $mockSetTargetResourceParameters.MembersToExclude = @('CONTOSO\KingJulian') - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1288,9 +1288,7 @@ Describe 'Add-SqlDscDatabaseRoleMember' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { - Add-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'John' - } | Should -Not -Throw + $null = Add-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'John' $mockMethodAddMemberWasCalled | Should -Be 1 } @@ -1379,9 +1377,7 @@ Describe 'Remove-SqlDscDatabaseRoleMember' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { - Remove-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'MyRole' - } | Should -Not -Throw + $null = Remove-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'MyRole' $mockMethodDropMemberWasCalled | Should -Be 1 } diff --git a/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 index 9a57a8e903..88ae147b01 100644 --- a/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 @@ -647,7 +647,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -685,7 +685,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -724,7 +724,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -800,7 +800,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -832,7 +832,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -858,7 +858,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -880,7 +880,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -902,7 +902,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -980,7 +980,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1012,7 +1012,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1087,7 +1087,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1133,7 +1133,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1179,7 +1179,7 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -1410,7 +1410,7 @@ Describe 'Assert-SqlLogin' -Tag 'Helper' { Verbose = $true } - { Assert-SqlLogin @assertSqlLoginParameters } | Should -Not -Throw + $null = Assert-SqlLogin @assertSqlLoginParameters -ErrorAction 'Stop' } } } @@ -1482,7 +1482,7 @@ Describe 'Assert-DatabaseCertificate' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Assert-DatabaseCertificate @assertDatabaseCertificateParameters } | Should -Not -Throw + $null = Assert-DatabaseCertificate @assertDatabaseCertificateParameters -ErrorAction 'Stop' } } } @@ -1554,7 +1554,7 @@ Describe 'Assert-DatabaseAsymmetricKey' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Assert-DatabaseAsymmetricKey @assertDatabaseAsymmetricKeyParameters } | Should -Not -Throw + $null = Assert-DatabaseAsymmetricKey @assertDatabaseAsymmetricKeyParameters -ErrorAction 'Stop' } } } diff --git a/tests/Unit/DSC_SqlEndpoint.Tests.ps1 b/tests/Unit/DSC_SqlEndpoint.Tests.ps1 index 486d717920..47605deeb3 100644 --- a/tests/Unit/DSC_SqlEndpoint.Tests.ps1 +++ b/tests/Unit/DSC_SqlEndpoint.Tests.ps1 @@ -189,7 +189,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -246,7 +246,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -372,7 +372,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -429,7 +429,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1166,7 +1166,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointName = 'NewEndpoint' $mockSetTargetResourceParameters.EndpointType = $MockEndpointType - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodCreateWasRun | Should -Be 1 $script:mockMethodStartWasRun | Should -Be 1 @@ -1197,7 +1197,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointType = 'DatabaseMirroring' $mockSetTargetResourceParameters.State = $MockState - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodCreateWasRun | Should -Be 1 $script:mockMethodAlterWasRun | Should -Be 0 @@ -1260,7 +1260,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointType = 'DatabaseMirroring' $mockSetTargetResourceParameters.$MockParameterName = $MockParameterValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodCreateWasRun | Should -Be 1 $script:mockMethodStartWasRun | Should -Be 1 @@ -1318,7 +1318,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointType = 'ServiceBroker' $mockSetTargetResourceParameters.$MockParameterName = $MockParameterValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodCreateWasRun | Should -Be 1 $script:mockMethodStartWasRun | Should -Be 1 @@ -1390,7 +1390,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointType = 'DatabaseMirroring' $mockSetTargetResourceParameters.$MockParameterName = $MockParameterValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodCreateWasRun | Should -Be 0 $script:mockMethodDropWasRun | Should -Be 0 @@ -1479,7 +1479,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointType = 'ServiceBroker' $mockSetTargetResourceParameters.$MockParameterName = $MockParameterValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodCreateWasRun | Should -Be 0 $script:mockMethodDropWasRun | Should -Be 0 @@ -1557,7 +1557,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.EndpointName = 'DefaultEndpointMirror' $mockSetTargetResourceParameters.EndpointType = 'DatabaseMirroring' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodDropWasRun | Should -Be 1 $script:mockMethodCreateWasRun | Should -Be 0 diff --git a/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 b/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 index 55edb3a8e2..68fa99f20f 100644 --- a/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 +++ b/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 @@ -329,7 +329,7 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Principal = 'COMPANY\Account' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It } @@ -352,7 +352,7 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' $mockSetTargetResourceParameters.Principal = 'COMPANY\MissingAccount' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It } @@ -430,7 +430,7 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Principal = 'COMPANY\Account' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It @@ -457,7 +457,7 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' $mockSetTargetResourceParameters.Principal = 'COMPANY\MissingAccount' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlLogin.Tests.ps1 b/tests/Unit/DSC_SqlLogin.Tests.ps1 index 1d1c52eade..2c0f79ad35 100644 --- a/tests/Unit/DSC_SqlLogin.Tests.ps1 +++ b/tests/Unit/DSC_SqlLogin.Tests.ps1 @@ -705,7 +705,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Name = $MockLoginName $mockSetTargetResourceParameters.LoginType = $MockLoginType - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -746,7 +746,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.DefaultDatabase = 'NewDatabase' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -800,7 +800,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.Disabled = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' $script:mockMethodDisableWasRun | Should -Be 1 } @@ -839,7 +839,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginMustChangePassword = $true $mockSetTargetResourceParameters.LoginCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockPassword) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -887,7 +887,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginMustChangePassword = $false $mockSetTargetResourceParameters.LoginCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockPassword) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -931,7 +931,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DefaultDatabase = 'NewDatabase' $mockSetTargetResourceParameters.LoginCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockPassword) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -988,7 +988,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Disabled = $true $mockSetTargetResourceParameters.LoginCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockPassword) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' $script:mockMethodDisableWasRun | Should -Be 1 } @@ -1136,7 +1136,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' $mockSetTargetResourceParameters.Name = 'SqlLogin1' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1195,7 +1195,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.Disabled = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' if ($MockPropertyValue) { @@ -1245,7 +1245,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1305,7 +1305,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } @@ -1363,7 +1363,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.Disabled = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' if ($MockPropertyValue) { @@ -1414,7 +1414,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1489,7 +1489,7 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.LoginCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($mockTestTargetResourceParameters.Name, $mockPassword) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1520,7 +1520,7 @@ Describe 'SqlLogin\Update-SQLServerLogin' { $mockLogin.LoginType = 'WindowsUser' - { Update-SQLServerLogin -Login $mockLogin } | Should -Not -Throw + $null = Update-SQLServerLogin -Login $mockLogin -ErrorAction 'Stop' $script:mockMethodAlterWasRun | Should -Be 1 } @@ -1569,7 +1569,7 @@ Describe 'SqlLogin\New-SQLServerLogin' { $mockLogin.LoginType = 'WindowsUser' - { New-SQLServerLogin -Login $mockLogin } | Should -Not -Throw + $null = New-SQLServerLogin -Login $mockLogin -ErrorAction 'Stop' $script:mockMethodCreateWasRun | Should -Be 1 } @@ -1593,7 +1593,7 @@ Describe 'SqlLogin\New-SQLServerLogin' { LoginCreateOptions = 'None' } - { New-SQLServerLogin @createLoginParameters } | Should -Not -Throw + $null = New-SQLServerLogin @createLoginParameters -ErrorAction 'Stop' $script:mockMethodCreateWasRun | Should -Be 1 } @@ -1722,7 +1722,7 @@ Describe 'SqlLogin\Remove-SQLServerLogin' { $mockLogin.LoginType = 'WindowsUser' - { Remove-SQLServerLogin -Login $mockLogin } | Should -Not -Throw + $null = Remove-SQLServerLogin -Login $mockLogin -ErrorAction 'Stop' $script:mockMethodDropWasRun | Should -Be 1 } @@ -1775,7 +1775,7 @@ Describe 'SqlLogin\Set-SQLServerLoginPassword' { SecureString = ConvertTo-SecureString -String 'P@ssw0rd-12P@ssw0rd-12' -AsPlainText -Force } - { Set-SQLServerLoginPassword @setPasswordParameters } | Should -Not -Throw + $null = Set-SQLServerLoginPassword @setPasswordParameters -ErrorAction 'Stop' $mockMethodChangePasswordWasRun | Should -Be 1 } diff --git a/tests/Unit/DSC_SqlMaxDop.Tests.ps1 b/tests/Unit/DSC_SqlMaxDop.Tests.ps1 index 55fe934bdf..c6fde460d6 100644 --- a/tests/Unit/DSC_SqlMaxDop.Tests.ps1 +++ b/tests/Unit/DSC_SqlMaxDop.Tests.ps1 @@ -524,7 +524,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -579,7 +579,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxDop = 4 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -638,7 +638,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DynamicAlloc = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } diff --git a/tests/Unit/DSC_SqlMemory.Tests.ps1 b/tests/Unit/DSC_SqlMemory.Tests.ps1 index 9768dba8ce..170132050d 100644 --- a/tests/Unit/DSC_SqlMemory.Tests.ps1 +++ b/tests/Unit/DSC_SqlMemory.Tests.ps1 @@ -905,7 +905,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -922,7 +922,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemory = 15000 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -939,7 +939,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MinMemory = 4096 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -962,7 +962,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemoryPercent = 50 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -985,7 +985,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MinMemoryPercent = 50 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -1008,7 +1008,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DynamicAlloc = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -1032,7 +1032,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DynamicAlloc = $true $mockSetTargetResourceParameters.MinMemory = 4096 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -1060,7 +1060,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DynamicAlloc = $true $mockSetTargetResourceParameters.MinMemoryPercent = 50 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -1084,7 +1084,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemoryPercent = 50 $mockSetTargetResourceParameters.MinMemory = 4096 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -1102,7 +1102,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemory = 8192 $mockSetTargetResourceParameters.MinMemory = 4096 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } @@ -1126,7 +1126,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemory = 16384 $mockSetTargetResourceParameters.MinMemoryPercent = 50 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $mockMethodAlterWasRun | Should -Be 1 } diff --git a/tests/Unit/DSC_SqlProtocol.Tests.ps1 b/tests/Unit/DSC_SqlProtocol.Tests.ps1 index fd3d6291d3..287bda9d34 100644 --- a/tests/Unit/DSC_SqlProtocol.Tests.ps1 +++ b/tests/Unit/DSC_SqlProtocol.Tests.ps1 @@ -778,7 +778,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It @@ -851,7 +851,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -910,7 +910,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -969,7 +969,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $false } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -1035,7 +1035,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { KeepAlive = 50000 } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -1096,7 +1096,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { SuppressRestart = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -1163,7 +1163,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -1220,7 +1220,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } @@ -1277,7 +1277,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { PipeName = '\\.\pipe\$$\CLU01A\MSSQL$SQL2014\sql\query' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters -ErrorAction 'Stop' $script:wasMethodAlterCalled | Should -BeTrue } diff --git a/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 b/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 index 244b8b0cec..1a47fe0e48 100644 --- a/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 +++ b/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 @@ -140,7 +140,7 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { IpAddressGroup = 'IP2' } - { Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @getTargetResourceParameters } Should -Invoke -CommandName Write-Warning @@ -1044,7 +1044,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { IpAddressGroup = 'IPAll' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters } Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It @@ -1112,7 +1112,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { UseTcpDynamicPort = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters <# Addition evaluation is done in the mock to test if the @@ -1185,7 +1185,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { TcpPort = '1433,1500,1501' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters <# Addition evaluation is done in the mock to test if the @@ -1256,7 +1256,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters <# Addition evaluation is done in the mock to test if the @@ -1326,7 +1326,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { Enabled = $false } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters <# Addition evaluation is done in the mock to test if the @@ -1402,7 +1402,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { IpAddress = $MockExpectedIpAddress } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters <# Addition evaluation is done in the mock to test if the @@ -1455,7 +1455,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { SuppressRestart = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @setTargetResourceParameters } Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It diff --git a/tests/Unit/DSC_SqlRS.Tests.ps1 b/tests/Unit/DSC_SqlRS.Tests.ps1 index f1a4e3c5e0..e0cebde5ac 100644 --- a/tests/Unit/DSC_SqlRS.Tests.ps1 +++ b/tests/Unit/DSC_SqlRS.Tests.ps1 @@ -589,7 +589,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { UseSsl = $true } - { Set-TargetResource @mockDefaultParameters } | Should -Not -Throw + $null = Set-TargetResource @mockDefaultParameters } Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { @@ -731,7 +731,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { } It 'Should configure Reporting Service without throwing an error' { - { Set-TargetResource @testParameters } | Should -Not -Throw + $null = Set-TargetResource @testParameters Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' @@ -826,7 +826,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { } It 'Should configure Reporting Service without throwing an error' { - { Set-TargetResource @testParameters } | Should -Not -Throw + $null = Set-TargetResource @testParameters Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' @@ -911,7 +911,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { } It 'Should configure Reporting Service without throwing an error' { - { Set-TargetResource @defaultParameters } | Should -Not -Throw + $null = Set-TargetResource @defaultParameters Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'RemoveURL' @@ -1010,7 +1010,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { } It 'Should configure Reporting Service without throwing an error' { - { Set-TargetResource @defaultParameters } | Should -Not -Throw + $null = Set-TargetResource @defaultParameters Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' diff --git a/tests/Unit/DSC_SqlRole.Tests.ps1 b/tests/Unit/DSC_SqlRole.Tests.ps1 index 2d42e4e1b7..8923da7535 100644 --- a/tests/Unit/DSC_SqlRole.Tests.ps1 +++ b/tests/Unit/DSC_SqlRole.Tests.ps1 @@ -714,7 +714,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Absent' $mockTestParameters.ServerRoleName = $mockSqlServerRole - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } } @@ -755,7 +755,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.ServerRoleName = $mockSqlServerRoleAdd - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -850,7 +850,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToInclude = 'CONTOSO\Lucy' - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -923,7 +923,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToExclude = 'CONTOSO\Kelly' - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1023,7 +1023,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.Members = @('CONTOSO\John', 'CONTOSO\Lucy') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1044,7 +1044,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.Members = @('CONTOSO\John', 'CONTOSO\Kelly', 'TestChildRole') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1064,7 +1064,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToInclude = @('TestChildRole') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1084,7 +1084,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToExclude = @('TestChildRole') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1104,7 +1104,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.Members = 'CONTOSO\John'.ToUpper() - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1120,7 +1120,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.Members = @('CONTOSO\John'.ToUpper(), 'CONTOSO\Kelly') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It } @@ -1138,7 +1138,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.MembersToInclude = @('CONTOSO\John'.ToUpper()) - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It @@ -1154,7 +1154,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.MembersToExclude = @('CONTOSO\John'.ToUpper()) - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = Set-TargetResource @mockTestParameters -ErrorAction 'Stop' } Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It diff --git a/tests/Unit/DSC_SqlScript.Tests.ps1 b/tests/Unit/DSC_SqlScript.Tests.ps1 index e48c8d332a..e98d81abd4 100644 --- a/tests/Unit/DSC_SqlScript.Tests.ps1 +++ b/tests/Unit/DSC_SqlScript.Tests.ps1 @@ -191,11 +191,11 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' { } } - It 'Should return the expected results' { + It 'Should complete without error' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } } @@ -207,13 +207,13 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' { } } - It 'Should return the expected results' { + It 'Should complete without error with query timeout' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 $mockSetTargetResourceParameters.QueryTimeout = 30 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } } diff --git a/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 b/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 index 9f217406fd..28aa4efd33 100644 --- a/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 +++ b/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 @@ -195,7 +195,7 @@ Describe 'SqlScriptQuery\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } } @@ -213,7 +213,7 @@ Describe 'SqlScriptQuery\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.QueryTimeout = 30 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } } diff --git a/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 b/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 index 027d2b79cb..73ec928ff1 100644 --- a/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 +++ b/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 @@ -384,7 +384,7 @@ Describe 'SqlSecureConnection\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Times 1 -Scope It -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } @@ -411,7 +411,7 @@ Describe 'SqlSecureConnection\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.SuppressRestart = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Times 1 -Scope It -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } @@ -441,7 +441,7 @@ Describe 'SqlSecureConnection\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters -ServerName 'MyHostName'} | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters -ServerName 'MyHostName' } Should -Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Times 1 -Scope It @@ -473,7 +473,7 @@ Describe 'SqlSecureConnection\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Times 0 -Scope It @@ -503,7 +503,7 @@ Describe 'SqlSecureConnection\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Times 1 -Scope It @@ -535,7 +535,7 @@ Describe 'SqlSecureConnection\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Times 1 -Scope It @@ -834,7 +834,7 @@ Describe 'SqlSecureConnection\Set-EncryptedConnectionSetting' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-EncryptedConnectionSetting -InstanceName 'NamedInstance' -Thumbprint '12345678' -ForceEncryption $true } | Should -Not -Throw + $null = Set-EncryptedConnectionSetting -InstanceName 'NamedInstance' -Thumbprint '12345678' -ForceEncryption $true } } } @@ -1016,7 +1016,7 @@ Describe 'SqlSecureConnection\Set-CertificatePermission' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' } | Should -Not -Throw + $null = Set-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' } } } @@ -1090,7 +1090,7 @@ Describe 'SqlSecureConnection\Get-CertificateAcl' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-CertificateAcl -Thumbprint '12345678' } | Should -Not -Throw + $null = Get-CertificateAcl -Thumbprint '12345678' } } } @@ -1146,7 +1146,7 @@ Describe 'SqlSecureConnection\Get-SqlEncryptionValue' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-SqlEncryptionValue -InstanceName 'INSTANCE' } | Should -Not -Throw + $null = Get-SqlEncryptionValue -InstanceName 'INSTANCE' } } } diff --git a/tests/Unit/DSC_SqlSetup.Tests.ps1 b/tests/Unit/DSC_SqlSetup.Tests.ps1 index f7354258bd..34a3797b08 100644 --- a/tests/Unit/DSC_SqlSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlSetup.Tests.ps1 @@ -2429,7 +2429,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Features = $mockSetTargetResourceParameters.Features -replace ',SDK', '' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -2474,7 +2474,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { ServerName = 'host.company.local' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -2515,7 +2515,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { TcpEnabled = $true } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -2557,7 +2557,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $mockSourcePathUNC } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -2601,7 +2601,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SuppressReboot = $true } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -2725,7 +2725,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Features = $mockSetTargetResourceParameters.Features -replace ',SDK', '' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -2774,7 +2774,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { NpEnabled = $false } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -2820,7 +2820,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { ServerName = 'host.company.local' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -2865,7 +2865,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { TcpEnabled = $false } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -2910,7 +2910,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { UseEnglish = $true } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -2955,7 +2955,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SkipRule = 'Cluster_VerifyForErrors' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -3004,7 +3004,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { ) } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It @@ -3048,7 +3048,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $global:DSCMachineStatus | Should -Be 1 } @@ -3074,7 +3074,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It @@ -3178,7 +3178,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -3205,7 +3205,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -3276,7 +3276,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLSysAdminAccounts = 'COMPANY\User1', 'COMPANY\SQLAdmins' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } } @@ -3385,7 +3385,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -3424,7 +3424,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { InstallSQLDataDir = 'E:\MSSQL\Data' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -3467,7 +3467,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLUserDBLogDir = 'E:\SQLData\UserDbLogs' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -3547,7 +3547,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -3728,7 +3728,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } # Reverting the mock to return a single site. @@ -3862,7 +3862,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'C:\ClusterStorage\SQLBackup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -3912,7 +3912,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'C:\ClusterStorage\SQLBackup\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } } @@ -3975,7 +3975,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { Action = 'PrepareFailoverCluster' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It @@ -4108,7 +4108,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -4147,7 +4147,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { InstallSQLDataDir = 'E:\MSSQL\Data' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -4190,7 +4190,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLUserDBLogDir = 'E:\SQLData\UserDbLogs' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -4270,7 +4270,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } } @@ -4451,7 +4451,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } # Reverting the mock to return a single site. diff --git a/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 b/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 index 4dc6fcf738..9fee701a7d 100644 --- a/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 +++ b/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 @@ -189,7 +189,7 @@ Describe 'DSC_SqlTraceFlag\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } } } @@ -214,7 +214,7 @@ Describe 'DSC_SqlTraceFlag\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } } } @@ -846,7 +846,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeFalse -Because 'no TraceFlag parameter was set' } @@ -862,7 +862,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf $mockSetTargetResourceParameters.ClearAllTraceFlags = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' @@ -884,7 +884,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf $mockSetTargetResourceParameters.TraceFlags = '3228' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' @@ -907,7 +907,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3228 $mockSetTargetResourceParameters.InstanceName = 'INST00' $mockSetTargetResourceParameters.TraceFlagsToInclude = '3228' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' @@ -930,7 +930,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3228 $mockSetTargetResourceParameters.TraceFlagsToInclude = '3228' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' @@ -953,7 +953,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3226;-T1802;-T3228 $mockSetTargetResourceParameters.TraceFlagsToExclude = '1802' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' @@ -976,7 +976,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3226 $mockSetTargetResourceParameters.TraceFlagsToExclude = '1802', '3226' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' @@ -1000,7 +1000,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf $mockSetTargetResourceParameters.TraceFlags = '4199' $mockSetTargetResourceParameters.RestartService = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters $script:mockMethodAlterRan | Should -BeTrue -Because 'method Alter() should run' diff --git a/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 b/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 index 7a4cbd3fb9..414a5774a5 100644 --- a/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 +++ b/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 @@ -414,7 +414,7 @@ Describe 'SqlWaitForAG\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It @@ -452,7 +452,7 @@ Describe 'SqlWaitForAG\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } # Looping twice so these mocks are called twice. diff --git a/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 b/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 index 8504a8cb9d..81a2f18e2c 100644 --- a/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 +++ b/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 @@ -1740,7 +1740,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { ('dummyPassword' | ConvertTo-SecureString -AsPlainText -Force) ) - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = Get-TargetResource @mockGetTargetResourceParameters } Should -Invoke New-SmbMapping -Exactly -Times 1 -Scope It @@ -1940,7 +1940,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 0 -Scope It Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It @@ -1976,7 +1976,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 0 -Scope It Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It @@ -2012,7 +2012,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It @@ -2029,7 +2029,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 0 -Scope It Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 1 -Scope It @@ -2054,7 +2054,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 0 -Scope It Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 1 -Scope It @@ -2091,7 +2091,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 1 -Scope It #-Because 'the rule already exist for the Database Engine' Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 1 -Scope It #-Because 'no rule exist for the SQL Browser' @@ -2108,7 +2108,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName Set-NetFirewallRule -Exactly -Times 0 -Scope It #-Because 'no rules exist to change' Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 2 -Scope It #-Because 'no rule exist for either the Database Engine or SQL Browser' @@ -2158,7 +2158,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It } @@ -2193,7 +2193,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It } @@ -2215,7 +2215,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 1 -Scope It } @@ -2238,7 +2238,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 1 -Scope It } @@ -2261,7 +2261,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 2 -Scope It #-Because 'no rule exist for either Analysis Services or SQL Browser' } @@ -2309,7 +2309,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It } @@ -2343,7 +2343,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It } @@ -2364,7 +2364,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 2 -Scope It } @@ -2413,7 +2413,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It } @@ -2447,7 +2447,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 0 -Scope It } @@ -2472,7 +2472,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters Should -Invoke -CommandName New-NetFirewallRule -Exactly -Times 2 -Scope It } @@ -2513,7 +2513,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { ('dummyPassword' | ConvertTo-SecureString -AsPlainText -Force) ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = Set-TargetResource @mockSetTargetResourceParameters } Should -Invoke New-SmbMapping -Exactly -Times 1 -Scope It diff --git a/tests/Unit/Private/Assert-Feature.Tests.ps1 b/tests/Unit/Private/Assert-Feature.Tests.ps1 index 2ca08bcb98..06178f9334 100644 --- a/tests/Unit/Private/Assert-Feature.Tests.ps1 +++ b/tests/Unit/Private/Assert-Feature.Tests.ps1 @@ -58,9 +58,7 @@ Describe 'Assert-Feature' -Tag 'Private' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { - Assert-Feature -Feature 'RS' -ProductVersion '14' - } | Should -Not -Throw + $null = Assert-Feature -Feature 'RS' -ProductVersion '14' -ErrorAction 'Stop' } } @@ -68,9 +66,7 @@ Describe 'Assert-Feature' -Tag 'Private' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { - Assert-Feature -Feature 'RS', 'SQLENGINE' -ProductVersion '14' - } | Should -Not -Throw + $null = Assert-Feature -Feature 'RS', 'SQLENGINE' -ProductVersion '14' -ErrorAction 'Stop' } } } diff --git a/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 b/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 index f4f212cdcb..f99e347933 100644 --- a/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 +++ b/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 @@ -67,10 +67,8 @@ Describe 'Assert-ManagedServiceType' -Tag 'Private' { InModuleScope -Parameters $_ -ScriptBlock { Set-StrictMode -Version 1.0 - { - $MockServiceObject | - Assert-ManagedServiceType -ServiceType 'DatabaseEngine' -ErrorAction 'Stop' - } | Should -Not -Throw + $null = $MockServiceObject | + Assert-ManagedServiceType -ServiceType 'DatabaseEngine' -ErrorAction 'Stop' } } } diff --git a/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 b/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 index e0aed6a98c..99bb494790 100644 --- a/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 +++ b/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 @@ -99,11 +99,9 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { ) { It 'Should not throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { - { - Assert-SetupActionProperties -Property @{ - ValidProperty = 'Value' - } -SetupAction $MockSetupAction - } | Should -Not -Throw + $null = Assert-SetupActionProperties -Property @{ + ValidProperty = 'Value' + } -SetupAction $MockSetupAction -ErrorAction 'Stop' } } } @@ -189,11 +187,9 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { InModuleScope -Parameters @{ MockFileStreamLevel = $_ } -ScriptBlock { - { - Assert-SetupActionProperties -Property @{ - FileStreamLevel = $MockFileStreamLevel - } -SetupAction 'NotUsed' - } | Should -Not -Throw + $null = Assert-SetupActionProperties -Property @{ + FileStreamLevel = $MockFileStreamLevel + } -SetupAction 'NotUsed' -ErrorAction 'Stop' } } } @@ -277,12 +273,10 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { ) { It 'Should not throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { - { - Assert-SetupActionProperties -Property @{ - $MockParameterName = 'AccountName' - ($MockParameterName -replace 'Account', 'Password') = 'Password' - } -SetupAction 'NotUsed' - } | Should -Not -Throw + $null = Assert-SetupActionProperties -Property @{ + $MockParameterName = 'AccountName' + ($MockParameterName -replace 'Account', 'Password') = 'Password' + } -SetupAction 'NotUsed' -ErrorAction 'Stop' } } } @@ -321,11 +315,9 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { It 'Should not throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { - { - Assert-SetupActionProperties -Property @{ - $MockParameterName = 'myMSA$' - } -SetupAction 'NotUsed' - } | Should -Not -Throw + $null = Assert-SetupActionProperties -Property @{ + $MockParameterName = 'myMSA$' + } -SetupAction 'NotUsed' -ErrorAction 'Stop' } } } diff --git a/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 index e6720b1ca9..ebe75dbadb 100644 --- a/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 @@ -111,7 +111,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag -contains 4199 @@ -121,7 +121,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag -contains 4199 @@ -131,7 +131,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It } @@ -139,7 +139,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When passing parameter ServerObject over the pipeline' { It 'Should call the mocked method and have correct value in the object' { - { $mockServiceObject | Add-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw + $null = $mockServiceObject | Add-SqlDscTraceFlag -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag -contains 4199 @@ -151,7 +151,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When adding a trace flag by default parameter set and parameters default values' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Add-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag -contains 4199 @@ -161,7 +161,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Add-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag -contains 4199 @@ -171,7 +171,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Add-SqlDscTraceFlag -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -TraceFlag 4199 -WhatIf -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It } @@ -191,7 +191,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object' { - { Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag.Count -eq 2 -and @@ -201,7 +201,7 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { } It 'Should not add duplicate if it already exist' { - { Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force } | Should -Not -Throw + $null = Add-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force -ErrorAction 'Stop' # Should not call Set-SqlDscTraceFlag when the trace flag already exists (idempotent) Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It diff --git a/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 b/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 index b418de373a..1ea662ed3f 100644 --- a/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 +++ b/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 @@ -96,7 +96,7 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the correct mock with the expected parameters' { - { Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Confirm:$false } | Should -Not -Throw + $null = Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Confirm:$false $mockMethodDisconnectCallCount | Should -Be 1 } @@ -104,7 +104,7 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the correct mock with the expected parameters' { - { Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Force } | Should -Not -Throw + $null = Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -Force $mockMethodDisconnectCallCount | Should -Be 1 } @@ -112,7 +112,7 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should call the correct mock with the expected parameters' { - { Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -WhatIf } | Should -Not -Throw + $null = Disconnect-SqlDscDatabaseEngine -ServerObject $mockServerObject -WhatIf $mockMethodDisconnectCallCount | Should -Be 0 } @@ -120,7 +120,7 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag 'Public' { Context 'When passing parameter ServerObject over the pipeline' { It 'Should call the correct mock with the expected parameters' { - { $mockServerObject | Disconnect-SqlDscDatabaseEngine -Force } | Should -Not -Throw + $null = $mockServerObject | Disconnect-SqlDscDatabaseEngine -Force $mockMethodDisconnectCallCount | Should -Be 1 } diff --git a/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 b/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 index 7424817b40..e67cc3eacd 100644 --- a/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 +++ b/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 @@ -156,7 +156,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { return $sqlServerModule } - { Import-SqlDscPreferredModule } | Should -Not -Throw + $null = Import-SqlDscPreferredModule Should -Invoke -CommandName Import-Module -Exactly -Times 0 -Scope It } @@ -181,7 +181,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } It 'Should use the already loaded module and not call Import-Module' { - { Import-SqlDscPreferredModule } | Should -Not -Throw + $null = Import-SqlDscPreferredModule Should -Invoke -CommandName Import-Module -Exactly -Times 0 -Scope It } @@ -205,7 +205,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } It 'Should import the SqlServer module without throwing' { - { Import-SqlDscPreferredModule } | Should -Not -Throw + $null = Import-SqlDscPreferredModule Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It @@ -231,7 +231,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } It 'Should import the SqlServer module without throwing' { - { Import-SqlDscPreferredModule -Name 'OtherModule' } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -Name 'OtherModule' Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It @@ -258,7 +258,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } It 'Should import the SQLPS module without throwing' { - { Import-SqlDscPreferredModule -Force } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -Force Should -Invoke -CommandName Get-SqlDscPreferredModule -ParameterFilter { $PesterBoundParameters.ContainsKey('Refresh') -and $Refresh -eq $true @@ -311,7 +311,7 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } It 'Should import the SQLPD module without throwing' { - { Import-SqlDscPreferredModule -Name 'OtherModule' -Force } | Should -Not -Throw + $null = Import-SqlDscPreferredModule -Name 'OtherModule' -Force Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It Should -Invoke -CommandName Get-Module -Exactly -Times 1 -Scope It diff --git a/tests/Unit/Public/Remove-SqlDscRole.Tests.ps1 b/tests/Unit/Public/Remove-SqlDscRole.Tests.ps1 index 17986a82f5..a6d07a969a 100644 --- a/tests/Unit/Public/Remove-SqlDscRole.Tests.ps1 +++ b/tests/Unit/Public/Remove-SqlDscRole.Tests.ps1 @@ -76,8 +76,7 @@ Describe 'Remove-SqlDscRole' -Tag 'Public' { It 'Should remove the server role successfully' { Mock -CommandName 'Write-Verbose' - { Remove-SqlDscRole -ServerObject $mockServerObject -Name 'CustomRole' -Force } | - Should -Not -Throw + $null = Remove-SqlDscRole -ServerObject $mockServerObject -Name 'CustomRole' -Force } It 'Should call Refresh when Refresh parameter is specified' { @@ -134,8 +133,7 @@ Describe 'Remove-SqlDscRole' -Tag 'Public' { It 'Should remove the server role successfully' { Mock -CommandName 'Write-Verbose' - { Remove-SqlDscRole -RoleObject $mockRole -Force } | - Should -Not -Throw + $null = Remove-SqlDscRole -RoleObject $mockRole -Force } } diff --git a/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 index 9324eb116d..de0ac47c1d 100644 --- a/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 @@ -103,7 +103,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag.Count -eq 0 @@ -113,7 +113,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag.Count -eq 0 @@ -123,7 +123,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It } @@ -131,7 +131,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When passing parameter ServerObject over the pipeline' { It 'Should call the mocked method and have correct value in the object' { - { $mockServiceObject | Remove-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw + $null = $mockServiceObject | Remove-SqlDscTraceFlag -TraceFlag 4199 -Force Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag.Count -eq 0 @@ -143,7 +143,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When removing a trace flag by default parameter set and parameters default values' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Remove-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag.Count -eq 0 @@ -153,7 +153,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Remove-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -TraceFlag 4199 -Force Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { $TraceFlag.Count -eq 0 @@ -163,7 +163,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Remove-SqlDscTraceFlag -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -TraceFlag 4199 -WhatIf Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It } @@ -181,7 +181,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { } It 'Should not call Set-SqlDscTraceFlag when there is no effective change' { - { Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force # Should not call Set since the trace flag to remove doesn't exist (no effective change). Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It @@ -201,7 +201,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object' { - { Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It } @@ -219,7 +219,7 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object' { - { Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force } | Should -Not -Throw + $null = Remove-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 3226 -Force # Should still re-set the existing trace flag. Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { diff --git a/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 b/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 index 3d42d15f9a..73bf3941cd 100644 --- a/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 @@ -170,8 +170,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -210,8 +209,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -250,8 +248,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should not call the mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 0 } @@ -290,16 +287,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters $script:mockMethodGrantCallCount | Should -Be 1 } @@ -355,16 +350,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } @@ -404,16 +397,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodRevokeCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters $script:mockMethodRevokeCallCount | Should -Be 1 } @@ -472,16 +463,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodRevokeUsingWithGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } @@ -521,16 +510,14 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscDatabasePermission @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -546,8 +533,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { $script:localizedData.DatabasePermission_IgnoreWithGrantForStateDeny } - { $mockServerObject | Set-SqlDscDatabasePermission -WithGrant @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscDatabasePermission -WithGrant @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 diff --git a/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 b/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 index 6bb0d1b536..b4adfda54c 100644 --- a/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 @@ -111,8 +111,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -149,8 +148,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -187,8 +185,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should not call the mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 0 } @@ -224,16 +221,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodGrantCallCount | Should -Be 1 } @@ -287,16 +282,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } @@ -333,16 +326,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodRevokeCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodRevokeCallCount | Should -Be 1 } @@ -398,16 +389,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodRevokeUsingWithGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } @@ -444,16 +433,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -469,8 +456,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { $script:localizedData.ServerPermission_IgnoreWithGrantForStateDeny } - { $mockServerObject | Set-SqlDscServerPermission -WithGrant @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission -WithGrant @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 @@ -513,8 +499,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -551,8 +536,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -589,8 +573,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should not call the mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 0 } @@ -626,16 +609,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodGrantCallCount | Should -Be 1 } @@ -689,16 +670,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } @@ -735,16 +714,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodRevokeCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodRevokeCallCount | Should -Be 1 } @@ -800,16 +777,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodRevokeUsingWithGrantCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodGrantUsingWithGrantCallCount | Should -Be 1 } @@ -846,16 +821,14 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } It 'Should call the correct mocked method' { - { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Not -Throw + $null = Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } Context 'When passing ServerObject over the pipeline' { It 'Should call the correct mocked method' { - { $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 } @@ -871,8 +844,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { $script:localizedData.ServerPermission_IgnoreWithGrantForStateDeny } - { $mockServerObject | Set-SqlDscServerPermission -WithGrant @mockDefaultParameters } | - Should -Not -Throw + $null = $mockServerObject | Set-SqlDscServerPermission -WithGrant @mockDefaultParameters $script:mockMethodDenyCallCount | Should -Be 1 diff --git a/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 b/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 index 8d0fab8db0..e384e25076 100644 --- a/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 @@ -133,7 +133,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When passing SilentlyContinue to ErrorAction' { It 'Should not throw ' { - { Set-SqlDscStartupParameter -ServerName 'localhost' -TraceFlag @() -ErrorAction 'SilentlyContinue' } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -ServerName 'localhost' -TraceFlag @() -ErrorAction 'SilentlyContinue' Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 1 -Scope It } @@ -175,7 +175,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199') @@ -186,7 +186,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -Force # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199') @@ -197,7 +197,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly $mockStartupParameters @@ -208,7 +208,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When passing parameter ServerObject over the pipeline' { It 'Should call the mocked method and have correct value in the object' { - { $mockServiceObject | Set-SqlDscStartupParameter -TraceFlag 4199 -Force } | Should -Not -Throw + $null = $mockServiceObject | Set-SqlDscStartupParameter -TraceFlag 4199 -Force # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199') @@ -243,7 +243,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscStartupParameter -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -TraceFlag 4199 -Confirm:$false # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199') @@ -254,7 +254,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscStartupParameter -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -TraceFlag 4199 -Force # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-T4199') @@ -265,7 +265,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Set-SqlDscStartupParameter -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -TraceFlag 4199 -WhatIf # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly $mockStartupParameters @@ -300,7 +300,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscStartupParameter -TraceFlag @() -Force } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -TraceFlag @() -Force # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly $mockExpectedStartupParameters @@ -333,7 +333,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscStartupParameter -InternalTraceFlag 8688 -Confirm:$false } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -InternalTraceFlag 8688 -Confirm:$false # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly ($mockStartupParameters + ';-t8688') @@ -367,7 +367,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object, removed all internal trace flag ang kept normal trace flags' { - { Set-SqlDscStartupParameter -InternalTraceFlag @() -Force } | Should -Not -Throw + $null = Set-SqlDscStartupParameter -InternalTraceFlag @() -Force # This is the object created by the mock and modified by the command. $mockServiceObject.StartupParameters | Should -BeExactly $mockExpectedStartupParameters diff --git a/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 index 21e2839994..a612168ff0 100644 --- a/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 @@ -97,7 +97,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Confirm:$false -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { $TraceFlag -contains 4199 @@ -107,7 +107,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { $TraceFlag -contains 4199 @@ -117,7 +117,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Set-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -ServiceObject $mockServiceObject -TraceFlag 4199 -WhatIf -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -Exactly -Times 0 -Scope It } @@ -125,7 +125,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When passing parameter ServerObject over the pipeline' { It 'Should call the mocked method and have correct value in the object' { - { $mockServiceObject | Set-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw + $null = $mockServiceObject | Set-SqlDscTraceFlag -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { $TraceFlag -contains 4199 @@ -141,7 +141,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Confirm with value $false' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -TraceFlag 4199 -Confirm:$false -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { $TraceFlag -contains 4199 @@ -151,7 +151,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter Force' { It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscTraceFlag -TraceFlag 4199 -Force } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -TraceFlag 4199 -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { $TraceFlag -contains 4199 @@ -161,7 +161,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { Context 'When using parameter WhatIf' { It 'Should not call the mocked method and should not have changed the value in the object' { - { Set-SqlDscTraceFlag -TraceFlag 4199 -WhatIf } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -TraceFlag 4199 -WhatIf -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -Exactly -Times 0 -Scope It } @@ -174,7 +174,7 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { } It 'Should call the mocked method and have correct value in the object' { - { Set-SqlDscTraceFlag -TraceFlag @() -Force } | Should -Not -Throw + $null = Set-SqlDscTraceFlag -TraceFlag @() -Force -ErrorAction 'Stop' Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { $TraceFlag.Count -eq 0 diff --git a/tests/Unit/SqlServerDsc.Common.Tests.ps1 b/tests/Unit/SqlServerDsc.Common.Tests.ps1 index 3bae5eb98d..23d92a04d2 100644 --- a/tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -157,7 +157,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It @@ -179,7 +179,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It @@ -312,7 +312,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It @@ -326,7 +326,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It @@ -340,7 +340,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' } } @@ -365,7 +365,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPathWithSpaces } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' } It 'Should finish successfully with exit code 2' { @@ -376,7 +376,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPathWithSpaces } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' } It 'Should finish successfully with exit code 3' { @@ -387,7 +387,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPathWithSpaces } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = Copy-ItemWithRobocopy @copyItemWithRobocopyParameter -ErrorAction 'Stop' } } } @@ -430,14 +430,12 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } It 'Should call the correct mocks' { - { - $invokeInstallationMediaCopyParameters = @{ - SourcePath = $mockSourcePathUNCWithLeaf - SourceCredential = $mockShareCredential - } + $invokeInstallationMediaCopyParameters = @{ + SourcePath = $mockSourcePathUNCWithLeaf + SourceCredential = $mockShareCredential + } - Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - } | Should -Not -Throw + $null = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters -ErrorAction 'Stop' Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-Guid -Exactly -Times 0 -Scope It @@ -469,14 +467,12 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } It 'Should call the correct mocks' { - { - $invokeInstallationMediaCopyParameters = @{ - SourcePath = $mockSourcePathUNCWithLeaf - SourceCredential = $mockShareCredential - } + $invokeInstallationMediaCopyParameters = @{ + SourcePath = $mockSourcePathUNCWithLeaf + SourceCredential = $mockShareCredential + } - Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - } | Should -Not -Throw + $null = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters -ErrorAction 'Stop' Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-Guid -Exactly -Times 0 -Scope It @@ -508,14 +504,12 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } It 'Should call the correct mocks' { - { - $invokeInstallationMediaCopyParameters = @{ - SourcePath = $mockSourcePathUNC - SourceCredential = $mockShareCredential - } + $invokeInstallationMediaCopyParameters = @{ + SourcePath = $mockSourcePathUNC + SourceCredential = $mockShareCredential + } - Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - } | Should -Not -Throw + $null = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters -ErrorAction 'Stop' Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-Guid -Exactly -Times 1 -Scope It @@ -601,13 +595,11 @@ Describe 'SqlServerDsc.Common\Connect-UncPath' -Tag 'ConnectUncPath' { Context 'When connecting to a UNC path without credentials (using current credentials)' { It 'Should call the correct mocks' { - { - $connectUncPathParameters = @{ - RemotePath = $mockSourcePathUNC - } + $connectUncPathParameters = @{ + RemotePath = $mockSourcePathUNC + } - Connect-UncPath @connectUncPathParameters - } | Should -Not -Throw + $null = Connect-UncPath @connectUncPathParameters -ErrorAction 'Stop' Should -Invoke -CommandName New-SmbMapping -ParameterFilter { <# @@ -623,14 +615,12 @@ Describe 'SqlServerDsc.Common\Connect-UncPath' -Tag 'ConnectUncPath' { Context 'When connecting to a UNC path with specific credentials' { It 'Should call the correct mocks' { - { - $connectUncPathParameters = @{ - RemotePath = $mockSourcePathUNC - SourceCredential = $mockShareCredential - } + $connectUncPathParameters = @{ + RemotePath = $mockSourcePathUNC + SourceCredential = $mockShareCredential + } - Connect-UncPath @connectUncPathParameters - } | Should -Not -Throw + $null = Connect-UncPath @connectUncPathParameters -ErrorAction 'Stop' Should -Invoke -CommandName New-SmbMapping -ParameterFilter { $RemotePath -eq $mockSourcePathUNC ` @@ -641,14 +631,12 @@ Describe 'SqlServerDsc.Common\Connect-UncPath' -Tag 'ConnectUncPath' { Context 'When connecting using Fully Qualified Domain Name (FQDN)' { It 'Should call the correct mocks' { - { - $connectUncPathParameters = @{ - RemotePath = $mockSourcePathUNC - SourceCredential = $mockFqdnShareCredential - } + $connectUncPathParameters = @{ + RemotePath = $mockSourcePathUNC + SourceCredential = $mockFqdnShareCredential + } - Connect-UncPath @connectUncPathParameters - } | Should -Not -Throw + $null = Connect-UncPath @connectUncPathParameters -ErrorAction 'Stop' Should -Invoke -CommandName New-SmbMapping -ParameterFilter { $RemotePath -eq $mockSourcePathUNC ` @@ -694,13 +682,11 @@ Describe 'SqlServerDsc.Common\Disconnect-UncPath' -Tag 'DisconnectUncPath' { Context 'When disconnecting from an UNC path' { It 'Should call the correct mocks' { - { - $disconnectUncPathParameters = @{ - RemotePath = $mockSourcePathUNC - } + $disconnectUncPathParameters = @{ + RemotePath = $mockSourcePathUNC + } - Disconnect-UncPath @disconnectUncPathParameters - } | Should -Not -Throw + $null = Disconnect-UncPath @disconnectUncPathParameters Should -Invoke -CommandName Remove-SmbMapping -Exactly -Times 1 -Scope It } @@ -807,7 +793,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { } It 'Should restart SQL Service and running SQL Agent service' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -ParameterFilter { <# @@ -827,7 +813,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { Context 'When skipping the cluster check' { It 'Should restart SQL Service and running SQL Agent service' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -SkipClusterCheck } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -SkipClusterCheck -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -ParameterFilter { <# @@ -848,7 +834,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { Context 'When skipping the online check' { It 'Should restart SQL Service and running SQL Agent service and not wait for the SQL Server instance to come back online' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -SkipWaitForOnline } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -SkipWaitForOnline -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -ParameterFilter { <# @@ -896,7 +882,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { } It 'Should just call Restart-SqlClusterService to restart the SQL Server cluster instance' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -ErrorAction 'Stop' Should -Invoke -CommandName Connect-SQL -ParameterFilter { <# @@ -916,7 +902,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { Context 'When passing the Timeout value' { It 'Should just call Restart-SqlClusterService with the correct parameter' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -Timeout 120 } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -Timeout 120 -ErrorAction 'Stop' Should -Invoke -CommandName Restart-SqlClusterService -ParameterFilter { <# @@ -930,7 +916,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { Context 'When passing the OwnerNode value' { It 'Should just call Restart-SqlClusterService with the correct parameter' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -OwnerNode @('TestNode') } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -OwnerNode @('TestNode') -ErrorAction 'Stop' Should -Invoke -CommandName Restart-SqlClusterService -ParameterFilter { <# @@ -968,7 +954,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { } It 'Should restart SQL Service and not try to restart missing SQL Agent service' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'NOAGENT' -SkipClusterCheck } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'NOAGENT' -SkipClusterCheck -ErrorAction 'Stop' Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 @@ -1008,7 +994,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { } It 'Should restart SQL Service and not try to restart stopped SQL Agent service' { - { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'STOPPEDAGENT' -SkipClusterCheck } | Should -Not -Throw + $null = Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'STOPPEDAGENT' -SkipClusterCheck -ErrorAction 'Stop' Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 @@ -1149,7 +1135,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should not restart any cluster resources' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -ErrorAction 'Stop' } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1178,7 +1164,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should not restart any cluster resources' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -ErrorAction 'Stop' } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1227,7 +1213,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should restart SQL Server cluster resource and the SQL Agent cluster resource' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -ErrorAction 'Stop' } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1279,7 +1265,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should restart SQL Server cluster resource and the SQL Agent cluster resource' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'DSCTEST' } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'DSCTEST' -ErrorAction 'Stop' } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1332,7 +1318,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should restart the SQL Server cluster resource and ignore the SQL Agent cluster resource online ' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1383,7 +1369,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should restart the SQL Server cluster resource and the SQL Agent cluster resource' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1437,7 +1423,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should only restart the SQL Server cluster resource' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1491,7 +1477,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should only restart the SQL Server cluster resource' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1534,7 +1520,7 @@ Describe 'SqlServerDsc.Common\Restart-SqlClusterService' -Tag 'RestartSqlCluster It 'Should not restart any cluster resources' { InModuleScope -ScriptBlock { - { Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } | Should -Not -Throw + $null = Restart-SqlClusterService -InstanceName 'MSSQLSERVER' -OwnerNode @('NODE1') } Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 @@ -1618,7 +1604,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { Context 'When connecting to the default instance using Windows Authentication' { It 'Should not throw when connecting' { - { Connect-SQLAnalysis -FeatureFlag 'AnalysisServicesConnection' } | Should -Not -Throw + $null = Connect-SQLAnalysis -FeatureFlag 'AnalysisServicesConnection' Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` @@ -1652,7 +1638,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName\$mockInstanceName" - { Connect-SQLAnalysis -InstanceName $mockInstanceName -FeatureFlag 'AnalysisServicesConnection' } | Should -Not -Throw + $null = Connect-SQLAnalysis -InstanceName $mockInstanceName -FeatureFlag 'AnalysisServicesConnection' } } @@ -1660,7 +1646,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName\$mockInstanceName;User ID=$mockSqlCredentialUserName;Password=$mockSqlCredentialPassword" - { Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockSqlCredential -FeatureFlag 'AnalysisServicesConnection' } | Should -Not -Throw + $null = Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockSqlCredential -FeatureFlag 'AnalysisServicesConnection' } } } @@ -1674,7 +1660,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName" - { Connect-SQLAnalysis } | Should -Not -Throw + $null = Connect-SQLAnalysis Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1685,7 +1671,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName\$mockInstanceName" - { Connect-SQLAnalysis -InstanceName $mockInstanceName } | Should -Not -Throw + $null = Connect-SQLAnalysis -InstanceName $mockInstanceName Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1697,7 +1683,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName\$mockInstanceName;User ID=$mockSqlCredentialUserName;Password=$mockSqlCredentialPassword" - { Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockSqlCredential } | Should -Not -Throw + $null = Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockSqlCredential Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1708,7 +1694,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName\$mockInstanceName;User ID=$mockNetBiosSqlCredentialUserName;Password=$mockNetBiosSqlCredentialPassword" - { Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockNetBiosSqlCredential } | Should -Not -Throw + $null = Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockNetBiosSqlCredential Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1719,7 +1705,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { It 'Should not throw when connecting' { $mockExpectedDataSource = "Data Source=$mockComputerName\$mockInstanceName;User ID=$mockFqdnSqlCredentialUserName;Password=$mockFqdnSqlCredentialPassword" - { Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockFqdnSqlCredential } | Should -Not -Throw + $null = Connect-SQLAnalysis -InstanceName $mockInstanceName -SetupCredential $mockFqdnSqlCredential Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter @@ -1806,7 +1792,7 @@ Describe 'SqlServerDsc.Common\Update-AvailabilityGroupReplica' -Tag 'UpdateAvail It 'Should silently alter the Availability Group Replica' { $availabilityReplica = New-Object -TypeName Microsoft.SqlServer.Management.Smo.AvailabilityReplica - { Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityReplica } | Should -Not -Throw + $null = Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityReplica } It 'Should throw the correct error, AlterAvailabilityGroupReplicaFailed, when altering the Availability Group Replica fails' { @@ -2571,7 +2557,7 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { } Context 'When connecting to the default instance using the correct service instance but does not return a correct Database Engine object' { - Context 'When using ErrorAction set to Stop' { + Context 'When using ErrorAction set to Stop' -Skip:($IsLinux -or $IsMacOS) { BeforeAll { Mock -CommandName New-Object -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.Server' @@ -2650,8 +2636,7 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { } It 'Should not throw an exception' { - { Connect-SQL -ServerName 'localhost' -SetupCredential $mockSqlCredential -LoginType 'SqlLogin' -ErrorAction 'SilentlyContinue' } | - Should -Not -Throw + $null = Connect-SQL -ServerName 'localhost' -SetupCredential $mockSqlCredential -LoginType 'SqlLogin' -ErrorAction 'SilentlyContinue' Should -Invoke -CommandName New-Object -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.Server' @@ -2846,7 +2831,7 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -InstanceName 'MSSQLSERVER' } | Should -Not -Throw + $null = Restart-ReportingServicesService -InstanceName 'MSSQLSERVER' Should -Invoke -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName @@ -2871,7 +2856,7 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -InstanceName 'SSRS' } | Should -Not -Throw + $null = Restart-ReportingServicesService -InstanceName 'SSRS' Should -Invoke -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName @@ -2896,7 +2881,7 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -InstanceName 'TEST' } | Should -Not -Throw + $null = Restart-ReportingServicesService -InstanceName 'TEST' Should -Invoke -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName @@ -2922,7 +2907,7 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep } It 'Should restart the service and dependent service' { - { Restart-ReportingServicesService -InstanceName 'TEST' -WaitTime 1 } | Should -Not -Throw + $null = Restart-ReportingServicesService -InstanceName 'TEST' -WaitTime 1 Should -Invoke -CommandName Get-Service -ParameterFilter { $Name -eq $mockServiceName diff --git a/tests/Unit/Stubs/Write-ModuleStubFile.ps1 b/tests/Unit/Stubs/Write-ModuleStubFile.ps1 index 101124e222..2dfde03bec 100644 --- a/tests/Unit/Stubs/Write-ModuleStubFile.ps1 +++ b/tests/Unit/Stubs/Write-ModuleStubFile.ps1 @@ -28,7 +28,7 @@ function Write-ModuleStubFile ) # Import the supplied module - Import-Module -Name $ModuleName -DisableNameChecking -Force -ErrorAction Stop + Import-Module -Name $ModuleName -DisableNameChecking -Force -ErrorAction 'Stop' # Get the module object $module = Get-Module -Name $ModuleName