diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dfe4952b..9f1602556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - SqlSetup - - Added new parameter ProductCoveredbySA which is introduced in SQL 2022. + - Added new parameter ProductCoveredBySA which is introduced in SQL 2022. ### Added @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SqlServerDsc - Replaced inline task `Package_Wiki_Content` with the one now available in the module _DscResource.DocGenerator_. + - Update tests to Pester 6 format. - `Connect-SqlDscDatabaseEngine` - Update comment-based help with more examples. - SqlSetup diff --git a/Resolve-Dependency.psd1 b/Resolve-Dependency.psd1 index 07945f819..ed3e063b8 100644 --- a/Resolve-Dependency.psd1 +++ b/Resolve-Dependency.psd1 @@ -3,11 +3,11 @@ AllowPrerelease = $false WithYAML = $true - #UseModuleFast = $true + UseModuleFast = $true #ModuleFastVersion = '0.1.2' #ModuleFastBleedingEdge = $true - UsePSResourceGet = $true + #UsePSResourceGet = $true #PSResourceGetVersion = '1.0.1' UsePowerShellGetCompatibilityModule = $true diff --git a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 index c2764332a..f9e5801ec 100644 --- a/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1 @@ -54,25 +54,23 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati It 'Should have the default instance SQL Server service started' { $getServiceResult = Get-Service -Name 'MSSQLSERVER' -ErrorAction 'Stop' - $getServiceResult.Status | Should -Be 'Running' + $getServiceResult.Status | Should-Be 'Running' } 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-MatchString '^Online$' } } } @@ -91,47 +89,43 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati It 'Should have the named instance SQL Server service started' { $getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' - $getServiceResult.Status | Should -Be 'Running' + $getServiceResult.Status | Should-Be 'Running' } 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-MatchString '^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-MatchString '^Online$' } } } diff --git a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 index a74ab0417..fd96b0ed2 100644 --- a/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Install-SqlDscServer.Integration.Tests.ps1 @@ -34,7 +34,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 Context 'When using Install parameter set' { Context 'When installing database engine default instance' { It 'Should run the command without throwing' { - { + $null = & ({ # Set splatting parameters for Install-SqlDscServer $installSqlDscServerParameters = @{ Install = $true @@ -141,15 +141,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 # (Get-ComputerName), # $modulePath # ) - } | Should -Not -Throw + }) } It 'Should have installed the SQL Server database engine' { # Validate the SQL Server installation $sqlServerService = Get-Service -Name 'MSSQLSERVER' - $sqlServerService | Should -Not -BeNullOrEmpty - $sqlServerService.Status | Should -Be 'Running' + $sqlServerService | Should-BeTruthy + $sqlServerService.Status | Should-Be 'Running' } It 'Should stop the default instance SQL Server service' { @@ -165,7 +165,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 #> $stopServiceResult | Where-Object -FilterScript { $_.Name -eq 'MSSQLSERVER'} - ).Status | Should -Be 'Stopped' + ).Status | Should-Be 'Stopped' } } @@ -176,7 +176,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 # } It 'Should run the command without throwing' { - { + $null = & ({ # Set splatting parameters for Install-SqlDscServer $installSqlDscServerParameters = @{ Install = $true @@ -285,15 +285,15 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 # $modulePath # ) # } | Should -Not -Throw - } | Should -Not -Throw + }) } It 'Should have installed the SQL Server database engine' { # Validate the SQL Server installation $sqlServerService = Get-Service -Name 'MSSQL$DSCSQLTEST' - $sqlServerService | Should -Not -BeNullOrEmpty - $sqlServerService.Status | Should -Be 'Running' + $sqlServerService | Should-BeTruthy + $sqlServerService.Status | Should-Be 'Running' } It 'Should stop the named instance SQL Server service' { @@ -307,7 +307,7 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 #> $stopServiceResult | Where-Object -FilterScript { $_.Name -eq 'MSSQL$DSCSQLTEST' } - ).Status | Should -Be 'Stopped' + ).Status | Should-Be 'Stopped' } } diff --git a/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 b/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 index 9bae6bbbe..fdd2dde9c 100644 --- a/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Prerequisites.Integration.Tests.ps1 @@ -33,15 +33,15 @@ Describe 'Prerequisites' { It 'Should create SqlInstall user' { $user = New-LocalUser -Name 'SqlInstall' -Password $password -FullName 'SQL Install User' -Description 'User for SQL installation.' - $user.Name | Should -Be 'SqlInstall' - (Get-LocalUser -Name 'SqlInstall').Name | Should -Be 'SqlInstall' + $user.Name | Should-Be 'SqlInstall' + (Get-LocalUser -Name 'SqlInstall').Name | Should-Be 'SqlInstall' } It 'Should create SqlAdmin user' { $user = New-LocalUser -Name 'SqlAdmin' -Password $password -FullName 'SQL Admin User' -Description 'User for SQL administration.' - $user.Name | Should -Be 'SqlAdmin' - (Get-LocalUser -Name 'SqlAdmin').Name | Should -Be 'SqlAdmin' + $user.Name | Should-Be 'SqlAdmin' + (Get-LocalUser -Name 'SqlAdmin').Name | Should-Be 'SqlAdmin' } } @@ -53,29 +53,29 @@ Describe 'Prerequisites' { It 'Should create svc-SqlPrimary user' { $user = New-LocalUser -Name 'svc-SqlPrimary' -Password $password -FullName 'svc-SqlPrimary' -Description 'Runs the SQL Server service.' - $user.Name | Should -Be 'svc-SqlPrimary' - (Get-LocalUser -Name 'svc-SqlPrimary').Name | Should -Be 'svc-SqlPrimary' + $user.Name | Should-Be 'svc-SqlPrimary' + (Get-LocalUser -Name 'svc-SqlPrimary').Name | Should-Be 'svc-SqlPrimary' } It 'Should create svc-SqlAgentPri user' { $user = New-LocalUser -Name 'svc-SqlAgentPri' -Password $password -FullName 'svc-SqlAgentPri' -Description 'Runs the SQL Server Agent service.' - $user.Name | Should -Be 'svc-SqlAgentPri' - (Get-LocalUser -Name 'svc-SqlAgentPri').Name | Should -Be 'svc-SqlAgentPri' + $user.Name | Should-Be 'svc-SqlAgentPri' + (Get-LocalUser -Name 'svc-SqlAgentPri').Name | Should-Be 'svc-SqlAgentPri' } It 'Should create svc-SqlSecondary user' { $user = New-LocalUser -Name 'svc-SqlSecondary' -Password $password -FullName 'svc-SqlSecondary' -Description 'Runs the SQL Server service.' - $user.Name | Should -Be 'svc-SqlSecondary' - (Get-LocalUser -Name 'svc-SqlSecondary').Name | Should -Be 'svc-SqlSecondary' + $user.Name | Should-Be 'svc-SqlSecondary' + (Get-LocalUser -Name 'svc-SqlSecondary').Name | Should-Be 'svc-SqlSecondary' } It 'Should create svc-SqlAgentSec user' { $user = New-LocalUser -Name 'svc-SqlAgentSec' -Password $password -FullName 'svc-SqlAgentSec' -Description 'Runs the SQL Server Agent service.' - $user.Name | Should -Be 'svc-SqlAgentSec' - (Get-LocalUser -Name 'svc-SqlAgentSec').Name | Should -Be 'svc-SqlAgentSec' + $user.Name | Should-Be 'svc-SqlAgentSec' + (Get-LocalUser -Name 'svc-SqlAgentSec').Name | Should-Be 'svc-SqlAgentSec' } } @@ -87,7 +87,7 @@ Describe 'Prerequisites' { # Verify if user is part of local administrator group $adminGroup = Get-LocalGroup -Name 'Administrators' $adminGroupMembers = Get-LocalGroupMember -Group $adminGroup - $adminGroupMembers.Name | Should -Contain ('{0}\SqlInstall' -f (Get-ComputerName)) + $adminGroupMembers.Name | Should-ContainCollection ('{0}\SqlInstall' -f (Get-ComputerName)) } } @@ -97,7 +97,7 @@ Describe 'Prerequisites' { $script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop' - $mediaFile.Name | Should -Be 'media.iso' + $mediaFile.Name | Should-Be 'media.iso' } It 'Should download SQL Server 2017 media' -Tag @('Integration_SQL2017') { @@ -105,7 +105,7 @@ Describe 'Prerequisites' { $script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop' - $mediaFile.Name | Should -Be 'media.iso' + $mediaFile.Name | Should-Be 'media.iso' } It 'Should download SQL Server 2019 media' -Tag @('Integration_SQL2019') { @@ -113,7 +113,7 @@ Describe 'Prerequisites' { $script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop' - $mediaFile.Name | Should -Be 'media.iso' + $mediaFile.Name | Should-Be 'media.iso' } It 'Should download SQL Server 2022 media' -Tag @('Integration_SQL2022') { @@ -121,31 +121,31 @@ Describe 'Prerequisites' { $script:mediaFile = Save-SqlDscSqlServerMediaFile -Url $url -DestinationPath $env:TEMP -Force -Quiet -ErrorAction 'Stop' - $mediaFile.Name | Should -Be 'media.iso' + $mediaFile.Name | Should-Be 'media.iso' } } Context 'Mount SQL Server media' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { It 'Should mount the media to a drive letter' { $mountedImage = Mount-DiskImage -ImagePath $script:mediaFile - $mountedImage | Should -BeOfType 'Microsoft.Management.Infrastructure.CimInstance' + $mountedImage | Should-HaveType 'Microsoft.Management.Infrastructure.CimInstance' $mountedVolume = Get-Volume -DiskImage $mountedImage - $mountedVolume.DriveLetter | Should -Not -BeNullOrEmpty + $mountedVolume.DriveLetter | Should-BeTruthy $env:IsoDriveLetter = $mountedVolume.DriveLetter - $env:IsoDriveLetter | Should -Not -BeNullOrEmpty + $env:IsoDriveLetter | Should-BeTruthy $env:IsoDrivePath = (Get-PSDrive -Name $env:IsoDriveLetter).Root - $env:IsoDrivePath | Should -Be ('{0}:\' -f $env:IsoDriveLetter) + $env:IsoDrivePath | Should-Be ('{0}:\' -f $env:IsoDriveLetter) } It 'Should have set environment variable for drive letter' { - $env:IsoDriveLetter | Should -Not -BeNullOrEmpty + $env:IsoDriveLetter | Should-BeTruthy } It 'Should have set environment variable for drive path' { - $env:IsoDrivePath | Should -Be ('{0}:\' -f $env:IsoDriveLetter) + $env:IsoDrivePath | Should-Be ('{0}:\' -f $env:IsoDriveLetter) } } @@ -153,45 +153,45 @@ Describe 'Prerequisites' { It 'Should have the minimum required version of Microsoft.PowerShell.PSResourceGet' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { $module = Get-Module -Name 'Microsoft.PowerShell.PSResourceGet' -ListAvailable - $module | Should -HaveCount 1 - $module.Version -ge '1.0.4.1' | Should -BeTrue + $module | Should-BeCollection -Count 1 + $module.Version -ge '1.0.4.1' | Should-BeTrue } It 'Should have a resource repository PSGallery with correct URI' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019', 'Integration_SQL2022') { $resourceRepository = Get-PSResourceRepository -Name 'PSGallery' - $resourceRepository | Should -HaveCount 1 - $resourceRepository.Uri | Should -Be 'https://www.powershellgallery.com/api/v2' + $resourceRepository | Should-BeCollection -Count 1 + $resourceRepository.Uri | Should-Be 'https://www.powershellgallery.com/api/v2' } It 'Should install SqlServer module version 21.1.18256' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019') { #Install-Module -Name 'SqlServer' -RequiredVersion '21.1.18256' -Force -ErrorAction 'Stop' $module = Install-PSResource -Name 'SqlServer' -Version '21.1.18256' -Scope 'AllUsers' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru - $module | Should -HaveCount 1 - $module.Version -eq '21.1.18256' | Should -BeTrue + $module | Should-BeCollection -Count 1 + $module.Version -eq '21.1.18256' | Should-BeTrue } It 'Should have SqlServer module version 21.1.18256 available' -Tag @('Integration_SQL2016', 'Integration_SQL2017', 'Integration_SQL2019') { $module = Get-Module -Name 'SqlServer' -ListAvailable - $module | Should -HaveCount 1 - $module.Version -eq '21.1.18256' | Should -BeTrue + $module | Should-BeCollection -Count 1 + $module.Version -eq '21.1.18256' | Should-BeTrue } It 'Should install SqlServer module version 22.2.0' -Tag @('Integration_SQL2022') { #Install-Module -Name 'SqlServer' -RequiredVersion '22.2.0' -Force -ErrorAction 'Stop' $module = Install-PSResource -Name 'SqlServer' -Version '22.2.0' -Scope 'AllUsers' -TrustRepository -ErrorAction 'Stop' -Confirm:$false -PassThru - $module | Should -HaveCount 1 - $module.Version -eq '22.2.0' | Should -BeTrue + $module | Should-BeCollection -Count 1 + $module.Version -eq '22.2.0' | Should-BeTrue } It 'Should have SqlServer module version 22.2.0 available' -Tag @('Integration_SQL2022') { $module = Get-Module -Name 'SqlServer' -ListAvailable - $module | Should -HaveCount 1 - $module.Version -eq '22.2.0' | Should -BeTrue + $module | Should-BeCollection -Count 1 + $module.Version -eq '22.2.0' | Should-BeTrue } } @@ -201,7 +201,7 @@ Describe 'Prerequisites' { # TODO: This fails on Appveyor, but works locally when debugging on AppVeyor. Investigate why. $result = Invoke-Command -ComputerName 'localhost' -ScriptBlock { 1 } -ErrorAction 'Stop' - $result | Should -Be 1 + $result | Should-Be 1 } } } diff --git a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 index 424081b5e..371b11449 100644 --- a/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 +++ b/tests/Integration/Commands/Uninstall-SqlDscServer.Integration.Tests.ps1 @@ -37,12 +37,12 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 It 'Should have the named instance SQL Server service started' { $getServiceResult = Get-Service -Name 'MSSQL$DSCSQLTEST' -ErrorAction 'Stop' - $getServiceResult.Status | Should -Be 'Running' + $getServiceResult.Status | Should-Be 'Running' } Context 'When uninstalling a named instance' { It 'Should run the command without throwing' { - { + $null = & ({ # Set splatting parameters for Uninstall-SqlDscServer $uninstallSqlDscServerParameters = @{ InstanceName = 'DSCSQLTEST' @@ -54,11 +54,11 @@ Describe 'Install-SqlDscServer' -Tag @('Integration_SQL2016', 'Integration_SQL20 } Uninstall-SqlDscServer @uninstallSqlDscServerParameters - } | Should -Not -Throw + }) } It 'Should not have a named instance SQL Server service' { - Get-Service -Name 'SQL Server (DSCSQLTEST)' -ErrorAction 'Ignore' | Should -BeNullOrEmpty + Get-Service -Name 'SQL Server (DSCSQLTEST)' -ErrorAction 'Ignore' | Should-BeFalsy } } } diff --git a/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 index 2432c6dda..2a770d055 100644 --- a/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAgentAlert.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,13 +101,13 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.Name - $resourceCurrentState.Severity | Should -Be $ConfigurationData.AllNodes.Severity + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.Name + $resourceCurrentState.Severity | Should-Be $ConfigurationData.AllNodes.Severity } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -123,7 +123,7 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -142,13 +142,13 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -157,13 +157,13 @@ Describe "_Integration" -Tag @('Integration_SQL2016', ' -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -BeNullOrEmpty - $resourceCurrentState.Severity | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-BeFalsy + $resourceCurrentState.Severity | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 index 94afa38fb..94fea4971 100644 --- a/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAgentFailsafe.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,13 +101,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.Name - $resourceCurrentState.NotificationMethod | Should -Be $ConfigurationData.AllNodes.NotificationMethod + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.Name + $resourceCurrentState.NotificationMethod | Should-Be $ConfigurationData.AllNodes.NotificationMethod } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -123,7 +123,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -142,13 +142,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -157,13 +157,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -BeNullOrEmpty - $resourceCurrentState.NotificationMethod | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-BeFalsy + $resourceCurrentState.NotificationMethod | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 index 33237c45d..012e7823e 100644 --- a/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAgentOperator.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,13 +101,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.Name - $resourceCurrentState.EmailAddress | Should -Be $ConfigurationData.AllNodes.EmailAddress + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.Name + $resourceCurrentState.EmailAddress | Should-Be $ConfigurationData.AllNodes.EmailAddress } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -123,7 +123,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -142,13 +142,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -157,13 +157,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.Name - $resourceCurrentState.EmailAddress | Should -Be $ConfigurationData.AllNodes.NewEmailAddress1 + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.Name + $resourceCurrentState.EmailAddress | Should-Be $ConfigurationData.AllNodes.NewEmailAddress1 } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -179,7 +179,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -198,13 +198,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -213,13 +213,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.Name - $resourceCurrentState.EmailAddress | Should -Be ('{0};{1}' -f $ConfigurationData.AllNodes.NewEmailAddress1, $ConfigurationData.AllNodes.NewEmailAddress2 ) + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.Name + $resourceCurrentState.EmailAddress | Should-Be ('{0};{1}' -f $ConfigurationData.AllNodes.NewEmailAddress1, $ConfigurationData.AllNodes.NewEmailAddress2 ) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -235,7 +235,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -254,13 +254,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -269,13 +269,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -BeNullOrEmpty - $resourceCurrentState.EmailAddress | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-BeFalsy + $resourceCurrentState.EmailAddress | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 index b75f120ab..49bf54db5 100644 --- a/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAlwaysOnService.Integration.Tests.ps1 @@ -87,7 +87,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -106,7 +106,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -122,7 +122,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -141,13 +141,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -156,11 +156,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' + $resourceCurrentState.Ensure | Should-Be 'Present' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -176,7 +176,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -195,13 +195,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -210,11 +210,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' + $resourceCurrentState.Ensure | Should-Be 'Absent' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -230,7 +230,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -249,7 +249,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag 'Skip' { } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 index a9e0c63fd..f52b4b74c 100644 --- a/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlAudit.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,7 +86,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -102,7 +102,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -121,13 +121,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -136,18 +136,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.AuditName1 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.Path1 - $resourceCurrentState.MaximumFileSize | Should -Be $ConfigurationData.AllNodes.MaximumFileSize1 - $resourceCurrentState.MaximumFileSizeUnit | Should -Be $ConfigurationData.AllNodes.MaximumFileSizeUnit1 - $resourceCurrentState.MaximumRolloverFiles | Should -Be $ConfigurationData.AllNodes.MaximumRolloverFiles1 + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.AuditName1 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Path | Should-Be $ConfigurationData.AllNodes.Path1 + $resourceCurrentState.MaximumFileSize | Should-Be $ConfigurationData.AllNodes.MaximumFileSize1 + $resourceCurrentState.MaximumFileSizeUnit | Should-Be $ConfigurationData.AllNodes.MaximumFileSizeUnit1 + $resourceCurrentState.MaximumRolloverFiles | Should-Be $ConfigurationData.AllNodes.MaximumRolloverFiles1 } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -163,7 +163,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -182,13 +182,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -197,16 +197,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.AuditName2 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.LogType | Should -Be $ConfigurationData.AllNodes.LogType2 - $resourceCurrentState.AuditFilter | Should -Be $ConfigurationData.AllNodes.AuditFilter2 + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.AuditName2 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.LogType | Should-Be $ConfigurationData.AllNodes.LogType2 + $resourceCurrentState.AuditFilter | Should-Be $ConfigurationData.AllNodes.AuditFilter2 } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -222,7 +222,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -241,13 +241,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -256,16 +256,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.AuditName2 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.LogType | Should -Be $ConfigurationData.AllNodes.LogType2 - $resourceCurrentState.AuditFilter | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.AuditName2 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.LogType | Should-Be $ConfigurationData.AllNodes.LogType2 + $resourceCurrentState.AuditFilter | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -281,7 +281,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -300,13 +300,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -315,18 +315,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.AuditName1 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Path | Should -BeNullOrEmpty - $resourceCurrentState.MaximumFileSize | Should -BeNullOrEmpty - $resourceCurrentState.MaximumFileSizeUnit | Should -BeNullOrEmpty - $resourceCurrentState.MaximumRolloverFiles | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.AuditName1 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Path | Should-BeFalsy + $resourceCurrentState.MaximumFileSize | Should-BeFalsy + $resourceCurrentState.MaximumFileSizeUnit | Should-BeFalsy + $resourceCurrentState.MaximumRolloverFiles | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -342,7 +342,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -361,13 +361,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -376,16 +376,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.AuditName2 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.LogType | Should -BeNullOrEmpty - $resourceCurrentState.AuditFilter | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.AuditName2 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.LogType | Should-BeFalsy + $resourceCurrentState.AuditFilter | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 index 363ee55cd..0a2f24c4d 100644 --- a/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabase.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,18 +101,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DatabaseName1 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DatabaseName1 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName # Same as the instance collation - $resourceCurrentState.Collation | Should -Be 'Finnish_Swedish_CI_AS' - $resourceCurrentState.RecoveryModel | Should -Be 'Full' - $resourceCurrentState.OwnerName | Should -Be ('{0}\SqlAdmin' -f $env:COMPUTERNAME) + $resourceCurrentState.Collation | Should-Be 'Finnish_Swedish_CI_AS' + $resourceCurrentState.RecoveryModel | Should-Be 'Full' + $resourceCurrentState.OwnerName | Should-Be ('{0}\SqlAdmin' -f $env:COMPUTERNAME) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -128,7 +128,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -147,13 +147,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -162,15 +162,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DatabaseName2 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Collation | Should -Be $ConfigurationData.AllNodes.Collation + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DatabaseName2 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Collation | Should-Be $ConfigurationData.AllNodes.Collation } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -186,7 +186,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -205,13 +205,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -220,15 +220,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DatabaseName3 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.CompatibilityLevel | Should -Be $ConfigurationData.AllNodes.CompatibilityLevel + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DatabaseName3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.CompatibilityLevel | Should-Be $ConfigurationData.AllNodes.CompatibilityLevel } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -244,7 +244,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -263,13 +263,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -278,15 +278,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DatabaseName4 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.RecoveryModel | Should -Be $ConfigurationData.AllNodes.RecoveryModel + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DatabaseName4 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.RecoveryModel | Should-Be $ConfigurationData.AllNodes.RecoveryModel } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -302,7 +302,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -321,13 +321,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -336,15 +336,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DatabaseName5 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.OwnerName | Should -Be $ConfigurationData.AllNodes.OwnerName + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DatabaseName5 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.OwnerName | Should-Be $ConfigurationData.AllNodes.OwnerName } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -360,7 +360,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -379,13 +379,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -394,18 +394,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DatabaseName2 - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Collation | Should -BeNullOrEmpty - $resourceCurrentState.OwnerName | Should -BeNullOrEmpty - $resourceCurrentState.RecoveryModel | Should -BeNullOrEmpty - $resourceCurrentState.CompatibilityLevel | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DatabaseName2 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Collation | Should-BeFalsy + $resourceCurrentState.OwnerName | Should-BeFalsy + $resourceCurrentState.RecoveryModel | Should-BeFalsy + $resourceCurrentState.CompatibilityLevel | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -421,7 +421,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -440,7 +440,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 index bb9646b6c..7c61fe4f7 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseDefaultLocation.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,12 +101,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Type | Should -Be 'Data' - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.DataFilePath + $resourceCurrentState.Type | Should-Be 'Data' + $resourceCurrentState.Path | Should-Be $ConfigurationData.AllNodes.DataFilePath } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -122,7 +122,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -141,13 +141,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -156,12 +156,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Type | Should -Be 'Log' - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.LogFilePath + $resourceCurrentState.Type | Should-Be 'Log' + $resourceCurrentState.Path | Should-Be $ConfigurationData.AllNodes.LogFilePath } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -177,7 +177,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -196,13 +196,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -211,13 +211,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Type | Should -Be 'Backup' + $resourceCurrentState.Type | Should-Be 'Backup' # Ending backslash is removed because of regression test for issue #1307. - $resourceCurrentState.Path | Should -Be $ConfigurationData.AllNodes.BackupFilePath.TrimEnd('\') + $resourceCurrentState.Path | Should-Be $ConfigurationData.AllNodes.BackupFilePath.TrimEnd('\') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 index c55a473d6..312e0502b 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseMail.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,20 +101,20 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.AccountName | Should -Be $ConfigurationData.AllNodes.AccountName - $resourceCurrentState.ProfileName | Should -Be $ConfigurationData.AllNodes.ProfileName - $resourceCurrentState.EmailAddress | Should -Be $ConfigurationData.AllNodes.EmailAddress - $resourceCurrentState.ReplyToAddress | Should -Be $ConfigurationData.AllNodes.EmailAddress - $resourceCurrentState.DisplayName | Should -Be $ConfigurationData.AllNodes.MailServerName - $resourceCurrentState.MailServerName | Should -Be $ConfigurationData.AllNodes.MailServerName - $resourceCurrentState.Description | Should -Be $ConfigurationData.AllNodes.Description - $resourceCurrentState.LoggingLevel | Should -Be $ConfigurationData.AllNodes.LoggingLevel - $resourceCurrentState.TcpPort | Should -Be $ConfigurationData.AllNodes.TcpPort + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.AccountName | Should-Be $ConfigurationData.AllNodes.AccountName + $resourceCurrentState.ProfileName | Should-Be $ConfigurationData.AllNodes.ProfileName + $resourceCurrentState.EmailAddress | Should-Be $ConfigurationData.AllNodes.EmailAddress + $resourceCurrentState.ReplyToAddress | Should-Be $ConfigurationData.AllNodes.EmailAddress + $resourceCurrentState.DisplayName | Should-Be $ConfigurationData.AllNodes.MailServerName + $resourceCurrentState.MailServerName | Should-Be $ConfigurationData.AllNodes.MailServerName + $resourceCurrentState.Description | Should-Be $ConfigurationData.AllNodes.Description + $resourceCurrentState.LoggingLevel | Should-Be $ConfigurationData.AllNodes.LoggingLevel + $resourceCurrentState.TcpPort | Should-Be $ConfigurationData.AllNodes.TcpPort } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -130,7 +130,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -149,17 +149,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -175,7 +175,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -194,13 +194,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -209,20 +209,20 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.AccountName | Should -BeNullOrEmpty - $resourceCurrentState.ProfileName | Should -BeNullOrEmpty - $resourceCurrentState.EmailAddress | Should -BeNullOrEmpty - $resourceCurrentState.ReplyToAddress | Should -BeNullOrEmpty - $resourceCurrentState.DisplayName | Should -BeNullOrEmpty - $resourceCurrentState.MailServerName | Should -BeNullOrEmpty - $resourceCurrentState.Description | Should -BeNullOrEmpty - $resourceCurrentState.LoggingLevel | Should -BeNullOrEmpty - $resourceCurrentState.TcpPort | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.AccountName | Should-BeFalsy + $resourceCurrentState.ProfileName | Should-BeFalsy + $resourceCurrentState.EmailAddress | Should-BeFalsy + $resourceCurrentState.ReplyToAddress | Should-BeFalsy + $resourceCurrentState.DisplayName | Should-BeFalsy + $resourceCurrentState.MailServerName | Should-BeFalsy + $resourceCurrentState.Description | Should-BeFalsy + $resourceCurrentState.LoggingLevel | Should-BeFalsy + $resourceCurrentState.TcpPort | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 index 04c54d5c7..a4f0bc0cd 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseObjectPermission.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,7 +86,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -102,7 +102,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -121,7 +121,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -137,7 +137,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -156,7 +156,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -176,7 +176,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -195,13 +195,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -210,27 +210,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.SchemaName | Should -Be $ConfigurationData.AllNodes.SchemaName - $resourceCurrentState.ObjectName | Should -Be $ConfigurationData.AllNodes.TableName - $resourceCurrentState.ObjectType | Should -Be 'Table' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Force | Should -BeFalse + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.SchemaName | Should-Be $ConfigurationData.AllNodes.SchemaName + $resourceCurrentState.ObjectName | Should-Be $ConfigurationData.AllNodes.TableName + $resourceCurrentState.ObjectType | Should-Be 'Table' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Force | Should-BeFalse - $resourceCurrentState.Permission | Should -HaveCount 1 - $resourceCurrentState.Permission[0] | Should -BeOfType 'CimInstance' + $resourceCurrentState.Permission | Should-BeCollection -Count 1 + $resourceCurrentState.Permission[0] | Should-HaveType 'CimInstance' $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'GrantWithGrant' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -251,7 +251,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -270,13 +270,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -285,27 +285,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.SchemaName | Should -Be $ConfigurationData.AllNodes.SchemaName - $resourceCurrentState.ObjectName | Should -Be $ConfigurationData.AllNodes.TableName - $resourceCurrentState.ObjectType | Should -Be 'Table' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Force | Should -BeTrue + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.SchemaName | Should-Be $ConfigurationData.AllNodes.SchemaName + $resourceCurrentState.ObjectName | Should-Be $ConfigurationData.AllNodes.TableName + $resourceCurrentState.ObjectType | Should-Be 'Table' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Force | Should-BeTrue - $resourceCurrentState.Permission | Should -HaveCount 1 - $resourceCurrentState.Permission[0] | Should -BeOfType 'CimInstance' + $resourceCurrentState.Permission | Should-BeCollection -Count 1 + $resourceCurrentState.Permission[0] | Should-HaveType 'CimInstance' $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'Grant' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -321,7 +321,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -340,13 +340,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -355,26 +355,26 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.SchemaName | Should -Be $ConfigurationData.AllNodes.SchemaName - $resourceCurrentState.ObjectName | Should -Be $ConfigurationData.AllNodes.TableName - $resourceCurrentState.ObjectType | Should -Be 'Table' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.SchemaName | Should-Be $ConfigurationData.AllNodes.SchemaName + $resourceCurrentState.ObjectName | Should-Be $ConfigurationData.AllNodes.TableName + $resourceCurrentState.ObjectType | Should-Be 'Table' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 1 - $resourceCurrentState.Permission[0] | Should -BeOfType 'CimInstance' + $resourceCurrentState.Permission | Should-BeCollection -Count 1 + $resourceCurrentState.Permission[0] | Should-HaveType 'CimInstance' $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'Grant' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -390,7 +390,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -409,13 +409,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -424,39 +424,39 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.SchemaName | Should -Be $ConfigurationData.AllNodes.SchemaName - $resourceCurrentState.ObjectName | Should -Be $ConfigurationData.AllNodes.TableName - $resourceCurrentState.ObjectType | Should -Be 'Table' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.SchemaName | Should-Be $ConfigurationData.AllNodes.SchemaName + $resourceCurrentState.ObjectName | Should-Be $ConfigurationData.AllNodes.TableName + $resourceCurrentState.ObjectType | Should-Be 'Table' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 4 - $resourceCurrentState.Permission[0] | Should -BeOfType 'CimInstance' - $resourceCurrentState.Permission[1] | Should -BeOfType 'CimInstance' - $resourceCurrentState.Permission[2] | Should -BeOfType 'CimInstance' - $resourceCurrentState.Permission[2] | Should -BeOfType 'CimInstance' + $resourceCurrentState.Permission | Should-BeCollection -Count 4 + $resourceCurrentState.Permission[0] | Should-HaveType 'CimInstance' + $resourceCurrentState.Permission[1] | Should-HaveType 'CimInstance' + $resourceCurrentState.Permission[2] | Should-HaveType 'CimInstance' + $resourceCurrentState.Permission[2] | Should-HaveType 'CimInstance' $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'Grant' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Insert') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Insert') $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'Deny' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Delete') - $grantPermission.Permission | Should -Contain @('Alter') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Delete') + $grantPermission.Permission | Should-ContainCollection @('Alter') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -472,7 +472,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -491,13 +491,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -506,36 +506,36 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.SchemaName | Should -Be $ConfigurationData.AllNodes.SchemaName - $resourceCurrentState.ObjectName | Should -Be $ConfigurationData.AllNodes.TableName - $resourceCurrentState.ObjectType | Should -Be 'Table' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.SchemaName | Should-Be $ConfigurationData.AllNodes.SchemaName + $resourceCurrentState.ObjectName | Should-Be $ConfigurationData.AllNodes.TableName + $resourceCurrentState.ObjectType | Should-Be 'Table' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.Permission[0] | Should -BeOfType 'CimInstance' - $resourceCurrentState.Permission[1] | Should -BeOfType 'CimInstance' - $resourceCurrentState.Permission[2] | Should -BeOfType 'CimInstance' + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.Permission[0] | Should-HaveType 'CimInstance' + $resourceCurrentState.Permission[1] | Should-HaveType 'CimInstance' + $resourceCurrentState.Permission[2] | Should-HaveType 'CimInstance' $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'Grant' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') $grantPermission = $resourceCurrentState.Permission.Where( { $_.State -eq 'Deny' }) - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Absent' - $grantPermission.Ensure[1] | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Delete') - $grantPermission.Permission | Should -Contain @('Alter') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Absent' + $grantPermission.Ensure[1] | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Delete') + $grantPermission.Permission | Should-ContainCollection @('Alter') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 index 3797c348b..b3af0f8a4 100644 --- a/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabasePermission.Integration.Tests.ps1 @@ -68,7 +68,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -87,13 +87,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -102,23 +102,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 3 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Select' - $grantState.Permission | Should -Contain 'CreateTable' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 3 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Select' + $grantState.Permission | Should-ContainCollection 'CreateTable' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -134,7 +134,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -153,13 +153,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -168,23 +168,23 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Not -Contain 'Select' - $grantState.Permission | Should -Not -Contain 'CreateTable' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-NotContainCollection 'Select' + $grantState.Permission | Should-NotContainCollection 'CreateTable' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -200,7 +200,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -219,13 +219,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -234,28 +234,28 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 2 - $denyState.Permission | Should -Contain 'Select' - $denyState.Permission | Should -Contain 'CreateTable' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 2 + $denyState.Permission | Should-ContainCollection 'Select' + $denyState.Permission | Should-ContainCollection 'CreateTable' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -271,7 +271,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -290,13 +290,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -305,32 +305,32 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' + $denyState.State | Should-Be 'Deny' <# Using '-HaveCount 0' does not work as it returns the error 'Expected an empty collection, but got collection with size 1 @($null).' even though the array is empty (does not contain oen item that is $null). Probably due to issue: https://github.com/pester/Pester/issues/1000 #> - $denyState.Permission | Should -BeNullOrEmpty + $denyState.Permission | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -346,7 +346,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -365,13 +365,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -380,22 +380,22 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be 'guest' - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be 'guest' + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Select' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Select' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -411,7 +411,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -430,13 +430,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -445,22 +445,22 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be 'guest' - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be 'guest' + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Not -Contain 'Select' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-NotContainCollection 'Select' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -476,7 +476,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -495,13 +495,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -510,22 +510,22 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be 'public' - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be 'public' + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Select' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Select' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -541,7 +541,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -560,13 +560,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -575,22 +575,22 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be 'public' - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be 'public' + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Not -Contain 'Select' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-NotContainCollection 'Select' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -692,116 +692,116 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["connect","update","alter"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["Connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["connect","update","alter"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["Connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 3 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' - $grantState.Permission | Should -Contain 'Alter' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 3 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' + $grantState.Permission | Should-ContainCollection 'Alter' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -818,16 +818,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -866,118 +866,118 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 3 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' - $grantState.Permission | Should -Contain 'Alter' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 3 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' + $grantState.Permission | Should-ContainCollection 'Alter' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":["delete","update"]}], but was [{"State":"Grant","Permission":["alter","connect","update"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":["delete","update"]}], but was [{"State":"Grant","Permission":["alter","connect","update"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 2 - $denyState.Permission | Should -Contain 'Delete' - $denyState.Permission | Should -Contain 'Update' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 2 + $denyState.Permission | Should-ContainCollection 'Delete' + $denyState.Permission | Should-ContainCollection 'Update' - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -994,16 +994,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -1040,117 +1040,117 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 2 - $denyState.Permission | Should -Contain 'Delete' - $denyState.Permission | Should -Contain 'Update' - - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["connect"]},{"State":"Deny","Permission":["delete","update"]},{"State":"GrantWithGrant","Permission":[]}]' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 2 + $denyState.Permission | Should-ContainCollection 'Delete' + $denyState.Permission | Should-ContainCollection 'Update' + + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["connect"]},{"State":"Deny","Permission":["delete","update"]},{"State":"GrantWithGrant","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'Select' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'Select' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1167,16 +1167,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -1209,115 +1209,115 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'Select' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'Select' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["connect"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1334,16 +1334,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -1391,148 +1391,148 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToExclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property PermissionToInclude $grantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property Reasons - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:PermissionToInclude' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property PermissionToInclude should be [{"State":"Grant","Permission":["update"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":["delete"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:PermissionToInclude' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property PermissionToInclude should be [{"State":"Grant","Permission":["update"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":["delete"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToExclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'Select' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'Select' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'Delete' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'Delete' # Property PermissionToInclude $grantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Update' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'Select' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'Select' $denyState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'Delete' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'Delete' # Property Reasons - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1549,16 +1549,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -1603,148 +1603,148 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'Select' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'Select' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'Delete' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'Delete' # Property PermissionToExclude $grantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property Reasons - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:PermissionToExclude' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property PermissionToExclude should be [{"State":"Grant","Permission":["update"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":["delete"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:PermissionToExclude' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property PermissionToExclude should be [{"State":"Grant","Permission":["update"]},{"State":"GrantWithGrant","Permission":["select"]},{"State":"Deny","Permission":["delete"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Connect' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Connect' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property PermissionToExclude $grantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'Update' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'Select' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'Select' $denyState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'Delete' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'Delete' # Property Reasons - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1761,16 +1761,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $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 1d75ad8a9..ed48512c8 100644 --- a/tests/Integration/Resources/DSC_SqlDatabaseUser.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlDatabaseUser.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,21 +101,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.UserType | Should -Be $ConfigurationData.AllNodes.User1_UserType - $resourceCurrentState.LoginName | Should -Be $ConfigurationData.AllNodes.User1_LoginName - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -Be 'Windows' - $resourceCurrentState.LoginType | Should -Be 'WindowsUser' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.UserType | Should-Be $ConfigurationData.AllNodes.User1_UserType + $resourceCurrentState.LoginName | Should-Be $ConfigurationData.AllNodes.User1_LoginName + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-Be 'Windows' + $resourceCurrentState.LoginType | Should-Be 'WindowsUser' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -131,7 +131,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -150,13 +150,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -165,21 +165,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User2_Name - $resourceCurrentState.UserType | Should -Be $ConfigurationData.AllNodes.User2_UserType - $resourceCurrentState.LoginName | Should -Be $ConfigurationData.AllNodes.User2_LoginName - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -Be 'Instance' - $resourceCurrentState.LoginType | Should -Be 'SqlLogin' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User2_Name + $resourceCurrentState.UserType | Should-Be $ConfigurationData.AllNodes.User2_UserType + $resourceCurrentState.LoginName | Should-Be $ConfigurationData.AllNodes.User2_LoginName + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-Be 'Instance' + $resourceCurrentState.LoginType | Should-Be 'SqlLogin' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -195,7 +195,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -214,13 +214,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -229,21 +229,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User3_Name - $resourceCurrentState.UserType | Should -Be $ConfigurationData.AllNodes.User3_UserType - $resourceCurrentState.LoginName | Should -BeNullOrEmpty - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -Be 'None' - $resourceCurrentState.LoginType | Should -Be 'SqlLogin' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User3_Name + $resourceCurrentState.UserType | Should-Be $ConfigurationData.AllNodes.User3_UserType + $resourceCurrentState.LoginName | Should-BeFalsy + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-Be 'None' + $resourceCurrentState.LoginType | Should-Be 'SqlLogin' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -259,7 +259,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -278,13 +278,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -293,21 +293,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User4_Name - $resourceCurrentState.UserType | Should -Be $ConfigurationData.AllNodes.User4_UserType - $resourceCurrentState.LoginName | Should -Be $ConfigurationData.AllNodes.User4_LoginName - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -Be 'Windows' - $resourceCurrentState.LoginType | Should -Be 'WindowsGroup' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User4_Name + $resourceCurrentState.UserType | Should-Be $ConfigurationData.AllNodes.User4_UserType + $resourceCurrentState.LoginName | Should-Be $ConfigurationData.AllNodes.User4_LoginName + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-Be 'Windows' + $resourceCurrentState.LoginType | Should-Be 'WindowsGroup' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -323,7 +323,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -342,13 +342,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -357,21 +357,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User4_Name - $resourceCurrentState.UserType | Should -Be 'NoLogin' - $resourceCurrentState.LoginName | Should -BeNullOrEmpty - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -Be 'None' - $resourceCurrentState.LoginType | Should -Be 'SqlLogin' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User4_Name + $resourceCurrentState.UserType | Should-Be 'NoLogin' + $resourceCurrentState.LoginName | Should-BeFalsy + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-Be 'None' + $resourceCurrentState.LoginType | Should-Be 'SqlLogin' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -387,7 +387,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -406,13 +406,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -421,21 +421,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User4_Name - $resourceCurrentState.UserType | Should -BeNullOrEmpty - $resourceCurrentState.LoginName | Should -BeNullOrEmpty - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -BeNullOrEmpty - $resourceCurrentState.UserType | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User4_Name + $resourceCurrentState.UserType | Should-BeFalsy + $resourceCurrentState.LoginName | Should-BeFalsy + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-BeFalsy + $resourceCurrentState.UserType | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -451,7 +451,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -470,13 +470,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -485,21 +485,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User5_Name - $resourceCurrentState.UserType | Should -Be $ConfigurationData.AllNodes.User5_UserType - $resourceCurrentState.LoginName | Should -BeNullOrEmpty - $resourceCurrentState.AsymmetricKeyName | Should -BeNullOrEmpty - $resourceCurrentState.CertificateName | Should -Be $ConfigurationData.AllNodes.CertificateName - $resourceCurrentState.AuthenticationType | Should -Be 'None' - $resourceCurrentState.LoginType | Should -Be 'Certificate' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User5_Name + $resourceCurrentState.UserType | Should-Be $ConfigurationData.AllNodes.User5_UserType + $resourceCurrentState.LoginName | Should-BeFalsy + $resourceCurrentState.AsymmetricKeyName | Should-BeFalsy + $resourceCurrentState.CertificateName | Should-Be $ConfigurationData.AllNodes.CertificateName + $resourceCurrentState.AuthenticationType | Should-Be 'None' + $resourceCurrentState.LoginType | Should-Be 'Certificate' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -515,7 +515,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -534,13 +534,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -549,21 +549,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseName | Should -Be $ConfigurationData.AllNodes.DatabaseName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User6_Name - $resourceCurrentState.UserType | Should -Be $ConfigurationData.AllNodes.User6_UserType - $resourceCurrentState.LoginName | Should -BeNullOrEmpty - $resourceCurrentState.AsymmetricKeyName | Should -Be $ConfigurationData.AllNodes.AsymmetricKeyName - $resourceCurrentState.CertificateName | Should -BeNullOrEmpty - $resourceCurrentState.AuthenticationType | Should -Be 'None' - $resourceCurrentState.LoginType | Should -Be 'AsymmetricKey' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseName | Should-Be $ConfigurationData.AllNodes.DatabaseName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User6_Name + $resourceCurrentState.UserType | Should-Be $ConfigurationData.AllNodes.User6_UserType + $resourceCurrentState.LoginName | Should-BeFalsy + $resourceCurrentState.AsymmetricKeyName | Should-Be $ConfigurationData.AllNodes.AsymmetricKeyName + $resourceCurrentState.CertificateName | Should-BeFalsy + $resourceCurrentState.AuthenticationType | Should-Be 'None' + $resourceCurrentState.LoginType | Should-Be 'AsymmetricKey' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 index 73db16529..67495c62c 100644 --- a/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlEndpoint.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive ConfigurationData = $ConfigurationData @@ -85,13 +85,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -100,17 +100,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.EndpointName | Should -Be $ConfigurationData.AllNodes.EndpointName - $resourceCurrentState.EndpointType | Should -Be 'DatabaseMirroring' - $resourceCurrentState.Port | Should -Be $ConfigurationData.AllNodes.Port - $resourceCurrentState.IpAddress | Should -Be $ConfigurationData.AllNodes.IpAddress - $resourceCurrentState.Owner | Should -Be $ConfigurationData.AllNodes.Owner - $resourceCurrentState.State | Should -Be 'Started' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.EndpointName | Should-Be $ConfigurationData.AllNodes.EndpointName + $resourceCurrentState.EndpointType | Should-Be 'DatabaseMirroring' + $resourceCurrentState.Port | Should-Be $ConfigurationData.AllNodes.Port + $resourceCurrentState.IpAddress | Should-Be $ConfigurationData.AllNodes.IpAddress + $resourceCurrentState.Owner | Should-Be $ConfigurationData.AllNodes.Owner + $resourceCurrentState.State | Should-Be 'Started' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -126,7 +126,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive ConfigurationData = $ConfigurationData @@ -144,13 +144,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -159,13 +159,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.EndpointName | Should -BeNullOrEmpty - $resourceCurrentState.EndpointType | Should -Be 'DatabaseMirroring' + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.EndpointName | Should-BeFalsy + $resourceCurrentState.EndpointType | Should-Be 'DatabaseMirroring' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -181,7 +181,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive ConfigurationData = $ConfigurationData @@ -199,13 +199,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -214,20 +214,20 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.EndpointName | Should -Be $ConfigurationData.AllNodes.SsbrEndpointName - $resourceCurrentState.EndpointType | Should -Be 'ServiceBroker' - $resourceCurrentState.Port | Should -Be $ConfigurationData.AllNodes.SsbrPort - $resourceCurrentState.IpAddress | Should -Be $ConfigurationData.AllNodes.IpAddress - $resourceCurrentState.Owner | Should -Be $ConfigurationData.AllNodes.Owner - $resourceCurrentState.State | Should -Be 'Started' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.EndpointName | Should-Be $ConfigurationData.AllNodes.SsbrEndpointName + $resourceCurrentState.EndpointType | Should-Be 'ServiceBroker' + $resourceCurrentState.Port | Should-Be $ConfigurationData.AllNodes.SsbrPort + $resourceCurrentState.IpAddress | Should-Be $ConfigurationData.AllNodes.IpAddress + $resourceCurrentState.Owner | Should-Be $ConfigurationData.AllNodes.Owner + $resourceCurrentState.State | Should-Be 'Started' - $resourceCurrentState.IsMessageForwardingEnabled | Should -Be $ConfigurationData.AllNodes.IsMessageForwardingEnabled - $resourceCurrentState.MessageForwardingSize | Should -Be $ConfigurationData.AllNodes.MessageForwardingSize + $resourceCurrentState.IsMessageForwardingEnabled | Should-Be $ConfigurationData.AllNodes.IsMessageForwardingEnabled + $resourceCurrentState.MessageForwardingSize | Should-Be $ConfigurationData.AllNodes.MessageForwardingSize } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -243,7 +243,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive ConfigurationData = $ConfigurationData @@ -261,13 +261,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -276,13 +276,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.EndpointName | Should -BeNullOrEmpty - $resourceCurrentState.EndpointType | Should -Be 'ServiceBroker' + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.EndpointName | Should-BeFalsy + $resourceCurrentState.EndpointType | Should-Be 'ServiceBroker' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 index 99bb2588c..aa87f7dd9 100644 --- a/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlLogin.Integration.Tests.ps1 @@ -72,7 +72,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -91,7 +91,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -107,7 +107,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -126,13 +126,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -141,14 +141,14 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser1Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser1Type - $resourceCurrentState.Disabled | Should -Be $false + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser1Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser1Type + $resourceCurrentState.Disabled | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -164,7 +164,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -183,13 +183,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -198,15 +198,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser2Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser2Type - $resourceCurrentState.DefaultDatabase | Should -Be $ConfigurationData.AllNodes.DefaultDbName - $resourceCurrentState.Disabled | Should -Be $false + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser2Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser2Type + $resourceCurrentState.DefaultDatabase | Should-Be $ConfigurationData.AllNodes.DefaultDbName + $resourceCurrentState.Disabled | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -222,7 +222,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -241,13 +241,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -256,14 +256,14 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser3Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser3Type - $resourceCurrentState.Disabled | Should -Be $true + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser3Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser3Type + $resourceCurrentState.Disabled | Should-BeTrue } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -279,7 +279,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -298,13 +298,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -313,17 +313,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser4Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser4Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -Be $false - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -Be $true - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -Be $true + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser4Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser4Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeTrue + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeTrue } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } It 'Should allow SQL Server, login username and password to connect to SQL Instance (using SqlConnection.Open())' { @@ -335,11 +335,11 @@ 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 - { + $null = & ({ $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString $sqlConnection.Open() $sqlConnection.Close() - } | Should -Not -Throw + }) } It 'Should allow SQL Server, login username and password to connect to correct, SQL instance, default database' { @@ -352,7 +352,7 @@ 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 - { + $null = & ({ $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString $sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection) @@ -362,12 +362,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlDataAdapter.Fill($sqlDataSet) | Out-Null $sqlConnection.Close() - $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName + $sqlDataSet.Tables[0].Rows[0].CurrentDataShould-Be $ConfigurationData.AllNodes.DefaultDbNamefaultDbName $script:CurrentDatabaseName = $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName - } | Should -Not -Throw + }) - $script:CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName + $script:CurrentDatabaseName | Should-Be $ConfigurationData.AllNodes.DefaultDbName $script:CurrentDatabaseName = $null } @@ -385,7 +385,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -404,13 +404,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -419,17 +419,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser4Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser4Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -Be $false # Left the same as this cannot be updated - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -Be $false - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -Be $false + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser4Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser4Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse # Left the same as this cannot be updated + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeFalse + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } It 'Should allow SQL Server, login username and (changed) password to connect to SQL Instance (using SqlConnection.Open())' { @@ -441,11 +441,11 @@ 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 - { + $null = & ({ $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString $sqlConnection.Open() $sqlConnection.Close() - } | Should -Not -Throw + }) } It 'Should allow SQL Server, login username and (changed) password to connect to correct, SQL instance, default database' { @@ -458,22 +458,24 @@ 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 - { + $script:sqlDataSet = $null + + $null = & ({ $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 + $script:sqlDataSet = New-Object System.Data.DataSet $sqlDataAdapter.Fill($sqlDataSet) | Out-Null $sqlConnection.Close() - $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName - $script:CurrentDatabaseName = $sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName - } | Should -Not -Throw + }) + + $script:sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should-Be $ConfigurationData.AllNodes.DefaultDbName - $script:CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName + $script:CurrentDatabaseName | Should-Be $ConfigurationData.AllNodes.DefaultDbName $script:CurrentDatabaseName = $null } @@ -495,7 +497,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should re-compile and re-apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -514,17 +516,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } It 'Should allow SQL Server, login username and password to connect to SQL Instance (using SqlConnection.Open())' { @@ -536,11 +538,11 @@ 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 - { + $null = & ({ $sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString $sqlConnection.Open() $sqlConnection.Close() - } | Should -Not -Throw + }) } } @@ -556,7 +558,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -575,13 +577,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -590,17 +592,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser5Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser5Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -BeFalse - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeFalse - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeFalse + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser5Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser5Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeFalse + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -621,7 +623,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -640,11 +642,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -660,7 +662,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -679,13 +681,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -694,17 +696,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser5Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser5Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -BeFalse - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeFalse - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeTrue + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser5Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser5Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeFalse + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeTrue } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -725,7 +727,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -744,11 +746,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -783,7 +785,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Throw -ExpectedMessage '*The CHECK_EXPIRATION option cannot be used when CHECK_POLICY is OFF*' + } | Should-Throw -ExceptionMessage '*The CHECK_EXPIRATION option cannot be used when CHECK_POLICY is OFF*' } } @@ -804,7 +806,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -823,13 +825,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -838,17 +840,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser5Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser5Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -BeFalse - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeTrue - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeTrue + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser5Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser5Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeTrue + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeTrue } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -864,7 +866,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -883,13 +885,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -898,18 +900,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser5Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser5Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -BeFalse - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeFalse + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser5Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser5Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeFalse # This was set to true by the previous test. - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeTrue + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeTrue } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -925,7 +927,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -944,13 +946,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -959,17 +961,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser5Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser5Type - $resourceCurrentState.Disabled | Should -Be $false - $resourceCurrentState.LoginMustChangePassword | Should -BeFalse - $resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeFalse - $resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeFalse + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser5Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscUser5Type + $resourceCurrentState.Disabled | Should-BeFalse + $resourceCurrentState.LoginMustChangePassword | Should-BeFalse + $resourceCurrentState.LoginPasswordExpirationEnabled | Should-BeFalse + $resourceCurrentState.LoginPasswordPolicyEnforced | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -985,7 +987,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -1004,13 +1006,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -1019,14 +1021,14 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscSqlUsers1Name - $resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscSqlUsers1Type - $resourceCurrentState.Disabled | Should -Be $false + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscSqlUsers1Name + $resourceCurrentState.LoginType | Should-Be $ConfigurationData.AllNodes.DscSqlUsers1Type + $resourceCurrentState.Disabled | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -1042,7 +1044,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -1061,13 +1063,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -1076,13 +1078,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser3Name - $resourceCurrentState.LoginType | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser3Name + $resourceCurrentState.LoginType | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -1098,7 +1100,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -1117,13 +1119,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -1132,13 +1134,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser5Name - $resourceCurrentState.LoginType | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.DscUser5Name + $resourceCurrentState.LoginType | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -1154,7 +1156,7 @@ 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') { - { + $null = & ({ # 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 @@ -1163,7 +1165,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $sqlConnection.Open() $sqlCommand.ExecuteNonQuery() $sqlConnection.Close() - } | Should -Not -Throw + }) } } @@ -1179,7 +1181,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -1198,7 +1200,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 index cd7fc08bf..8b5808220 100644 --- a/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlPermission.Integration.Tests.ps1 @@ -68,7 +68,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -87,13 +87,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -102,22 +102,22 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 3 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $grantState.Permission | Should -Contain 'CreateEndpoint' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 3 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $grantState.Permission | Should-ContainCollection 'CreateEndpoint' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -133,7 +133,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -152,13 +152,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -167,22 +167,22 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Not -Contain 'AlterAnyAvailabilityGroup' - $grantState.Permission | Should -Not -Contain 'CreateEndpoint' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-NotContainCollection 'AlterAnyAvailabilityGroup' + $grantState.Permission | Should-NotContainCollection 'CreateEndpoint' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -198,7 +198,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -217,13 +217,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -232,27 +232,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 2 - $denyState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $denyState.Permission | Should -Contain 'CreateEndpoint' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 2 + $denyState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $denyState.Permission | Should-ContainCollection 'CreateEndpoint' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -268,7 +268,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -287,13 +287,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -302,31 +302,32 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' + $denyState.State | Should-Be 'Deny' + <# Using '-HaveCount 0' does not work as it returns the error 'Expected an empty collection, but got collection with size 1 @($null).' even though the array is empty (does not contain oen item that is $null). Probably due to issue: https://github.com/pester/Pester/issues/1000 #> - $denyState.Permission | Should -BeNullOrEmpty + $denyState.Permission | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -429,114 +430,114 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql","ViewServerState","AlterAnyEndpoint"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql","ViewServerState","AlterAnyEndpoint"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 3 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'ViewServerState' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 3 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'ViewServerState' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -553,16 +554,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -601,116 +602,116 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 3 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'ViewServerState' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 3 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'ViewServerState' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":["ControlServer","ViewServerState"]}], but was [{"State":"Grant","Permission":["AlterAnyEndpoint","ConnectSql","ViewServerState"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":["ControlServer","ViewServerState"]}], but was [{"State":"Grant","Permission":["AlterAnyEndpoint","ConnectSql","ViewServerState"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 2 - $denyState.Permission | Should -Contain 'ControlServer' - $denyState.Permission | Should -Contain 'ViewServerState' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 2 + $denyState.Permission | Should-ContainCollection 'ControlServer' + $denyState.Permission | Should-ContainCollection 'ViewServerState' - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -727,16 +728,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -774,115 +775,115 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 2 - $denyState.Permission | Should -Contain 'ControlServer' - $denyState.Permission | Should -Contain 'ViewServerState' - - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Deny","Permission":[]}], but was [{"State":"Deny","Permission":["ControlServer","ViewServerState"]},{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]}]' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 2 + $denyState.Permission | Should-ContainCollection 'ControlServer' + $denyState.Permission | Should-ContainCollection 'ViewServerState' + + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Deny","Permission":[]}], but was [{"State":"Deny","Permission":["ControlServer","ViewServerState"]},{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -899,16 +900,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -942,113 +943,113 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:Permission' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Grant","Permission":["ConnectSql"]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:Permission' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Grant","Permission":["ConnectSql"]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy + $resourceCurrentState.PermissionToExclude | Should-BeFalsy $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1065,16 +1066,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -1122,146 +1123,146 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToExclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property PermissionToInclude $grantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property Reasons - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:PermissionToInclude' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property PermissionToInclude should be [{"State":"Grant","Permission":["ViewServerState"]},{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Deny","Permission":["ControlServer"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:PermissionToInclude' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property PermissionToInclude should be [{"State":"Grant","Permission":["ViewServerState"]},{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Deny","Permission":["ControlServer"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToExclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToExclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'ViewServerState' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'ViewServerState' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'ControlServer' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'ControlServer' # Property PermissionToInclude $grantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ViewServerState' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ViewServerState' $grantWithGrantState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' $denyState = $resourceCurrentState.PermissionToInclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'ControlServer' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'ControlServer' # Property Reasons - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1278,16 +1279,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } } @@ -1332,146 +1333,146 @@ 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' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'ViewServerState' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'ViewServerState' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'ControlServer' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'ControlServer' # Property PermissionToExclude $grantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property Reasons - $resourceCurrentState.Reasons | Should -HaveCount 1 - $resourceCurrentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:PermissionToExclude' - $resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property PermissionToExclude should be [{"State":"Grant","Permission":["ViewServerState"]},{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Deny","Permission":["ControlServer"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $resourceCurrentState.Reasons | Should-BeCollection -Count 1 + $resourceCurrentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:PermissionToExclude' + $resourceCurrentState.Reasons[0].Phrase | Should-Be 'The property PermissionToExclude should be [{"State":"Grant","Permission":["ViewServerState"]},{"State":"GrantWithGrant","Permission":["AlterAnyAvailabilityGroup"]},{"State":"Deny","Permission":["ControlServer"]}], but was [{"State":"Grant","Permission":[]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } It 'Should run method Test() and return the state as $false' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeFalse + $resourceCurrentState.InDesiredState | Should-BeFalse } It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $resourceCurrentState.RebootRequired | Should-BeFalse } } Context 'When the system is in the desired state' { It 'Should run method Get() and return the correct values' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Get' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.User1_Name - $resourceCurrentState.Permission | Should -HaveCount 3 - $resourceCurrentState.PermissionToInclude | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.Name | Should-Be $ConfigurationData.AllNodes.User1_Name + $resourceCurrentState.Permission | Should-BeCollection -Count 3 + $resourceCurrentState.PermissionToInclude | Should-BeFalsy # Property Permission $grantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ConnectSql' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ConnectSql' $grantWithGrantState = $resourceCurrentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $resourceCurrentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy # Property PermissionToExclude $grantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Grant' }) - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 1 - $grantState.Permission | Should -Contain 'ViewServerState' + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 1 + $grantState.Permission | Should-ContainCollection 'ViewServerState' $grantWithGrantState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -HaveCount 1 - $grantWithGrantState.Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeCollection -Count 1 + $grantWithGrantState.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' $denyState = $resourceCurrentState.PermissionToExclude.Where({ $_.State -eq 'Deny' }) - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -HaveCount 1 - $denyState.Permission | Should -Contain 'ControlServer' + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeCollection -Count 1 + $denyState.Permission | Should-ContainCollection 'ControlServer' # Property Reasons - $resourceCurrentState.Reasons | Should -BeNullOrEmpty + $resourceCurrentState.Reasons | Should-BeFalsy } It 'Should run method Test() and return the state as $true' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Test' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.InDesiredState | Should -BeTrue + $resourceCurrentState.InDesiredState | Should-BeTrue } <# @@ -1488,16 +1489,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', all properties are in desired state. #> It 'Should run method Set() without throwing and not require reboot' { - { + $null = & ({ $mockInvokeDscResourceParameters = $mockDefaultInvokeDscResourceParameters.Clone() $mockInvokeDscResourceParameters.Method = 'Set' $mockInvokeDscResourceParameters.Property = $mockInvokeDscResourceProperty $script:resourceCurrentState = Invoke-DscResource @mockInvokeDscResourceParameters - } | Should -Not -Throw + }) - $resourceCurrentState.RebootRequired | Should -BeFalse + $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 090bceb52..57019ed3e 100644 --- a/tests/Integration/Resources/DSC_SqlProtocol.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlProtocol.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,13 +101,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ProtocolName | Should -Be 'NamedPipes' - $resourceCurrentState.Enabled | Should -BeFalse - $resourceCurrentState.PipeName | Should -Be '\\.\pipe\MSSQL$DSCSQLTEST\sql\query' + $resourceCurrentState.ProtocolName | Should-Be 'NamedPipes' + $resourceCurrentState.Enabled | Should-BeFalse + $resourceCurrentState.PipeName | Should-Be '\\.\pipe\MSSQL$DSCSQLTEST\sql\query' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -123,7 +123,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -142,13 +142,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -157,13 +157,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ProtocolName | Should -Be 'NamedPipes' - $resourceCurrentState.Enabled | Should -BeTrue - $resourceCurrentState.PipeName | Should -Be '\\.\pipe\MSSQL$DSCSQLTEST\sql\query' + $resourceCurrentState.ProtocolName | Should-Be 'NamedPipes' + $resourceCurrentState.Enabled | Should-BeTrue + $resourceCurrentState.PipeName | Should-Be '\\.\pipe\MSSQL$DSCSQLTEST\sql\query' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 index 9acf9a628..873e5eed6 100644 --- a/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlProtocolTcpIp.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,13 +101,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.IpAddressGroup | Should -Be 'IP1' - $resourceCurrentState.Enabled | Should -BeTrue - $resourceCurrentState.IpAddress | Should -Be $ConfigurationData.AllNodes.IpAddress + $resourceCurrentState.IpAddressGroup | Should-Be 'IP1' + $resourceCurrentState.Enabled | Should-BeTrue + $resourceCurrentState.IpAddress | Should-Be $ConfigurationData.AllNodes.IpAddress } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 index ccdac7dea..1d12321f9 100644 --- a/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRS.Integration.Tests.ps1 @@ -96,7 +96,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -115,7 +115,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -131,7 +131,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -150,13 +150,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -165,16 +165,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseServerName | Should -Be $ConfigurationData.AllNodes.DatabaseServerName - $resourceCurrentState.DatabaseInstanceName | Should -Be $ConfigurationData.AllNodes.DatabaseInstanceName - $resourceCurrentState.IsInitialized | Should -Be $true - $resourceCurrentState.UseSsl | Should -Be $false - $resourceCurrentState.ReportServerReservedUrl | Should -Contain 'http://+:80' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseServerName | Should-Be $ConfigurationData.AllNodes.DatabaseServerName + $resourceCurrentState.DatabaseInstanceName | Should-Be $ConfigurationData.AllNodes.DatabaseInstanceName + $resourceCurrentState.IsInitialized | Should-BeTrue + $resourceCurrentState.UseSsl | Should-BeFalse + $resourceCurrentState.ReportServerReservedUrl | Should-ContainCollection 'http://+:80' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } It 'Should be able to access the ReportServer site without any error' { @@ -207,7 +207,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $webRequestStatusCode = $webRequestResponse.StatusCode -as [int] } - $webRequestStatusCode | Should -BeExactly 200 + $webRequestStatusCode | Should-BeString -CaseSensitive 200 } It 'Should be able to access the Reports site without any error' { @@ -237,7 +237,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $webRequestStatusCode = $webRequestResponse.StatusCode -as [int] } - $webRequestStatusCode | Should -BeExactly 200 + $webRequestStatusCode | Should-BeString -CaseSensitive 200 } } @@ -253,7 +253,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -272,7 +272,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 index 9f4848047..a4a7931bf 100644 --- a/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRSSetup.Integration.Tests.ps1 @@ -133,7 +133,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -152,13 +152,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -167,29 +167,29 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.InstallFolder | Should -Be 'C:\Program Files\Microsoft SQL Server Reporting Services' - $resourceCurrentState.ServiceName | Should -Be 'SQLServerReportingServices' - $resourceCurrentState.ErrorDumpDirectory | Should -Be 'C:\Program Files\Microsoft SQL Server Reporting Services\SSRS\LogFiles' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.InstallFolder | Should-Be 'C:\Program Files\Microsoft SQL Server Reporting Services' + $resourceCurrentState.ServiceName | Should-Be 'SQLServerReportingServices' + $resourceCurrentState.ErrorDumpDirectory | Should-Be 'C:\Program Files\Microsoft SQL Server Reporting Services\SSRS\LogFiles' if (Test-ContinuousIntegrationTaskCategory -Category 'Integration_SQL2017') { - $resourceCurrentState.CurrentVersion | Should -BeGreaterThan ([System.Version] '14.0.0.0') + $resourceCurrentState.CurrentVersion | Should-BeGreaterThan ([System.Version] '14.0.0.0') } if (Test-ContinuousIntegrationTaskCategory -Category 'Integration_SQL2019') { - $resourceCurrentState.CurrentVersion | Should -BeGreaterThan ([System.Version] '15.0.0.0') + $resourceCurrentState.CurrentVersion | Should-BeGreaterThan ([System.Version] '15.0.0.0') } if (Test-ContinuousIntegrationTaskCategory -Category 'Integration_SQL2022') { - $resourceCurrentState.CurrentVersion | Should -BeGreaterThan ([System.Version] '16.0.0.0') + $resourceCurrentState.CurrentVersion | Should-BeGreaterThan ([System.Version] '16.0.0.0') } } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -205,7 +205,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -224,7 +224,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2017', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 index 62d275190..1a7206fb5 100644 --- a/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRS_Default.Integration.Tests.ps1 @@ -96,7 +96,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -115,7 +115,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -131,7 +131,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -150,13 +150,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -165,15 +165,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DatabaseServerName | Should -Be $ConfigurationData.AllNodes.DatabaseServerName - $resourceCurrentState.DatabaseInstanceName | Should -Be $ConfigurationData.AllNodes.DatabaseInstanceName - $resourceCurrentState.IsInitialized | Should -Be $true - $resourceCurrentState.UseSsl | Should -Be $false + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DatabaseServerName | Should-Be $ConfigurationData.AllNodes.DatabaseServerName + $resourceCurrentState.DatabaseInstanceName | Should-Be $ConfigurationData.AllNodes.DatabaseInstanceName + $resourceCurrentState.IsInitialized | Should-BeTrue + $resourceCurrentState.UseSsl | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } It 'Should be able to access the ReportServer site without any error' { @@ -206,7 +206,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $webRequestStatusCode = $webRequestResponse.StatusCode -as [int] } - $webRequestStatusCode | Should -BeExactly 200 + $webRequestStatusCode | Should-BeString -CaseSensitive 200 } It 'Should be able to access the Reports site without any error' { @@ -236,7 +236,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $webRequestStatusCode = $webRequestResponse.StatusCode -as [int] } - $webRequestStatusCode | Should -BeExactly 200 + $webRequestStatusCode | Should-BeString -CaseSensitive 200 } } @@ -252,7 +252,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -271,13 +271,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -286,11 +286,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.UseSsl | Should -Be $true + $resourceCurrentState.UseSsl | Should-BeTrue } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } <# @@ -310,7 +310,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $reportServerUri = 'http://{0}/ReportServer_{1}' -f $env:COMPUTERNAME, $ConfigurationData.AllNodes.InstanceName } - { Invoke-WebRequest -Uri $reportServerUri -UseDefaultCredentials } | Should -Throw + { Invoke-WebRequest -Uri $reportServerUri -UseDefaultCredentials } | Should-Throw } } @@ -326,7 +326,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -345,13 +345,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -360,11 +360,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.UseSsl | Should -Be $false + $resourceCurrentState.UseSsl | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } It 'Should be able to access the ReportServer site without any error' { @@ -394,7 +394,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $webRequestStatusCode = $webRequestResponse.StatusCode -as [int] } - $webRequestStatusCode | Should -BeExactly 200 + $webRequestStatusCode | Should-BeString -CaseSensitive 200 } It 'Should be able to access the Reports site without any error' { @@ -424,7 +424,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $webRequestStatusCode = $webRequestResponse.StatusCode -as [int] } - $webRequestStatusCode | Should -BeExactly 200 + $webRequestStatusCode | Should-BeString -CaseSensitive 200 } } @@ -440,7 +440,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -459,7 +459,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 index 07172878d..979fc6824 100644 --- a/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlReplication.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,7 +86,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -102,7 +102,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -121,13 +121,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -136,16 +136,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DistributorMode | Should -Be 'Local' - $resourceCurrentState.DistributionDBName | Should -Be 'MyDistribution' - $resourceCurrentState.RemoteDistributor | Should -Be ('{0}\DSCSQLTEST' -f $env:COMPUTERNAME) - $resourceCurrentState.WorkingDirectory | Should -Be 'C:\Temp' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DistributorMode | Should-Be 'Local' + $resourceCurrentState.DistributionDBName | Should-Be 'MyDistribution' + $resourceCurrentState.RemoteDistributor | Should-Be ('{0}\DSCSQLTEST' -f $env:COMPUTERNAME) + $resourceCurrentState.WorkingDirectory | Should-Be 'C:\Temp' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -161,7 +161,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -180,13 +180,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -195,16 +195,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.DefaultInstanceName - $resourceCurrentState.DistributorMode | Should -Be 'Remote' - $resourceCurrentState.DistributionDBName | Should -Be 'MyDistribution' - $resourceCurrentState.RemoteDistributor | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, $ConfigurationData.AllNodes.InstanceName) - $resourceCurrentState.WorkingDirectory | Should -Be 'C:\Temp' + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.DefaultInstanceName + $resourceCurrentState.DistributorMode | Should-Be 'Remote' + $resourceCurrentState.DistributionDBName | Should-Be 'MyDistribution' + $resourceCurrentState.RemoteDistributor | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, $ConfigurationData.AllNodes.InstanceName) + $resourceCurrentState.WorkingDirectory | Should-Be 'C:\Temp' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -220,7 +220,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -239,13 +239,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -254,16 +254,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DistributorMode | Should -BeNullOrEmpty - $resourceCurrentState.DistributionDBName | Should -BeNullOrEmpty - $resourceCurrentState.RemoteDistributor | Should -BeNullOrEmpty - $resourceCurrentState.WorkingDirectory | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DistributorMode | Should-BeFalsy + $resourceCurrentState.DistributionDBName | Should-BeFalsy + $resourceCurrentState.RemoteDistributor | Should-BeFalsy + $resourceCurrentState.WorkingDirectory | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -279,7 +279,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -298,13 +298,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -313,16 +313,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.DistributorMode | Should -BeNullOrEmpty - $resourceCurrentState.DistributionDBName | Should -BeNullOrEmpty - $resourceCurrentState.RemoteDistributor | Should -BeNullOrEmpty - $resourceCurrentState.WorkingDirectory | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.DistributorMode | Should-BeFalsy + $resourceCurrentState.DistributionDBName | Should-BeFalsy + $resourceCurrentState.RemoteDistributor | Should-BeFalsy + $resourceCurrentState.WorkingDirectory | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -338,7 +338,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -357,7 +357,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 index 02abe0ddb..a8a438a03 100644 --- a/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlRole.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -75,9 +75,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -88,13 +88,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -103,15 +103,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role1Name - $resourceCurrentState.Members | Should -Be $ConfigurationData.AllNodes.User4Name - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role1Name + $resourceCurrentState.Members | Should-Be $ConfigurationData.AllNodes.User4Name + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -127,7 +127,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -135,9 +135,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -148,13 +148,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -163,15 +163,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role2Name - $resourceCurrentState.Members | Should -BeNullOrEmpty - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role2Name + $resourceCurrentState.Members | Should-BeFalsy + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -187,7 +187,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -195,9 +195,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -208,13 +208,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -223,18 +223,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role3Name - $resourceCurrentState.Members | Should -Be @( + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role3Name + $resourceCurrentState.Members | Should-Be @( $ConfigurationData.AllNodes.User1Name $ConfigurationData.AllNodes.User2Name ) - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -250,7 +250,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -258,9 +258,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -271,13 +271,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -286,20 +286,20 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role1Name + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role1Name - $resourceCurrentState.Members | Should -Be @( + $resourceCurrentState.Members | Should-Be @( $ConfigurationData.AllNodes.User1Name $ConfigurationData.AllNodes.User2Name ) - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -315,7 +315,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -323,9 +323,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -336,13 +336,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -351,21 +351,21 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role2Name + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role2Name - $resourceCurrentState.Members | Should -Be @( + $resourceCurrentState.Members | Should-Be @( $ConfigurationData.AllNodes.User1Name $ConfigurationData.AllNodes.User2Name $ConfigurationData.AllNodes.User4Name ) - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -381,7 +381,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -389,9 +389,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -402,13 +402,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -417,15 +417,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Present' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role2Name - $resourceCurrentState.Members | Should -Be $ConfigurationData.AllNodes.User4Name - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Present' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role2Name + $resourceCurrentState.Members | Should-Be $ConfigurationData.AllNodes.User4Name + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -441,7 +441,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -449,9 +449,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -462,13 +462,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -477,15 +477,15 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Ensure | Should -Be 'Absent' - $resourceCurrentState.ServerRoleName | Should -Be $ConfigurationData.AllNodes.Role3Name - $resourceCurrentState.Members | Should -BeNullOrEmpty - $resourceCurrentState.MembersToInclude | Should -BeNullOrEmpty - $resourceCurrentState.MembersToExclude | Should -BeNullOrEmpty + $resourceCurrentState.Ensure | Should-Be 'Absent' + $resourceCurrentState.ServerRoleName | Should-Be $ConfigurationData.AllNodes.Role3Name + $resourceCurrentState.Members | Should-BeFalsy + $resourceCurrentState.MembersToInclude | Should-BeFalsy + $resourceCurrentState.MembersToExclude | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -BeTrue + Test-DscConfiguration -Verbose | Should-BeTrue } } @@ -501,7 +501,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -509,9 +509,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -522,12 +522,11 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing an exception' { - { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | - Should -Not -Throw + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop }) } It "Should have set the resource and all values should match for $($ConfigurationData.AllNodes.Role4Name)." { @@ -539,10 +538,10 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $_.ServerRoleName -eq $testRoleName } - $currentState.Ensure | Should -Be 'Present' - $currentState.Members | Should -BeNullOrEmpty - $currentState.MembersToInclude | Should -BeNullOrEmpty - $currentState.MembersToExclude | Should -BeNullOrEmpty + $currentState.Ensure | Should-Be 'Present' + $currentState.Members | Should-BeFalsy + $currentState.MembersToInclude | Should-BeFalsy + $currentState.MembersToExclude | Should-BeFalsy } It "Should have set the resource and all values should match for $($ConfigurationData.AllNodes.Role5Name)." { @@ -555,10 +554,10 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $_.ServerRoleName -eq $testRoleName } - $currentState.Ensure | Should -Be 'Present' - $currentState.Members | Should -Be @($testMemberName) - $currentState.MembersToInclude | Should -BeNullOrEmpty - $currentState.MembersToExclude | Should -BeNullOrEmpty + $currentState.Ensure | Should-Be 'Present' + $currentState.Members | Should-Be @($testMemberName) + $currentState.MembersToInclude | Should-BeFalsy + $currentState.MembersToExclude | Should-BeFalsy } } @@ -574,7 +573,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -582,9 +581,9 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } & $configurationName @configurationParameters - } | Should -Not -Throw + }) - { + $null = & ({ $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' @@ -595,13 +594,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing an exception' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It "Should have set the resource and all values should match for $($ConfigurationData.AllNodes.Role5Name)." { @@ -613,10 +612,10 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', $_.ServerRoleName -eq $testRoleName } - $currentState.Ensure | Should -Be 'Present' - $currentState.Members | Should -BeNullOrEmpty - $currentState.MembersToInclude | Should -BeNullOrEmpty - $currentState.MembersToExclude | Should -BeNullOrEmpty + $currentState.Ensure | Should-Be 'Present' + $currentState.Members | Should-BeFalsy + $currentState.MembersToInclude | Should-BeFalsy + $currentState.MembersToExclude | Should-BeFalsy } } } diff --git a/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 index 942bdd8a6..e65c75304 100644 --- a/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlScript.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -91,7 +91,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -107,7 +107,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -126,13 +126,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -178,17 +178,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', throw $_ } - $resultObject.Name | Should -Be $ConfigurationData.AllNodes.Database1Name + $resultObject.Name | Should-Be $ConfigurationData.AllNodes.Database1Name - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.GetFilePath | Should -Be $ConfigurationData.AllNodes.GetSqlScriptPath - $resourceCurrentState.TestFilePath | Should -Be $ConfigurationData.AllNodes.TestSqlScriptPath - $resourceCurrentState.SetFilePath | Should -Be $ConfigurationData.AllNodes.SetSqlScriptPath + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.GetFilePath | Should-Be $ConfigurationData.AllNodes.GetSqlScriptPath + $resourceCurrentState.TestFilePath | Should-Be $ConfigurationData.AllNodes.TestSqlScriptPath + $resourceCurrentState.SetFilePath | Should-Be $ConfigurationData.AllNodes.SetSqlScriptPath } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -204,7 +204,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -223,13 +223,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -238,16 +238,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.GetResult | Should -Match $ConfigurationData.AllNodes.Database2Name - $resourceCurrentState.GetFilePath | Should -Be $ConfigurationData.AllNodes.GetSqlScriptPath - $resourceCurrentState.TestFilePath | Should -Be $ConfigurationData.AllNodes.TestSqlScriptPath - $resourceCurrentState.SetFilePath | Should -Be $ConfigurationData.AllNodes.SetSqlScriptPath + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.GetResult | Should-MatchString $ConfigurationData.AllNodes.Database2Name + $resourceCurrentState.GetFilePath | Should-Be $ConfigurationData.AllNodes.GetSqlScriptPath + $resourceCurrentState.TestFilePath | Should-Be $ConfigurationData.AllNodes.TestSqlScriptPath + $resourceCurrentState.SetFilePath | Should-Be $ConfigurationData.AllNodes.SetSqlScriptPath } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -263,7 +263,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -282,13 +282,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -334,17 +334,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', throw $_ } - $resultObject.Name | Should -Be $ConfigurationData.AllNodes.Database3Name + $resultObject.Name | Should-Be $ConfigurationData.AllNodes.Database3Name - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.GetFilePath | Should -Be $ConfigurationData.AllNodes.GetSqlScriptPath - $resourceCurrentState.TestFilePath | Should -Be $ConfigurationData.AllNodes.TestSqlScriptPath - $resourceCurrentState.SetFilePath | Should -Be $ConfigurationData.AllNodes.SetSqlScriptPath + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.GetFilePath | Should-Be $ConfigurationData.AllNodes.GetSqlScriptPath + $resourceCurrentState.TestFilePath | Should-Be $ConfigurationData.AllNodes.TestSqlScriptPath + $resourceCurrentState.SetFilePath | Should-Be $ConfigurationData.AllNodes.SetSqlScriptPath } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -360,7 +360,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -379,7 +379,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 index a46b2f1ed..285ba99d4 100644 --- a/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlScriptQuery.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -138,17 +138,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', throw $_ } - $resultObject.Name | Should -Be $ConfigurationData.AllNodes.Database1Name + $resultObject.Name | Should-Be $ConfigurationData.AllNodes.Database1Name - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.GetQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.GetQuery -replace '\r\n', "`n") - $resourceCurrentState.TestQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.TestQuery -replace '\r\n', "`n") - $resourceCurrentState.SetQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.SetQuery -replace '\r\n', "`n") + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.GetQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.GetQuery -replace '\r\n', "`n") + $resourceCurrentState.TestQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.TestQuery -replace '\r\n', "`n") + $resourceCurrentState.SetQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.SetQuery -replace '\r\n', "`n") } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -164,7 +164,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -183,13 +183,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -198,16 +198,16 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.GetResult | Should -Match $ConfigurationData.AllNodes.Database2Name - $resourceCurrentState.GetQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.GetQuery -replace '\r\n', "`n") - $resourceCurrentState.TestQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.TestQuery -replace '\r\n', "`n") - $resourceCurrentState.SetQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.SetQuery -replace '\r\n', "`n") + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.GetResult | Should-MatchString $ConfigurationData.AllNodes.Database2Name + $resourceCurrentState.GetQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.GetQuery -replace '\r\n', "`n") + $resourceCurrentState.TestQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.TestQuery -replace '\r\n', "`n") + $resourceCurrentState.SetQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.SetQuery -replace '\r\n', "`n") } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -223,7 +223,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -242,13 +242,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -294,17 +294,17 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', throw $_ } - $resultObject.Name | Should -Be $ConfigurationData.AllNodes.Database3Name + $resultObject.Name | Should-Be $ConfigurationData.AllNodes.Database3Name - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.GetQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.GetQuery -replace '\r\n', "`n") - $resourceCurrentState.TestQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.TestQuery -replace '\r\n', "`n") - $resourceCurrentState.SetQuery -replace '\r\n', "`n" | Should -Be ($ConfigurationData.AllNodes.SetQuery -replace '\r\n', "`n") + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.GetQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.GetQuery -replace '\r\n', "`n") + $resourceCurrentState.TestQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.TestQuery -replace '\r\n', "`n") + $resourceCurrentState.SetQuery -replace '\r\n', "`n" | Should-Be ($ConfigurationData.AllNodes.SetQuery -replace '\r\n', "`n") } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -320,7 +320,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -339,7 +339,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 index 3e4dd27c3..af07c7939 100644 --- a/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlSecureConnection.Integration.Tests.ps1 @@ -81,7 +81,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -100,13 +100,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -115,13 +115,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Thumbprint | Should -Be $env:SqlCertificateThumbprint - $resourceCurrentState.ForceEncryption | Should -BeTrue - $resourceCurrentState.ServerName | Should -Be 'localhost' + $resourceCurrentState.Thumbprint | Should-Be $env:SqlCertificateThumbprint + $resourceCurrentState.ForceEncryption | Should-BeTrue + $resourceCurrentState.ServerName | Should-Be 'localhost' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -137,7 +137,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -156,13 +156,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -171,13 +171,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Thumbprint | Should -Be 'Empty' - $resourceCurrentState.ForceEncryption | Should -BeFalse - $resourceCurrentState.ServerName | Should -Be 'localhost' + $resourceCurrentState.Thumbprint | Should-Be 'Empty' + $resourceCurrentState.ForceEncryption | Should-BeFalse + $resourceCurrentState.ServerName | Should-Be 'localhost' } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 index 2f9da0f2d..a5081d558 100644 --- a/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlServiceAccount.Integration.Tests.ps1 @@ -76,7 +76,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -95,7 +95,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -111,7 +111,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -130,13 +130,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -145,12 +145,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlSecondary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlSecondary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -166,7 +166,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -185,13 +185,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -200,12 +200,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentSecondary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentSecondary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -221,7 +221,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -240,13 +240,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -255,12 +255,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlPrimary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlPrimary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -276,7 +276,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -295,13 +295,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -310,12 +310,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentPrimary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentPrimary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -331,7 +331,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -350,7 +350,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -366,7 +366,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -385,13 +385,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -400,12 +400,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlSecondary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlSecondary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -421,7 +421,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -440,13 +440,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -455,12 +455,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentSecondary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentSecondary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -476,7 +476,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -495,13 +495,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -510,12 +510,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlPrimary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeDatabaseEngine + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlPrimary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -531,7 +531,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -550,13 +550,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -565,12 +565,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServiceType | Should -Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent - $resourceCurrentState.ServiceAccountName | Should -Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentPrimary_UserName -Leaf)) + $resourceCurrentState.ServiceType | Should-Be $ConfigurationData.AllNodes.ServiceTypeSqlServerAgent + $resourceCurrentState.ServiceAccountName | Should-Be ('{0}\{1}' -f $env:COMPUTERNAME, (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentPrimary_UserName -Leaf)) } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 index f2935fda2..21bd38702 100644 --- a/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlSetup.Integration.Tests.ps1 @@ -191,7 +191,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -210,7 +210,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -226,7 +226,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -245,12 +245,12 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } # Make sure the module was installed. It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -276,7 +276,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -295,13 +295,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -310,77 +310,77 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Action | Should -Be 'Install' - $resourceCurrentState.AgtSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.AgtSvcAccountUsername | Should -Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentServicePrimaryAccountUserName -Leaf)) - $resourceCurrentState.AgtSvcStartupType | Should -Be 'Automatic' - $resourceCurrentState.ASServerMode | Should -BeNullOrEmpty - $resourceCurrentState.ASBackupDir | Should -BeNullOrEmpty - $resourceCurrentState.ASCollation | Should -BeNullOrEmpty - $resourceCurrentState.ASConfigDir | Should -BeNullOrEmpty - $resourceCurrentState.ASDataDir | Should -BeNullOrEmpty - $resourceCurrentState.ASLogDir | Should -BeNullOrEmpty - $resourceCurrentState.ASTempDir | Should -BeNullOrEmpty - $resourceCurrentState.ASSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ASSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ASSysAdminAccounts | Should -BeNullOrEmpty - $resourceCurrentState.BrowserSvcStartupType | Should -BeNullOrEmpty - $resourceCurrentState.ErrorReporting | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterGroupName | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterIPAddress | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterNetworkName | Should -BeNullOrEmpty - $resourceCurrentState.Features | Should -Be $ConfigurationData.AllNodes.DatabaseEngineNamedInstanceFeatures - $resourceCurrentState.ForceReboot | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.InstallSharedDir | Should -Be $ConfigurationData.AllNodes.InstallSharedDir - $resourceCurrentState.InstallSharedWOWDir | Should -Be $ConfigurationData.AllNodes.InstallSharedWOWDir - $resourceCurrentState.InstallSQLDataDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSQLDataDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)\MSSQL") - $resourceCurrentState.InstanceDir | Should -Be $ConfigurationData.AllNodes.InstanceDir - $resourceCurrentState.InstanceID | Should -Be $ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName - $resourceCurrentState.ISSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ISSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ProductKey | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.SAPwd | Should -BeNullOrEmpty - $resourceCurrentState.SecurityMode | Should -Be 'SQL' - $resourceCurrentState.SetupProcessTimeout | Should -BeNullOrEmpty - $resourceCurrentState.SourceCredential | Should -BeNullOrEmpty - $resourceCurrentState.SourcePath | Should -Be "$($ConfigurationData.AllNodes.DriveLetter):\" - $resourceCurrentState.SQLCollation | Should -Be $ConfigurationData.AllNodes.Collation - $resourceCurrentState.SQLSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.SQLSvcAccountUsername | Should -Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) - $resourceCurrentState.SqlSvcStartupType | Should -Be 'Automatic' - $resourceCurrentState.SQLTempDBDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSQLDataDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)\MSSQL\Data") - $resourceCurrentState.SqlTempDbFileCount | Should -Be $ConfigurationData.AllNodes.SqlTempDbFileCount - $resourceCurrentState.SqlTempDbFileSize | Should -Be $ConfigurationData.AllNodes.SqlTempDbFileSize - $resourceCurrentState.SqlTempDbFileGrowth | Should -Be $ConfigurationData.AllNodes.SqlTempDbFileGrowth - $resourceCurrentState.SQLTempDbLogDir | Should -BeNullOrEmpty - $resourceCurrentState.SqlTempDbLogFileSize | Should -Be $ConfigurationData.AllNodes.SqlTempDbLogFileSize - $resourceCurrentState.SqlTempDbLogFileGrowth | Should -Be $ConfigurationData.AllNodes.SqlTempDbLogFileGrowth - $resourceCurrentState.SQLUserDBDir | Should -Be $ConfigurationData.AllNodes.SQLUserDBDir - $resourceCurrentState.SQLUserDBLogDir | Should -Be $ConfigurationData.AllNodes.SQLUserDBLogDir - $resourceCurrentState.SQLBackupDir | Should -Be $ConfigurationData.AllNodes.SQLBackupDir - $resourceCurrentState.SQMReporting | Should -BeNullOrEmpty - $resourceCurrentState.SuppressReboot | Should -BeNullOrEmpty - $resourceCurrentState.UpdateEnabled | Should -BeNullOrEmpty - $resourceCurrentState.UpdateSource | Should -BeNullOrEmpty - $resourceCurrentState.UseEnglish | Should -BeTrue + $resourceCurrentState.Action | Should-Be 'Install' + $resourceCurrentState.AgtSvcAccount | Should-BeFalsy + $resourceCurrentState.AgtSvcAccountUsername | Should-Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentServicePrimaryAccountUserName -Leaf)) + $resourceCurrentState.AgtSvcStartupType | Should-Be 'Automatic' + $resourceCurrentState.ASServerMode | Should-BeFalsy + $resourceCurrentState.ASBackupDir | Should-BeFalsy + $resourceCurrentState.ASCollation | Should-BeFalsy + $resourceCurrentState.ASConfigDir | Should-BeFalsy + $resourceCurrentState.ASDataDir | Should-BeFalsy + $resourceCurrentState.ASLogDir | Should-BeFalsy + $resourceCurrentState.ASTempDir | Should-BeFalsy + $resourceCurrentState.ASSvcAccount | Should-BeFalsy + $resourceCurrentState.ASSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ASSysAdminAccounts | Should-BeFalsy + $resourceCurrentState.BrowserSvcStartupType | Should-BeFalsy + $resourceCurrentState.ErrorReporting | Should-BeFalsy + $resourceCurrentState.FailoverClusterGroupName | Should-BeFalsy + $resourceCurrentState.FailoverClusterIPAddress | Should-BeFalsy + $resourceCurrentState.FailoverClusterNetworkName | Should-BeFalsy + $resourceCurrentState.Features | Should-Be $ConfigurationData.AllNodes.DatabaseEngineNamedInstanceFeatures + $resourceCurrentState.ForceReboot | Should-BeFalsy + $resourceCurrentState.FTSvcAccount | Should-BeFalsy + $resourceCurrentState.FTSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.InstallSharedDir | Should-Be $ConfigurationData.AllNodes.InstallSharedDir + $resourceCurrentState.InstallSharedWOWDir | Should-Be $ConfigurationData.AllNodes.InstallSharedWOWDir + $resourceCurrentState.InstallSQLDataDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSQLDataDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)\MSSQL") + $resourceCurrentState.InstanceDir | Should-Be $ConfigurationData.AllNodes.InstanceDir + $resourceCurrentState.InstanceID | Should-Be $ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName + $resourceCurrentState.ISSvcAccount | Should-BeFalsy + $resourceCurrentState.ISSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ProductKey | Should-BeFalsy + $resourceCurrentState.RSSvcAccount | Should-BeFalsy + $resourceCurrentState.RSSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.SAPwd | Should-BeFalsy + $resourceCurrentState.SecurityMode | Should-Be 'SQL' + $resourceCurrentState.SetupProcessTimeout | Should-BeFalsy + $resourceCurrentState.SourceCredential | Should-BeFalsy + $resourceCurrentState.SourcePath | Should-Be "$($ConfigurationData.AllNodes.DriveLetter):\" + $resourceCurrentState.SQLCollation | Should-Be $ConfigurationData.AllNodes.Collation + $resourceCurrentState.SQLSvcAccount | Should-BeFalsy + $resourceCurrentState.SQLSvcAccountUsername | Should-Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) + $resourceCurrentState.SqlSvcStartupType | Should-Be 'Automatic' + $resourceCurrentState.SQLTempDBDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSQLDataDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)\MSSQL\Data") + $resourceCurrentState.SqlTempDbFileCount | Should-Be $ConfigurationData.AllNodes.SqlTempDbFileCount + $resourceCurrentState.SqlTempDbFileSize | Should-Be $ConfigurationData.AllNodes.SqlTempDbFileSize + $resourceCurrentState.SqlTempDbFileGrowth | Should-Be $ConfigurationData.AllNodes.SqlTempDbFileGrowth + $resourceCurrentState.SQLTempDbLogDir | Should-BeFalsy + $resourceCurrentState.SqlTempDbLogFileSize | Should-Be $ConfigurationData.AllNodes.SqlTempDbLogFileSize + $resourceCurrentState.SqlTempDbLogFileGrowth | Should-Be $ConfigurationData.AllNodes.SqlTempDbLogFileGrowth + $resourceCurrentState.SQLUserDBDir | Should-Be $ConfigurationData.AllNodes.SQLUserDBDir + $resourceCurrentState.SQLUserDBLogDir | Should-Be $ConfigurationData.AllNodes.SQLUserDBLogDir + $resourceCurrentState.SQLBackupDir | Should-Be $ConfigurationData.AllNodes.SQLBackupDir + $resourceCurrentState.SQMReporting | Should-BeFalsy + $resourceCurrentState.SuppressReboot | Should-BeFalsy + $resourceCurrentState.UpdateEnabled | Should-BeFalsy + $resourceCurrentState.UpdateSource | Should-BeFalsy + $resourceCurrentState.UseEnglish | Should-BeTrue # Verify all the accounts are returned in the property SQLSysAdminAccounts. - $ConfigurationData.AllNodes.SqlAdministratorAccountUserName | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - $ConfigurationData.AllNodes.SqlInstallAccountUserName | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - "NT SERVICE\MSSQL`$$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)" | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - "NT SERVICE\SQLAgent`$$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)" | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'NT SERVICE\SQLWriter' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'NT SERVICE\Winmgmt' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'sa' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ($ConfigurationData.AllNodes.SqlAdministratorAccountUserName) + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ($ConfigurationData.AllNodes.SqlInstallAccountUserName) + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ("NT SERVICE\MSSQL`$$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)") + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ("NT SERVICE\SQLAgent`$$($ConfigurationData.AllNodes.DatabaseEngineNamedInstanceName)") + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('NT SERVICE\SQLWriter') + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('NT SERVICE\Winmgmt') + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('sa') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -396,7 +396,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -415,7 +415,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -441,7 +441,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -460,13 +460,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -475,72 +475,72 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Action | Should -Be 'Install' - $resourceCurrentState.AgtSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.AgtSvcAccountUsername | Should -Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentServicePrimaryAccountUserName -Leaf)) - $resourceCurrentState.ASServerMode | Should -BeNullOrEmpty - $resourceCurrentState.ASBackupDir | Should -BeNullOrEmpty - $resourceCurrentState.ASCollation | Should -BeNullOrEmpty - $resourceCurrentState.ASConfigDir | Should -BeNullOrEmpty - $resourceCurrentState.ASDataDir | Should -BeNullOrEmpty - $resourceCurrentState.ASLogDir | Should -BeNullOrEmpty - $resourceCurrentState.ASTempDir | Should -BeNullOrEmpty - $resourceCurrentState.ASSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ASSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ASSysAdminAccounts | Should -BeNullOrEmpty - $resourceCurrentState.BrowserSvcStartupType | Should -BeNullOrEmpty - $resourceCurrentState.ErrorReporting | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterGroupName | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterIPAddress | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterNetworkName | Should -BeNullOrEmpty - $resourceCurrentState.Features | Should -Be $ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceFeatures - $resourceCurrentState.ForceReboot | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.InstallSharedDir | Should -Be $ConfigurationData.AllNodes.InstallSharedDir - $resourceCurrentState.InstallSharedWOWDir | Should -Be $ConfigurationData.AllNodes.InstallSharedWOWDir - $resourceCurrentState.InstallSQLDataDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL") - $resourceCurrentState.InstanceDir | Should -Be $ConfigurationData.AllNodes.InstallSharedDir - $resourceCurrentState.InstanceID | Should -Be $ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName - $resourceCurrentState.ISSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ISSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ProductKey | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.SAPwd | Should -BeNullOrEmpty - $resourceCurrentState.SecurityMode | Should -BeNullOrEmpty - $resourceCurrentState.SetupProcessTimeout | Should -BeNullOrEmpty - $resourceCurrentState.SourceCredential | Should -BeNullOrEmpty - $resourceCurrentState.SourcePath | Should -Be "$($ConfigurationData.AllNodes.DriveLetter):\" - $resourceCurrentState.SQLBackupDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\Backup") - $resourceCurrentState.SQLCollation | Should -Be $ConfigurationData.AllNodes.Collation - $resourceCurrentState.SQLSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.SQLSvcAccountUsername | Should -Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) - $resourceCurrentState.SQLTempDBDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\Data") - $resourceCurrentState.SQLTempDBLogDir | Should -BeNullOrEmpty - $resourceCurrentState.SQMReporting | Should -BeNullOrEmpty - $resourceCurrentState.SuppressReboot | Should -BeNullOrEmpty - $resourceCurrentState.UpdateEnabled | Should -BeNullOrEmpty - $resourceCurrentState.UpdateSource | Should -BeNullOrEmpty - $resourceCurrentState.UseEnglish | Should -BeFalse + $resourceCurrentState.Action | Should-Be 'Install' + $resourceCurrentState.AgtSvcAccount | Should-BeFalsy + $resourceCurrentState.AgtSvcAccountUsername | Should-Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlAgentServicePrimaryAccountUserName -Leaf)) + $resourceCurrentState.ASServerMode | Should-BeFalsy + $resourceCurrentState.ASBackupDir | Should-BeFalsy + $resourceCurrentState.ASCollation | Should-BeFalsy + $resourceCurrentState.ASConfigDir | Should-BeFalsy + $resourceCurrentState.ASDataDir | Should-BeFalsy + $resourceCurrentState.ASLogDir | Should-BeFalsy + $resourceCurrentState.ASTempDir | Should-BeFalsy + $resourceCurrentState.ASSvcAccount | Should-BeFalsy + $resourceCurrentState.ASSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ASSysAdminAccounts | Should-BeFalsy + $resourceCurrentState.BrowserSvcStartupType | Should-BeFalsy + $resourceCurrentState.ErrorReporting | Should-BeFalsy + $resourceCurrentState.FailoverClusterGroupName | Should-BeFalsy + $resourceCurrentState.FailoverClusterIPAddress | Should-BeFalsy + $resourceCurrentState.FailoverClusterNetworkName | Should-BeFalsy + $resourceCurrentState.Features | Should-Be $ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceFeatures + $resourceCurrentState.ForceReboot | Should-BeFalsy + $resourceCurrentState.FTSvcAccount | Should-BeFalsy + $resourceCurrentState.FTSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.InstallSharedDir | Should-Be $ConfigurationData.AllNodes.InstallSharedDir + $resourceCurrentState.InstallSharedWOWDir | Should-Be $ConfigurationData.AllNodes.InstallSharedWOWDir + $resourceCurrentState.InstallSQLDataDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL") + $resourceCurrentState.InstanceDir | Should-Be $ConfigurationData.AllNodes.InstallSharedDir + $resourceCurrentState.InstanceID | Should-Be $ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName + $resourceCurrentState.ISSvcAccount | Should-BeFalsy + $resourceCurrentState.ISSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ProductKey | Should-BeFalsy + $resourceCurrentState.RSSvcAccount | Should-BeFalsy + $resourceCurrentState.RSSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.SAPwd | Should-BeFalsy + $resourceCurrentState.SecurityMode | Should-BeFalsy + $resourceCurrentState.SetupProcessTimeout | Should-BeFalsy + $resourceCurrentState.SourceCredential | Should-BeFalsy + $resourceCurrentState.SourcePath | Should-Be "$($ConfigurationData.AllNodes.DriveLetter):\" + $resourceCurrentState.SQLBackupDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\Backup") + $resourceCurrentState.SQLCollation | Should-Be $ConfigurationData.AllNodes.Collation + $resourceCurrentState.SQLSvcAccount | Should-BeFalsy + $resourceCurrentState.SQLSvcAccountUsername | Should-Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) + $resourceCurrentState.SQLTempDBDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\Data") + $resourceCurrentState.SQLTempDBLogDir | Should-BeFalsy + $resourceCurrentState.SQMReporting | Should-BeFalsy + $resourceCurrentState.SuppressReboot | Should-BeFalsy + $resourceCurrentState.UpdateEnabled | Should-BeFalsy + $resourceCurrentState.UpdateSource | Should-BeFalsy + $resourceCurrentState.UseEnglish | Should-BeFalse # Regression test for issue #1287 - $resourceCurrentState.SQLUserDBDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\DATA\") - $resourceCurrentState.SQLUserDBLogDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\DATA\") + $resourceCurrentState.SQLUserDBDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\DATA\") + $resourceCurrentState.SQLUserDBLogDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.SqlServerInstanceIdPrefix).$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)\MSSQL\DATA\") # Verify all the accounts are returned in the property SQLSysAdminAccounts. - $ConfigurationData.AllNodes.SqlAdministratorAccountUserName | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - $ConfigurationData.AllNodes.SqlInstallAccountUserName | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - "NT SERVICE\$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)" | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'NT SERVICE\SQLSERVERAGENT' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'NT SERVICE\SQLWriter' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'NT SERVICE\Winmgmt' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts - 'sa' | Should -BeIn $resourceCurrentState.SQLSysAdminAccounts + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ($ConfigurationData.AllNodes.SqlAdministratorAccountUserName) + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ($ConfigurationData.AllNodes.SqlInstallAccountUserName) + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ("NT SERVICE\$($ConfigurationData.AllNodes.DatabaseEngineDefaultInstanceName)") + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('NT SERVICE\SQLSERVERAGENT') + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('NT SERVICE\SQLWriter') + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('NT SERVICE\Winmgmt') + $resourceCurrentState.SQLSysAdminAccounts | Should-ContainCollection ('sa') } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -556,7 +556,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -575,7 +575,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -601,7 +601,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -620,13 +620,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -635,27 +635,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Action | Should -Be 'Install' - $resourceCurrentState.AgtSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.AgtSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ASServerMode | Should -Be $ConfigurationData.AllNodes.AnalysisServicesMultiServerMode - $resourceCurrentState.ASBackupDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Backup") - $resourceCurrentState.ASCollation | Should -Be $ConfigurationData.AllNodes.Collation - $resourceCurrentState.ASConfigDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Config") - $resourceCurrentState.ASDataDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Data") - $resourceCurrentState.ASLogDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Log") - $resourceCurrentState.ASTempDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Temp") - $resourceCurrentState.ASSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ASSvcAccountUsername | Should -Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) - $resourceCurrentState.ASSysAdminAccounts | Should -Be @( + $resourceCurrentState.Action | Should-Be 'Install' + $resourceCurrentState.AgtSvcAccount | Should-BeFalsy + $resourceCurrentState.AgtSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ASServerMode | Should-Be $ConfigurationData.AllNodes.AnalysisServicesMultiServerMode + $resourceCurrentState.ASBackupDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Backup") + $resourceCurrentState.ASCollation | Should-Be $ConfigurationData.AllNodes.Collation + $resourceCurrentState.ASConfigDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Config") + $resourceCurrentState.ASDataDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Data") + $resourceCurrentState.ASLogDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Log") + $resourceCurrentState.ASTempDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)\OLAP\Temp") + $resourceCurrentState.ASSvcAccount | Should-BeFalsy + $resourceCurrentState.ASSvcAccountUsername | Should-Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) + $resourceCurrentState.ASSysAdminAccounts | Should-Be @( $ConfigurationData.AllNodes.SqlAdministratorAccountUserName, "NT SERVICE\SSASTELEMETRY`$$($ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName)" ) - $resourceCurrentState.BrowserSvcStartupType | Should -BeNullOrEmpty - $resourceCurrentState.ErrorReporting | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterGroupName | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterIPAddress | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterNetworkName | Should -BeNullOrEmpty + $resourceCurrentState.BrowserSvcStartupType | Should-BeFalsy + $resourceCurrentState.ErrorReporting | Should-BeFalsy + $resourceCurrentState.FailoverClusterGroupName | Should-BeFalsy + $resourceCurrentState.FailoverClusterIPAddress | Should-BeFalsy + $resourceCurrentState.FailoverClusterNetworkName | Should-BeFalsy if ($script:sqlVersion -in (160)) { @@ -664,49 +664,49 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Thus they are not installed with the Database Engine instance DSCSQLTEST in prior test, so this test do not find them already installed. #> - $resourceCurrentState.Features | Should -Be 'AS' + $resourceCurrentState.Features | Should-Be 'AS' } else { - $resourceCurrentState.Features | Should -Be 'AS,CONN,BC,SDK' + $resourceCurrentState.Features | Should-Be 'AS,CONN,BC,SDK' } - $resourceCurrentState.ForceReboot | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.InstallSharedDir | Should -Be $ConfigurationData.AllNodes.InstallSharedDir - $resourceCurrentState.InstallSharedWOWDir | Should -Be $ConfigurationData.AllNodes.InstallSharedWOWDir - $resourceCurrentState.InstallSQLDataDir | Should -BeNullOrEmpty - $resourceCurrentState.InstanceDir | Should -BeNullOrEmpty - $resourceCurrentState.InstanceID | Should -BeNullOrEmpty - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName - $resourceCurrentState.ISSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ISSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ProductKey | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.SAPwd | Should -BeNullOrEmpty - $resourceCurrentState.SecurityMode | Should -BeNullOrEmpty - $resourceCurrentState.SetupProcessTimeout | Should -BeNullOrEmpty - $resourceCurrentState.SourceCredential | Should -BeNullOrEmpty - $resourceCurrentState.SourcePath | Should -Be "$($ConfigurationData.AllNodes.DriveLetter):\" - $resourceCurrentState.SQLBackupDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLCollation | Should -BeNullOrEmpty - $resourceCurrentState.SQLSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.SQLSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.SQLSysAdminAccounts | Should -BeNullOrEmpty - $resourceCurrentState.SQLTempDBDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLTempDBLogDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLUserDBDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLUserDBLogDir | Should -BeNullOrEmpty - $resourceCurrentState.SQMReporting | Should -BeNullOrEmpty - $resourceCurrentState.SuppressReboot | Should -BeNullOrEmpty - $resourceCurrentState.UpdateEnabled | Should -BeNullOrEmpty - $resourceCurrentState.UpdateSource | Should -BeNullOrEmpty + $resourceCurrentState.ForceReboot | Should-BeFalsy + $resourceCurrentState.FTSvcAccount | Should-BeFalsy + $resourceCurrentState.FTSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.InstallSharedDir | Should-Be $ConfigurationData.AllNodes.InstallSharedDir + $resourceCurrentState.InstallSharedWOWDir | Should-Be $ConfigurationData.AllNodes.InstallSharedWOWDir + $resourceCurrentState.InstallSQLDataDir | Should-BeFalsy + $resourceCurrentState.InstanceDir | Should-BeFalsy + $resourceCurrentState.InstanceID | Should-BeFalsy + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.AnalysisServicesMultiInstanceName + $resourceCurrentState.ISSvcAccount | Should-BeFalsy + $resourceCurrentState.ISSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ProductKey | Should-BeFalsy + $resourceCurrentState.RSSvcAccount | Should-BeFalsy + $resourceCurrentState.RSSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.SAPwd | Should-BeFalsy + $resourceCurrentState.SecurityMode | Should-BeFalsy + $resourceCurrentState.SetupProcessTimeout | Should-BeFalsy + $resourceCurrentState.SourceCredential | Should-BeFalsy + $resourceCurrentState.SourcePath | Should-Be "$($ConfigurationData.AllNodes.DriveLetter):\" + $resourceCurrentState.SQLBackupDir | Should-BeFalsy + $resourceCurrentState.SQLCollation | Should-BeFalsy + $resourceCurrentState.SQLSvcAccount | Should-BeFalsy + $resourceCurrentState.SQLSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.SQLSysAdminAccounts | Should-BeFalsy + $resourceCurrentState.SQLTempDBDir | Should-BeFalsy + $resourceCurrentState.SQLTempDBLogDir | Should-BeFalsy + $resourceCurrentState.SQLUserDBDir | Should-BeFalsy + $resourceCurrentState.SQLUserDBLogDir | Should-BeFalsy + $resourceCurrentState.SQMReporting | Should-BeFalsy + $resourceCurrentState.SuppressReboot | Should-BeFalsy + $resourceCurrentState.UpdateEnabled | Should-BeFalsy + $resourceCurrentState.UpdateSource | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -722,7 +722,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -741,7 +741,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -767,7 +767,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -786,13 +786,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } -ErrorVariable itBlockError It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -801,27 +801,27 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Action | Should -Be 'Install' - $resourceCurrentState.AgtSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.AgtSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ASServerMode | Should -Be $ConfigurationData.AllNodes.AnalysisServicesTabularServerMode - $resourceCurrentState.ASBackupDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Backup") - $resourceCurrentState.ASCollation | Should -Be $ConfigurationData.AllNodes.Collation - $resourceCurrentState.ASConfigDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Config") - $resourceCurrentState.ASDataDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Data") - $resourceCurrentState.ASLogDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Log") - $resourceCurrentState.ASTempDir | Should -Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Temp") - $resourceCurrentState.ASSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ASSvcAccountUsername | Should -Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) - $resourceCurrentState.ASSysAdminAccounts | Should -Be @( + $resourceCurrentState.Action | Should-Be 'Install' + $resourceCurrentState.AgtSvcAccount | Should-BeFalsy + $resourceCurrentState.AgtSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ASServerMode | Should-Be $ConfigurationData.AllNodes.AnalysisServicesTabularServerMode + $resourceCurrentState.ASBackupDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Backup") + $resourceCurrentState.ASCollation | Should-Be $ConfigurationData.AllNodes.Collation + $resourceCurrentState.ASConfigDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Config") + $resourceCurrentState.ASDataDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Data") + $resourceCurrentState.ASLogDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Log") + $resourceCurrentState.ASTempDir | Should-Be (Join-Path -Path $ConfigurationData.AllNodes.InstallSharedDir -ChildPath "$($ConfigurationData.AllNodes.AnalysisServiceInstanceIdPrefix).$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)\OLAP\Temp") + $resourceCurrentState.ASSvcAccount | Should-BeFalsy + $resourceCurrentState.ASSvcAccountUsername | Should-Be ('.\{0}' -f (Split-Path -Path $ConfigurationData.AllNodes.SqlServicePrimaryAccountUserName -Leaf)) + $resourceCurrentState.ASSysAdminAccounts | Should-Be @( $ConfigurationData.AllNodes.SqlAdministratorAccountUserName, "NT SERVICE\SSASTELEMETRY`$$($ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName)" ) - $resourceCurrentState.BrowserSvcStartupType | Should -BeNullOrEmpty - $resourceCurrentState.ErrorReporting | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterGroupName | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterIPAddress | Should -BeNullOrEmpty - $resourceCurrentState.FailoverClusterNetworkName | Should -BeNullOrEmpty + $resourceCurrentState.BrowserSvcStartupType | Should-BeFalsy + $resourceCurrentState.ErrorReporting | Should-BeFalsy + $resourceCurrentState.FailoverClusterGroupName | Should-BeFalsy + $resourceCurrentState.FailoverClusterIPAddress | Should-BeFalsy + $resourceCurrentState.FailoverClusterNetworkName | Should-BeFalsy if ($script:sqlVersion -in (160)) { @@ -830,49 +830,49 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', Thus they are not installed with the Database Engine instance DSCSQLTEST in prior test, so this test do not find them already installed. #> - $resourceCurrentState.Features | Should -Be 'AS' + $resourceCurrentState.Features | Should-Be 'AS' } else { - $resourceCurrentState.Features | Should -Be 'AS,CONN,BC,SDK' + $resourceCurrentState.Features | Should-Be 'AS,CONN,BC,SDK' } - $resourceCurrentState.ForceReboot | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.FTSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.InstallSharedDir | Should -Be $ConfigurationData.AllNodes.InstallSharedDir - $resourceCurrentState.InstallSharedWOWDir | Should -Be $ConfigurationData.AllNodes.InstallSharedWOWDir - $resourceCurrentState.InstallSQLDataDir | Should -BeNullOrEmpty - $resourceCurrentState.InstanceDir | Should -BeNullOrEmpty - $resourceCurrentState.InstanceID | Should -BeNullOrEmpty - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName - $resourceCurrentState.ISSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.ISSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.ProductKey | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.RSSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.SAPwd | Should -BeNullOrEmpty - $resourceCurrentState.SecurityMode | Should -BeNullOrEmpty - $resourceCurrentState.SetupProcessTimeout | Should -BeNullOrEmpty - $resourceCurrentState.SourceCredential | Should -BeNullOrEmpty - $resourceCurrentState.SourcePath | Should -Be "$($ConfigurationData.AllNodes.DriveLetter):\" - $resourceCurrentState.SQLBackupDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLCollation | Should -BeNullOrEmpty - $resourceCurrentState.SQLSvcAccount | Should -BeNullOrEmpty - $resourceCurrentState.SQLSvcAccountUsername | Should -BeNullOrEmpty - $resourceCurrentState.SQLSysAdminAccounts | Should -BeNullOrEmpty - $resourceCurrentState.SQLTempDBDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLTempDBLogDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLUserDBDir | Should -BeNullOrEmpty - $resourceCurrentState.SQLUserDBLogDir | Should -BeNullOrEmpty - $resourceCurrentState.SQMReporting | Should -BeNullOrEmpty - $resourceCurrentState.SuppressReboot | Should -BeNullOrEmpty - $resourceCurrentState.UpdateEnabled | Should -BeNullOrEmpty - $resourceCurrentState.UpdateSource | Should -BeNullOrEmpty + $resourceCurrentState.ForceReboot | Should-BeFalsy + $resourceCurrentState.FTSvcAccount | Should-BeFalsy + $resourceCurrentState.FTSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.InstallSharedDir | Should-Be $ConfigurationData.AllNodes.InstallSharedDir + $resourceCurrentState.InstallSharedWOWDir | Should-Be $ConfigurationData.AllNodes.InstallSharedWOWDir + $resourceCurrentState.InstallSQLDataDir | Should-BeFalsy + $resourceCurrentState.InstanceDir | Should-BeFalsy + $resourceCurrentState.InstanceID | Should-BeFalsy + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.AnalysisServicesTabularInstanceName + $resourceCurrentState.ISSvcAccount | Should-BeFalsy + $resourceCurrentState.ISSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.ProductKey | Should-BeFalsy + $resourceCurrentState.RSSvcAccount | Should-BeFalsy + $resourceCurrentState.RSSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.SAPwd | Should-BeFalsy + $resourceCurrentState.SecurityMode | Should-BeFalsy + $resourceCurrentState.SetupProcessTimeout | Should-BeFalsy + $resourceCurrentState.SourceCredential | Should-BeFalsy + $resourceCurrentState.SourcePath | Should-Be "$($ConfigurationData.AllNodes.DriveLetter):\" + $resourceCurrentState.SQLBackupDir | Should-BeFalsy + $resourceCurrentState.SQLCollation | Should-BeFalsy + $resourceCurrentState.SQLSvcAccount | Should-BeFalsy + $resourceCurrentState.SQLSvcAccountUsername | Should-BeFalsy + $resourceCurrentState.SQLSysAdminAccounts | Should-BeFalsy + $resourceCurrentState.SQLTempDBDir | Should-BeFalsy + $resourceCurrentState.SQLTempDBLogDir | Should-BeFalsy + $resourceCurrentState.SQLUserDBDir | Should-BeFalsy + $resourceCurrentState.SQLUserDBLogDir | Should-BeFalsy + $resourceCurrentState.SQMReporting | Should-BeFalsy + $resourceCurrentState.SuppressReboot | Should-BeFalsy + $resourceCurrentState.UpdateEnabled | Should-BeFalsy + $resourceCurrentState.UpdateSource | Should-BeFalsy } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -888,7 +888,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -907,7 +907,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -923,7 +923,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -942,7 +942,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } } diff --git a/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 index e89e94c75..3d044b8f3 100644 --- a/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlTraceFlag.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,13 +86,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -101,18 +101,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 1 - $resourceCurrentState.TraceFlags | Should -Contain '2371' - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 1 + $resourceCurrentState.TraceFlags | Should-ContainCollection '2371' + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -128,7 +128,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -147,13 +147,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -162,19 +162,19 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 2 - $resourceCurrentState.TraceFlags | Should -Contain '3226' - $resourceCurrentState.TraceFlags | Should -Contain '4199' - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 2 + $resourceCurrentState.TraceFlags | Should-ContainCollection '3226' + $resourceCurrentState.TraceFlags | Should-ContainCollection '4199' + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -190,7 +190,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -209,13 +209,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -224,18 +224,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 1 - $resourceCurrentState.TraceFlags | Should -Contain '3226' - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 1 + $resourceCurrentState.TraceFlags | Should-ContainCollection '3226' + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -251,7 +251,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -270,13 +270,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -285,19 +285,19 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 2 - $resourceCurrentState.TraceFlags | Should -Contain '3226' - $resourceCurrentState.TraceFlags | Should -Contain '4199' - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 2 + $resourceCurrentState.TraceFlags | Should-ContainCollection '3226' + $resourceCurrentState.TraceFlags | Should-ContainCollection '4199' + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -313,7 +313,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -332,13 +332,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -347,18 +347,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 0 - $resourceCurrentState.TraceFlags | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 0 + $resourceCurrentState.TraceFlags | Should-BeFalsy + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -374,7 +374,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -393,13 +393,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -408,18 +408,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 0 - $resourceCurrentState.TraceFlags | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 0 + $resourceCurrentState.TraceFlags | Should-BeFalsy + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -435,7 +435,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -454,13 +454,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -469,18 +469,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 1 - $resourceCurrentState.TraceFlags | Should -Contain '4199' - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 1 + $resourceCurrentState.TraceFlags | Should-ContainCollection '4199' + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } @@ -496,7 +496,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -515,13 +515,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -530,18 +530,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.ServerName | Should -Be $ConfigurationData.AllNodes.ServerName - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.TraceFlags | Should -HaveCount 0 - $resourceCurrentState.TraceFlags | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToInclude | Should -BeNullOrEmpty - $resourceCurrentState.TraceFlagsToExclude | Should -BeNullOrEmpty - $resourceCurrentState.RestartService | Should -BeNullOrEmpty - $resourceCurrentState.RestartTimeout | Should -BeNullOrEmpty + $resourceCurrentState.ServerName | Should-Be $ConfigurationData.AllNodes.ServerName + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.TraceFlags | Should-BeCollection -Count 0 + $resourceCurrentState.TraceFlags | Should-BeFalsy + $resourceCurrentState.TraceFlagsToInclude | Should-BeFalsy + $resourceCurrentState.TraceFlagsToExclude | Should-BeFalsy + $resourceCurrentState.RestartService | Should-BeFalsy + $resourceCurrentState.RestartTimeout | Should-BeFalsy } It 'Should return ''True'' when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 b/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 index 0b185c8f8..59f0be691 100644 --- a/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 +++ b/tests/Integration/Resources/DSC_SqlWindowsFirewall.Integration.Tests.ps1 @@ -67,7 +67,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -86,7 +86,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } } @@ -102,7 +102,7 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } It 'Should compile and apply the MOF without throwing' { - { + $null = & ({ $configurationParameters = @{ OutputPath = $TestDrive # The variable $ConfigurationData was dot-sourced above. @@ -121,13 +121,13 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', } Start-DscConfiguration @startDscConfigurationParameters - } | Should -Not -Throw + }) } It 'Should be able to call Get-DscConfiguration without throwing' { - { + $null = & ({ $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop - } | Should -Not -Throw + }) } It 'Should have set the resource and all the parameters should match' { @@ -136,18 +136,18 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016', -and $_.ResourceId -eq $resourceId } - $resourceCurrentState.Features | Should -Be 'SQLENGINE' - $resourceCurrentState.InstanceName | Should -Be $ConfigurationData.AllNodes.InstanceName - $resourceCurrentState.SourcePath | Should -Be $ConfigurationData.AllNodes.SourcePath - $resourceCurrentState.DatabaseEngineFirewall | Should -BeTrue - $resourceCurrentState.BrowserFirewall | Should -BeTrue - $resourceCurrentState.ReportingServicesFirewall | Should -BeFalse - $resourceCurrentState.AnalysisServicesFirewall | Should -BeFalse - $resourceCurrentState.IntegrationServicesFirewall | Should -BeFalse + $resourceCurrentState.Features | Should-Be 'SQLENGINE' + $resourceCurrentState.InstanceName | Should-Be $ConfigurationData.AllNodes.InstanceName + $resourceCurrentState.SourcePath | Should-Be $ConfigurationData.AllNodes.SourcePath + $resourceCurrentState.DatabaseEngineFirewall | Should-BeTrue + $resourceCurrentState.BrowserFirewall | Should-BeTrue + $resourceCurrentState.ReportingServicesFirewall | Should-BeFalse + $resourceCurrentState.AnalysisServicesFirewall | Should-BeFalse + $resourceCurrentState.IntegrationServicesFirewall | Should-BeFalse } It 'Should return $true when Test-DscConfiguration is run' { - Test-DscConfiguration -Verbose | Should -Be 'True' + Test-DscConfiguration -Verbose | Should-Be 'True' } } } diff --git a/tests/QA/ScriptAnalyzer.Tests.ps1 b/tests/QA/ScriptAnalyzer.Tests.ps1 index 0b8a15f80..268c1de1a 100644 --- a/tests/QA/ScriptAnalyzer.Tests.ps1 +++ b/tests/QA/ScriptAnalyzer.Tests.ps1 @@ -101,7 +101,7 @@ Describe 'Script Analyzer Rules' { $report = $pssaError | Format-Table -AutoSize | Out-String -Width 200 - $pssaError | Should -HaveCount 0 -Because "all script analyzer rules should pass.`r`n`r`n $report`r`n" + $pssaError | Should-BeCollection -Because "all script analyzer rules should pass.`r`n`r`n $report`r`n" -Count 0 } } } diff --git a/tests/QA/module.tests.ps1 b/tests/QA/module.tests.ps1 index 3db37dce3..4ccc75d63 100644 --- a/tests/QA/module.tests.ps1 +++ b/tests/QA/module.tests.ps1 @@ -93,30 +93,30 @@ Describe 'Changelog Management' -Tag 'Changelog' { # Only check if there are any changed files. if ($filesChanged) { - $filesChanged | Should -Contain 'CHANGELOG.md' -Because 'the CHANGELOG.md must be updated with at least one entry in the Unreleased section for each PR' + $filesChanged | Should-ContainCollection 'CHANGELOG.md' -Because 'the CHANGELOG.md must be updated with at least one entry in the Unreleased section for each PR' } } 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-BeTruthy } } 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 + Get-Module -Name $script:moduleName | Should-BeTruthy } 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 + Get-Module $script:moduleName | Should-BeFalsy } } @@ -166,7 +166,7 @@ Describe 'Quality for module' -Tags 'TestQuality' { } It 'Should have a unit test for ' -ForEach $testCasesAllModuleFunction { - Get-ChildItem -Path 'tests\' -Recurse -Include "$Name.Tests.ps1" | Should -Not -BeNullOrEmpty + Get-ChildItem -Path 'tests\' -Recurse -Include "$Name.Tests.ps1" | Should-BeTruthy } It 'Should pass Script Analyzer for ' -ForEach $testCasesAllModuleFunction -Skip:(-not $scriptAnalyzerRules) { @@ -174,8 +174,7 @@ Describe 'Quality for module' -Tags 'TestQuality' { $pssaResult = (Invoke-ScriptAnalyzer -Path $functionFile.FullName) $report = $pssaResult | Format-Table -AutoSize | Out-String -Width 110 - $pssaResult | Should -BeNullOrEmpty -Because ` - "some rule triggered.`r`n`r`n $report" + $pssaResult | Should-BeFalsy -Because "some rule triggered.`r`n`r`n $report" } } @@ -199,17 +198,17 @@ Describe 'Help for module' -Tags 'helpQuality' { } It 'Should have .SYNOPSIS' { - $functionHelp.Synopsis | Should -Not -BeNullOrEmpty + $functionHelp.Synopsis | Should-BeTruthy } It 'Should have a .DESCRIPTION with length greater than 40 characters for ' { - $functionHelp.Description.Length | Should -BeGreaterThan 40 + $functionHelp.Description.Length | Should-BeGreaterThan 40 } It 'Should have at least one (1) example for ' { - $functionHelp.Examples.Count | Should -BeGreaterThan 0 - $functionHelp.Examples[0] | Should -Match ([regex]::Escape($function.Name)) - $functionHelp.Examples[0].Length | Should -BeGreaterThan ($function.Name.Length + 10) + $functionHelp.Examples.Count | Should-BeGreaterThan 0 + $functionHelp.Examples[0] | Should-MatchString ([regex]::Escape($function.Name)) + $functionHelp.Examples[0].Length | Should-BeGreaterThan ($function.Name.Length + 10) } It 'Should have described all parameters for ' { @@ -217,8 +216,8 @@ Describe 'Help for module' -Tags 'helpQuality' { foreach ($parameter in $parameters) { - $functionHelp.Parameters.($parameter.ToUpper()) | Should -Not -BeNullOrEmpty -Because ('the parameter {0} must have a description' -f $parameter) - $functionHelp.Parameters.($parameter.ToUpper()).Length | Should -BeGreaterThan 25 -Because ('the parameter {0} must have descriptive description' -f $parameter) + $functionHelp.Parameters.($parameter.ToUpper()) | Should-BeTruthy -Because ('the parameter {0} must have a description' -f $parameter) + $functionHelp.Parameters.($parameter.ToUpper()).Length | Should-BeGreaterThan 25 -Because ('the parameter {0} must have descriptive description' -f $parameter) } } } diff --git a/tests/Unit/Classes/DatabasePermission.Tests.ps1 b/tests/Unit/Classes/DatabasePermission.Tests.ps1 index 61aa45e43..b3972da04 100644 --- a/tests/Unit/Classes/DatabasePermission.Tests.ps1 +++ b/tests/Unit/Classes/DatabasePermission.Tests.ps1 @@ -55,8 +55,8 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } It 'Should be of the correct type' { - $mockDatabasePermissionInstance | Should -Not -BeNullOrEmpty - $mockDatabasePermissionInstance.GetType().Name | Should -Be 'DatabasePermission' + $mockDatabasePermissionInstance | Should-BeTruthy + $mockDatabasePermissionInstance.GetType().Name | Should-Be 'DatabasePermission' } } @@ -73,7 +73,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } It 'Should be able read the values from instance' { - $mockDatabasePermissionInstance.State | Should -Be 'Grant' + $mockDatabasePermissionInstance.State | Should-Be 'Grant' $mockDatabasePermissionInstance.Permission = 'select' } } @@ -93,7 +93,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { $databasPermissionInstance2.State = 'Grant' $databasPermissionInstance2.Permission = 'select' - $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should -BeTrue + $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should-BeTrue } } } @@ -111,7 +111,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { $databasPermissionInstance2.State = 'Grant' $databasPermissionInstance2.Permission = @('select', 'update') - $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should -BeTrue + $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should-BeTrue } } } @@ -139,7 +139,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } It 'Should return $false' { - $mockDatabasePermissionInstance1 -eq $mockDatabasePermissionInstance2 | Should -BeFalse + $mockDatabasePermissionInstance1 -eq $mockDatabasePermissionInstance2 | Should-BeFalse } } @@ -165,7 +165,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } It 'Should return $false' { - $mockDatabasePermissionInstance1 -eq $mockDatabasePermissionInstance2 | Should -BeFalse + $mockDatabasePermissionInstance1 -eq $mockDatabasePermissionInstance2 | Should-BeFalse } } } @@ -195,7 +195,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { $mockErrorMessage = $mockErrorMessage -replace '\[', '`[' $mockErrorMessage = $mockErrorMessage -replace '\]', '`]' - { $mockDatabasePermissionInstance1.CompareTo('AnyValue') } | Should -Throw -ExpectedMessage $mockErrorMessage + { $mockDatabasePermissionInstance1.CompareTo('AnyValue') } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -229,7 +229,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } } - $mockDatabasePermissionInstance1.CompareTo($mockDatabasePermissionInstance2) | Should -BeLessThan 0 + $mockDatabasePermissionInstance1.CompareTo($mockDatabasePermissionInstance2) | Should-BeLessThan 0 } } } @@ -264,7 +264,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } } - $mockDatabasePermissionInstance1.CompareTo($mockDatabasePermissionInstance2) | Should -BeGreaterThan 0 + $mockDatabasePermissionInstance1.CompareTo($mockDatabasePermissionInstance2) | Should-BeGreaterThan 0 } } @@ -277,7 +277,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } } - $mockDatabasePermissionInstance1.CompareTo($null) | Should -BeGreaterThan 0 + $mockDatabasePermissionInstance1.CompareTo($null) | Should-BeGreaterThan 0 } } } @@ -312,7 +312,7 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { } } - $mockDatabasePermissionInstance1.CompareTo($mockDatabasePermissionInstance2) | Should -Be 0 + $mockDatabasePermissionInstance1.CompareTo($mockDatabasePermissionInstance2) | Should-Be 0 } } } @@ -352,9 +352,9 @@ Describe 'DatabasePermission' -Tag 'DatabasePermission' { $mockSortedArray = $mockDatabasePermissionArray | Sort-Object - $mockSortedArray[0].State | Should -Be 'Grant' - $mockSortedArray[1].State | Should -Be 'GrantWithGrant' - $mockSortedArray[2].State | Should -Be 'Deny' + $mockSortedArray[0].State | Should-Be 'Grant' + $mockSortedArray[1].State | Should-Be 'GrantWithGrant' + $mockSortedArray[2].State | Should-Be 'Deny' } } } diff --git a/tests/Unit/Classes/ServerPermission.Tests.ps1 b/tests/Unit/Classes/ServerPermission.Tests.ps1 index fd144e7af..e61d4f13c 100644 --- a/tests/Unit/Classes/ServerPermission.Tests.ps1 +++ b/tests/Unit/Classes/ServerPermission.Tests.ps1 @@ -55,8 +55,8 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } It 'Should be of the correct type' { - $mockServerPermissionInstance | Should -Not -BeNullOrEmpty - $mockServerPermissionInstance.GetType().Name | Should -Be 'ServerPermission' + $mockServerPermissionInstance | Should-BeTruthy + $mockServerPermissionInstance.GetType().Name | Should-Be 'ServerPermission' } } @@ -73,7 +73,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } It 'Should be able read the values from instance' { - $mockServerPermissionInstance.State | Should -Be 'Grant' + $mockServerPermissionInstance.State | Should-Be 'Grant' $mockServerPermissionInstance.Permission = 'ViewServerState' } } @@ -93,7 +93,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { $databasPermissionInstance2.State = 'Grant' $databasPermissionInstance2.Permission = 'ViewServerState' - $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should -BeTrue + $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should-BeTrue } } } @@ -111,7 +111,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { $databasPermissionInstance2.State = 'Grant' $databasPermissionInstance2.Permission = @('ViewServerState', 'AlterAnyAvailabilityGroup') - $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should -BeTrue + $databasPermissionInstance1 -eq $databasPermissionInstance2 | Should-BeTrue } } } @@ -139,7 +139,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } It 'Should return $false' { - $mockServerPermissionInstance1 -eq $mockServerPermissionInstance2 | Should -BeFalse + $mockServerPermissionInstance1 -eq $mockServerPermissionInstance2 | Should-BeFalse } } @@ -165,7 +165,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } It 'Should return $false' { - $mockServerPermissionInstance1 -eq $mockServerPermissionInstance2 | Should -BeFalse + $mockServerPermissionInstance1 -eq $mockServerPermissionInstance2 | Should-BeFalse } } } @@ -195,7 +195,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { $mockErrorMessage = $mockErrorMessage -replace '\[', '`[' $mockErrorMessage = $mockErrorMessage -replace '\]', '`]' - { $mockServerPermissionInstance1.CompareTo('AnyValue') } | Should -Throw -ExpectedMessage $mockErrorMessage + { $mockServerPermissionInstance1.CompareTo('AnyValue') } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -229,7 +229,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } } - $mockServerPermissionInstance1.CompareTo($mockServerPermissionInstance2) | Should -BeLessThan 0 + $mockServerPermissionInstance1.CompareTo($mockServerPermissionInstance2) | Should-BeLessThan 0 } } } @@ -264,7 +264,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } } - $mockServerPermissionInstance1.CompareTo($mockServerPermissionInstance2) | Should -BeGreaterThan 0 + $mockServerPermissionInstance1.CompareTo($mockServerPermissionInstance2) | Should-BeGreaterThan 0 } } @@ -277,7 +277,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } } - $mockServerPermissionInstance1.CompareTo($null) | Should -BeGreaterThan 0 + $mockServerPermissionInstance1.CompareTo($null) | Should-BeGreaterThan 0 } } } @@ -312,7 +312,7 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { } } - $mockServerPermissionInstance1.CompareTo($mockServerPermissionInstance2) | Should -Be 0 + $mockServerPermissionInstance1.CompareTo($mockServerPermissionInstance2) | Should-Be 0 } } } @@ -352,9 +352,9 @@ Describe 'ServerPermission' -Tag 'ServerPermission' { $mockSortedArray = $mockServerPermissionArray | Sort-Object - $mockSortedArray[0].State | Should -Be 'Grant' - $mockSortedArray[1].State | Should -Be 'GrantWithGrant' - $mockSortedArray[2].State | Should -Be 'Deny' + $mockSortedArray[0].State | Should-Be 'Grant' + $mockSortedArray[1].State | Should-Be 'GrantWithGrant' + $mockSortedArray[2].State | Should-Be 'Deny' } } } diff --git a/tests/Unit/Classes/SqlAudit.Tests.ps1 b/tests/Unit/Classes/SqlAudit.Tests.ps1 index 827a6faa0..1ed763925 100644 --- a/tests/Unit/Classes/SqlAudit.Tests.ps1 +++ b/tests/Unit/Classes/SqlAudit.Tests.ps1 @@ -70,21 +70,21 @@ Describe 'SqlAudit' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlAudit]::new() } | Should -Not -Throw + $null = & ({ [SqlAudit]::new() }) } } It 'Should have a default or empty constructor' { InModuleScope -ScriptBlock { $instance = [SqlAudit]::new() - $instance | Should -Not -BeNullOrEmpty + $instance | Should-BeTruthy } } It 'Should be the correct type' { InModuleScope -ScriptBlock { $instance = [SqlAudit]::new() - $instance.GetType().Name | Should -Be 'SqlAudit' + $instance.GetType().Name | Should-Be 'SqlAudit' } } } @@ -126,13 +126,13 @@ Describe 'SqlAudit\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlAuditInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.Name | Should -Be 'MockAuditName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Credential | Should -BeNullOrEmpty - $currentState.Reasons | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.Name | Should-Be 'MockAuditName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Credential | Should-BeFalsy + $currentState.Reasons | Should-BeFalsy - $currentState.Path | Should -Be 'C:\Temp' + $currentState.Path | Should-Be 'C:\Temp' } } @@ -170,15 +170,15 @@ Describe 'SqlAudit\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlAuditInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.Name | Should -Be 'MockAuditName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Reasons | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.Name | Should-Be 'MockAuditName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Reasons | Should-BeFalsy - $currentState.Credential | Should -BeOfType [System.Management.Automation.PSCredential] - $currentState.Credential.UserName | Should -Be 'MyCredentialUserName' + $currentState.Credential | Should-HaveType ([System.Management.Automation.PSCredential]) + $currentState.Credential.UserName | Should-Be 'MyCredentialUserName' - $currentState.Path | Should -Be 'C:\Temp' + $currentState.Path | Should-Be 'C:\Temp' } } } @@ -220,16 +220,16 @@ Describe 'SqlAudit\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlAuditInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.Name | Should -Be 'MockAuditName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.Name | Should-Be 'MockAuditName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Credential | Should-BeFalsy - $currentState.Path | Should -Be 'C:\Temp' + $currentState.Path | Should-Be 'C:\Temp' - $currentState.Reasons | Should -HaveCount 1 - $currentState.Reasons[0].Code | Should -Be 'SqlAudit:SqlAudit:Path' - $currentState.Reasons[0].Phrase | Should -Be 'The property Path should be "C:\NewFolder", but was "C:\Temp"' + $currentState.Reasons | Should-BeCollection -Count 1 + $currentState.Reasons[0].Code | Should-Be 'SqlAudit:SqlAudit:Path' + $currentState.Reasons[0].Phrase | Should-Be 'The property Path should be "C:\NewFolder", but was "C:\Temp"' } } } @@ -275,7 +275,7 @@ Describe 'SqlAudit\Set()' -Tag 'Set' { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance.Set() - $script:mockMethodModifyCallCount | Should -Be 0 + $script:mockMethodModifyCallCount | Should-Be 0 } } } @@ -302,7 +302,7 @@ Describe 'SqlAudit\Set()' -Tag 'Set' { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance.Set() - $script:mockMethodModifyCallCount | Should -Be 1 + $script:mockMethodModifyCallCount | Should-Be 1 } } } @@ -335,7 +335,7 @@ Describe 'SqlAudit\Test()' -Tag 'Test' { It 'Should return $true' { InModuleScope -ScriptBlock { - $script:mockSqlAuditInstance.Test() | Should -BeTrue + $script:mockSqlAuditInstance.Test() | Should-BeTrue } } } @@ -366,7 +366,7 @@ Describe 'SqlAudit\Test()' -Tag 'Test' { It 'Should return $false' { InModuleScope -ScriptBlock { - $script:mockSqlAuditInstance.Test() | Should -BeFalse + $script:mockSqlAuditInstance.Test() | Should-BeFalse } } } @@ -397,10 +397,10 @@ Describe 'SqlAudit\GetCurrentState()' -Tag 'GetCurrentState' { } ) - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Force | Should -BeFalse - $currentState.Credential | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Force | Should-BeFalsy + $currentState.Credential | Should-BeFalsy } } @@ -419,12 +419,12 @@ Describe 'SqlAudit\GetCurrentState()' -Tag 'GetCurrentState' { } ) - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Force | Should -BeFalse + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Force | Should-BeFalsy - $currentState.Credential | Should -BeOfType [System.Management.Automation.PSCredential] - $currentState.Credential.UserName | Should -Be 'MyCredentialUserName' + $currentState.Credential | Should-HaveType ([System.Management.Automation.PSCredential]) + $currentState.Credential.UserName | Should-Be 'MyCredentialUserName' } } } @@ -481,23 +481,23 @@ Describe 'SqlAudit\GetCurrentState()' -Tag 'GetCurrentState' { } ) - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Force | Should -BeFalse - $currentState.Credential | Should -BeNullOrEmpty - - $currentState.LogType | Should -BeNullOrEmpty - $currentState.Path | Should -Be 'C:\Temp' - $currentState.AuditFilter | Should -Be '([server_principal_name] like ''%ADMINISTRATOR'')' - $currentState.MaximumFiles | Should -Be 2 - $currentState.MaximumFileSize | Should -Be 2 - $currentState.MaximumFileSizeUnit | Should -Be 'Megabyte' - $currentState.MaximumRolloverFiles | Should -Be 2 - $currentState.ReserveDiskSpace | Should -BeTrue - $currentState.OnFailure | Should -Be 'Continue' - $currentState.QueueDelay | Should -Be 1000 - $currentState.AuditGuid | Should -Be '06962963-ddd1-4a6b-86d6-0ef8d99b8e7b' - $currentState.Enabled | Should -BeTrue + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Force | Should-BeFalsy + $currentState.Credential | Should-BeFalsy + + $currentState.LogType | Should-BeFalsy + $currentState.Path | Should-Be 'C:\Temp' + $currentState.AuditFilter | Should-Be '([server_principal_name] like ''%ADMINISTRATOR'')' + $currentState.MaximumFiles | Should-Be 2 + $currentState.MaximumFileSize | Should-Be 2 + $currentState.MaximumFileSizeUnit | Should-Be 'Megabyte' + $currentState.MaximumRolloverFiles | Should-Be 2 + $currentState.ReserveDiskSpace | Should-BeTrue + $currentState.OnFailure | Should-Be 'Continue' + $currentState.QueueDelay | Should-Be 1000 + $currentState.AuditGuid | Should-Be '06962963-ddd1-4a6b-86d6-0ef8d99b8e7b' + $currentState.Enabled | Should-BeTrue } } } @@ -546,23 +546,23 @@ Describe 'SqlAudit\GetCurrentState()' -Tag 'GetCurrentState' { } ) - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Force | Should -BeFalse - $currentState.Credential | Should -BeNullOrEmpty - - $currentState.LogType | Should -Be 'SecurityLog' - $currentState.Path | Should -BeNullOrEmpty - $currentState.AuditFilter | Should -Be '([server_principal_name] like ''%ADMINISTRATOR'')' - $currentState.MaximumFiles | Should -Be 0 - $currentState.MaximumFileSize | Should -Be 0 - $currentState.MaximumFileSizeUnit | Should -BeNullOrEmpty - $currentState.MaximumRolloverFiles | Should -Be 0 - $currentState.ReserveDiskSpace | Should -BeNullOrEmpty - $currentState.OnFailure | Should -Be 'Continue' - $currentState.QueueDelay | Should -Be 1000 - $currentState.AuditGuid | Should -Be '06962963-ddd1-4a6b-86d6-0ef8d99b8e7b' - $currentState.Enabled | Should -BeTrue + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Force | Should-BeFalsy + $currentState.Credential | Should-BeFalsy + + $currentState.LogType | Should-Be 'SecurityLog' + $currentState.Path | Should-BeFalsy + $currentState.AuditFilter | Should-Be '([server_principal_name] like ''%ADMINISTRATOR'')' + $currentState.MaximumFiles | Should-Be 0 + $currentState.MaximumFileSize | Should-Be 0 + $currentState.MaximumFileSizeUnit | Should-BeFalsy + $currentState.MaximumRolloverFiles | Should-Be 0 + $currentState.ReserveDiskSpace | Should-BeFalsy + $currentState.OnFailure | Should-Be 'Continue' + $currentState.QueueDelay | Should-Be 1000 + $currentState.AuditGuid | Should-Be '06962963-ddd1-4a6b-86d6-0ef8d99b8e7b' + $currentState.Enabled | Should-BeTrue } } } @@ -600,7 +600,7 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Remove-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-SqlDscAudit -Exactly -Scope It -Times 1 } } } @@ -639,7 +639,7 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName New-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-SqlDscAudit -Exactly -Scope It -Times 1 } } @@ -673,8 +673,8 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName New-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Enable-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Enable-SqlDscAudit -Exactly -Scope It -Times 1 } } } @@ -709,8 +709,8 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName New-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disable-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disable-SqlDscAudit -Exactly -Scope It -Times 1 } } } @@ -745,7 +745,7 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { Enabled = $false } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -786,8 +786,8 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Get-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Enable-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Enable-SqlDscAudit -Exactly -Scope It -Times 1 } } } @@ -827,8 +827,8 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Get-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disable-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disable-SqlDscAudit -Exactly -Scope It -Times 1 } } } @@ -897,10 +897,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Get-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Set-SqlDscAudit -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-SqlDscAudit -Exactly -ParameterFilter { $PesterBoundParameters.$MockPropertyName -eq $MockExpectedValue - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -941,10 +941,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Get-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Set-SqlDscAudit -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-SqlDscAudit -Exactly -ParameterFilter { $MaximumFileSize -eq 20 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -985,10 +985,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Get-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Set-SqlDscAudit -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-SqlDscAudit -Exactly -ParameterFilter { $MaximumFileSizeUnit -eq 'Megabyte' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1029,10 +1029,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Get-SqlDscAudit -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Set-SqlDscAudit -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscAudit -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-SqlDscAudit -Exactly -ParameterFilter { $ReserveDiskSpace -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1080,7 +1080,7 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { MaximumFiles = 20 } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1134,9 +1134,9 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Remove-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-SqlDscAudit -Exactly -Scope It -Times 1 - $script:mockMethodCreateAuditCallCount | Should -Be 1 + $script:mockMethodCreateAuditCallCount | Should-Be 1 } } } @@ -1190,9 +1190,9 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { } ) - Should -Invoke -CommandName Remove-SqlDscAudit -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-SqlDscAudit -Exactly -Scope It -Times 1 - $script:mockMethodCreateAuditCallCount | Should -Be 1 + $script:mockMethodCreateAuditCallCount | Should-Be 1 } } } @@ -1249,11 +1249,11 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { Path = 'C:\Temp' } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Remove-SqlDscAudit -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Remove-SqlDscAudit -Exactly -Scope It -Times 0 - $script:mockMethodCreateAuditCallCount | Should -Be 0 + $script:mockMethodCreateAuditCallCount | Should-Be 0 } } } @@ -1282,7 +1282,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { $mockErrorMessage += ' (Parameter ''Path'')' - { $script:mockSqlAuditInstance.Get() } | Should -Throw -ExpectedMessage $mockErrorMessage + { $script:mockSqlAuditInstance.Get() } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -1292,7 +1292,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { $mockErrorMessage += ' (Parameter ''Path'')' - { $script:mockSqlAuditInstance.Set() } | Should -Throw -ExpectedMessage $mockErrorMessage + { $script:mockSqlAuditInstance.Set() } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -1302,7 +1302,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { $mockErrorMessage += ' (Parameter ''Path'')' - { $script:mockSqlAuditInstance.Test() } | Should -Throw -ExpectedMessage $mockErrorMessage + { $script:mockSqlAuditInstance.Test() } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1333,7 +1333,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { MaximumRolloverFiles = 2 } ) - } | Should -Throw -ExpectedMessage '*DRC0010*' + } | Should-Throw -ExceptionMessage '*DRC0010*' } } } @@ -1376,7 +1376,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { $MockPropertyName = 'AnyValue' } ) - } | Should -Throw -ExpectedMessage '*DRC0010*' + } | Should-Throw -ExceptionMessage '*DRC0010*' } } } @@ -1411,7 +1411,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { $MockPropertyName = 'AnyValue' } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1440,7 +1440,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { MaximumFileSizeUnit = 'Megabyte' } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1481,7 +1481,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { QueueDelay = $MockQueueDelayValue } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1509,7 +1509,7 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { ReserveDiskSpace = $true } ) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 b/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 index cc7d20ed7..41188b023 100644 --- a/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 +++ b/tests/Unit/Classes/SqlDatabasePermission.Tests.ps1 @@ -70,21 +70,21 @@ Describe 'SqlDatabasePermission' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlDatabasePermission]::new() } | Should -Not -Throw + $null = & ({ [SqlDatabasePermission]::new() }) } } It 'Should have a default or empty constructor' { InModuleScope -ScriptBlock { $instance = [SqlDatabasePermission]::new() - $instance | Should -Not -BeNullOrEmpty + $instance | Should-BeTruthy } } It 'Should be the correct type' { InModuleScope -ScriptBlock { $instance = [SqlDatabasePermission]::new() - $instance.GetType().Name | Should -Be 'SqlDatabasePermission' + $instance.GetType().Name | Should-Be 'SqlDatabasePermission' } } } @@ -148,17 +148,17 @@ Describe 'SqlDatabasePermission\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlDatabasePermissionInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.DatabaseName | Should -Be 'MockDatabaseName' - $currentState.Name | Should -Be 'MockUserName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Credential | Should -BeNullOrEmpty - $currentState.Reasons | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.DatabaseName | Should-Be 'MockDatabaseName' + $currentState.Name | Should-Be 'MockUserName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Credential | Should-BeFalsy + $currentState.Reasons | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' - $currentState.Permission[0].State | Should -Be 'Grant' - $currentState.Permission[0].Permission | Should -Be 'Connect' + $currentState.Permission[0].State | Should-Be 'Grant' + $currentState.Permission[0].Permission | Should-Be 'Connect' } } } @@ -224,21 +224,21 @@ Describe 'SqlDatabasePermission\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlDatabasePermissionInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.DatabaseName | Should -Be 'MockDatabaseName' - $currentState.Name | Should -Be 'MockUserName' - $currentState.ServerName | Should -Be (Get-ComputerName) + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.DatabaseName | Should-Be 'MockDatabaseName' + $currentState.Name | Should-Be 'MockUserName' + $currentState.ServerName | Should-Be (Get-ComputerName) - $currentState.Credential | Should -BeOfType [System.Management.Automation.PSCredential] + $currentState.Credential | Should-HaveType ([System.Management.Automation.PSCredential]) - $currentState.Credential.UserName | Should -Be 'MyCredentialUserName' + $currentState.Credential.UserName | Should-Be 'MyCredentialUserName' - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' - $currentState.Permission[0].State | Should -Be 'Grant' - $currentState.Permission[0].Permission | Should -Be 'Connect' + $currentState.Permission[0].State | Should-Be 'Grant' + $currentState.Permission[0].Permission | Should-Be 'Connect' - $currentState.Reasons | Should -BeNullOrEmpty + $currentState.Reasons | Should-BeFalsy } } } @@ -301,21 +301,21 @@ Describe 'SqlDatabasePermission\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlDatabasePermissionInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.DatabaseName | Should -Be 'MockDatabaseName' - $currentState.Name | Should -Be 'MockUserName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.DatabaseName | Should-Be 'MockDatabaseName' + $currentState.Name | Should-Be 'MockUserName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' - $currentState.Permission[0].State | Should -Be 'Grant' - $currentState.Permission[0].Permission | Should -Contain 'Connect' - $currentState.Permission[0].Permission | Should -Contain 'Update' + $currentState.Permission[0].State | Should-Be 'Grant' + $currentState.Permission[0].Permission | Should-ContainCollection 'Connect' + $currentState.Permission[0].Permission | Should-ContainCollection 'Update' - $currentState.Reasons | Should -HaveCount 1 - $currentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' - $currentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["Connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["Connect","Update"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $currentState.Reasons | Should-BeCollection -Count 1 + $currentState.Reasons[0].Code | Should-Be 'SqlDatabasePermission:SqlDatabasePermission:Permission' + $currentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["Connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["Connect","Update"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } } } @@ -348,28 +348,28 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy } } @@ -387,30 +387,30 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeOfType [System.Management.Automation.PSCredential] + $currentState.Credential | Should-HaveType ([System.Management.Automation.PSCredential]) - $currentState.Credential.UserName | Should -Be 'MyCredentialUserName' + $currentState.Credential.UserName | Should-Be 'MyCredentialUserName' - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy } } } @@ -463,30 +463,30 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy } } } @@ -539,29 +539,29 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'Select' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'Select' } } } @@ -619,33 +619,33 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'Select' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'Select' - $currentState.PermissionToInclude | Should -HaveCount 1 - $currentState.PermissionToInclude[0].State | Should -Be 'Grant' - $currentState.PermissionToInclude[0].Permission | Should -Be 'Update' + $currentState.PermissionToInclude | Should-BeCollection -Count 1 + $currentState.PermissionToInclude[0].State | Should-Be 'Grant' + $currentState.PermissionToInclude[0].Permission | Should-Be 'Update' } } } @@ -702,33 +702,33 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'Select' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'Select' - $currentState.PermissionToInclude | Should -HaveCount 1 - $currentState.PermissionToInclude[0].State | Should -Be 'Grant' - $currentState.PermissionToInclude[0].Permission | Should -BeNullOrEmpty + $currentState.PermissionToInclude | Should-BeCollection -Count 1 + $currentState.PermissionToInclude[0].State | Should-Be 'Grant' + $currentState.PermissionToInclude[0].Permission | Should-BeFalsy } } } @@ -787,33 +787,33 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'Select' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'Select' - $currentState.PermissionToExclude | Should -HaveCount 1 - $currentState.PermissionToExclude[0].State | Should -Be 'Grant' - $currentState.PermissionToExclude[0].Permission | Should -Be 'Alter' + $currentState.PermissionToExclude | Should-BeCollection -Count 1 + $currentState.PermissionToExclude[0].State | Should-Be 'Grant' + $currentState.PermissionToExclude[0].Permission | Should-Be 'Alter' } } } @@ -870,33 +870,33 @@ Describe 'SqlDatabasePermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'DatabasePermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'DatabasePermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'Connect' - $grantState.Permission | Should -Contain 'Update' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'Connect' + $grantState.Permission | Should-ContainCollection 'Update' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'Select' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'Select' - $currentState.PermissionToExclude | Should -HaveCount 1 - $currentState.PermissionToExclude[0].State | Should -Be 'Grant' - $currentState.PermissionToExclude[0].Permission | Should -BeNullOrEmpty + $currentState.PermissionToExclude | Should-BeCollection -Count 1 + $currentState.PermissionToExclude[0].State | Should-Be 'Grant' + $currentState.PermissionToExclude[0].Permission | Should-BeFalsy } } } @@ -953,7 +953,7 @@ Describe 'SqlDatabasePermission\Set()' -Tag 'Set' { InModuleScope -ScriptBlock { $script:mockSqlDatabasePermissionInstance.Set() - $script:mockMethodModifyCallCount | Should -Be 0 + $script:mockMethodModifyCallCount | Should-Be 0 } } } @@ -987,7 +987,7 @@ Describe 'SqlDatabasePermission\Set()' -Tag 'Set' { InModuleScope -ScriptBlock { $script:mockSqlDatabasePermissionInstance.Set() - $script:mockMethodModifyCallCount | Should -Be 1 + $script:mockMethodModifyCallCount | Should-Be 1 } } } @@ -1031,7 +1031,7 @@ Describe 'SqlDatabasePermission\Test()' -Tag 'Test' { It 'Should return $true' { InModuleScope -ScriptBlock { - $script:mockSqlDatabasePermissionInstance.Test() | Should -BeTrue + $script:mockSqlDatabasePermissionInstance.Test() | Should-BeTrue } } } @@ -1063,7 +1063,7 @@ Describe 'SqlDatabasePermission\Test()' -Tag 'Test' { It 'Should return $false' { InModuleScope -ScriptBlock { - $script:mockSqlDatabasePermissionInstance.Test() | Should -BeFalse + $script:mockSqlDatabasePermissionInstance.Test() | Should-BeFalse } } } @@ -1114,7 +1114,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { $mockSqlDatabasePermissionInstance.Modify(@{ Permission = [DatabasePermission[]] @() }) - } | Should -Throw -ExpectedMessage $mockErrorRecord + } | Should-Throw -ExceptionMessage $mockErrorRecord } } } @@ -1178,7 +1178,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlDatabasePermissionInstance.Modify(@{ Permission = [DatabasePermission[]] @( [DatabasePermission] @{ @@ -1195,18 +1195,18 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Grants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.Connect -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # GrantWithGrants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.Update -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1268,7 +1268,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlDatabasePermissionInstance.Modify(@{ Permission = [DatabasePermission[]] @( [DatabasePermission] @{ @@ -1285,28 +1285,28 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Revoking Grants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.Alter -eq $true -and $Permission.Select -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Revoking GrantWithGrants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.Delete -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Revoking Denies - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.CreateDatabase -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Adding new Grant - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.Connect -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1370,7 +1370,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlDatabasePermissionInstance.Modify(@{ PermissionToInclude = [DatabasePermission[]] @( [DatabasePermission] @{ @@ -1387,18 +1387,18 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Grants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.Connect -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # GrantWithGrants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.Update -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1462,7 +1462,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlDatabasePermissionInstance.Modify(@{ PermissionToExclude = [DatabasePermission[]] @( [DatabasePermission] @{ @@ -1479,18 +1479,18 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Revoking Grants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.Connect -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Revoking GrantWithGrants - Should -Invoke -CommandName Set-SqlDscDatabasePermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscDatabasePermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.Update -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1584,7 +1584,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorRecord + } | Should-Throw -ExceptionMessage $mockErrorRecord } } } @@ -1677,7 +1677,7 @@ Describe 'SqlDatabasePermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorRecord + } | Should-Throw -ExceptionMessage $mockErrorRecord } } } @@ -1705,7 +1705,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { Permission = [DatabasePermission[]] @([DatabasePermission] @{}) PermissionToInclude = [DatabasePermission[]] @([DatabasePermission] @{}) }) - } | Should -Throw -ExpectedMessage '*DRC0010*' + } | Should-Throw -ExceptionMessage '*DRC0010*' } } } @@ -1718,7 +1718,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { Permission = [DatabasePermission[]] @([DatabasePermission] @{}) PermissionToExclude = [DatabasePermission[]] @([DatabasePermission] @{}) }) - } | Should -Throw -ExpectedMessage '*DRC0010*' + } | Should-Throw -ExceptionMessage '*DRC0010*' } } } @@ -1733,7 +1733,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { InModuleScope -ScriptBlock { { $mockSqlDatabasePermissionInstance.AssertProperties(@{}) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1766,7 +1766,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1790,7 +1790,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1825,7 +1825,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1862,7 +1862,7 @@ Describe 'SqlDatabasePermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/Classes/SqlPermission.Tests.ps1 b/tests/Unit/Classes/SqlPermission.Tests.ps1 index 968e4d8d3..27b32110f 100644 --- a/tests/Unit/Classes/SqlPermission.Tests.ps1 +++ b/tests/Unit/Classes/SqlPermission.Tests.ps1 @@ -70,21 +70,21 @@ Describe 'SqlPermission' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlPermission]::new() } | Should -Not -Throw + $null = & ({ [SqlPermission]::new() }) } } It 'Should have a default or empty constructor' { InModuleScope -ScriptBlock { $instance = [SqlPermission]::new() - $instance | Should -Not -BeNullOrEmpty + $instance | Should-BeTruthy } } It 'Should be the correct type' { InModuleScope -ScriptBlock { $instance = [SqlPermission]::new() - $instance.GetType().Name | Should -Be 'SqlPermission' + $instance.GetType().Name | Should-Be 'SqlPermission' } } } @@ -147,16 +147,16 @@ Describe 'SqlPermission\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlPermissionInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.Name | Should -Be 'MockUserName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Credential | Should -BeNullOrEmpty - $currentState.Reasons | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.Name | Should-Be 'MockUserName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Credential | Should-BeFalsy + $currentState.Reasons | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' - $currentState.Permission[0].State | Should -Be 'Grant' - $currentState.Permission[0].Permission | Should -Be 'ConnectSql' + $currentState.Permission[0].State | Should-Be 'Grant' + $currentState.Permission[0].Permission | Should-Be 'ConnectSql' } } } @@ -221,20 +221,20 @@ Describe 'SqlPermission\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlPermissionInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.Name | Should -Be 'MockUserName' - $currentState.ServerName | Should -Be (Get-ComputerName) + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.Name | Should-Be 'MockUserName' + $currentState.ServerName | Should-Be (Get-ComputerName) - $currentState.Credential | Should -BeOfType [System.Management.Automation.PSCredential] + $currentState.Credential | Should-HaveType ([System.Management.Automation.PSCredential]) - $currentState.Credential.UserName | Should -Be 'MyCredentialUserName' + $currentState.Credential.UserName | Should-Be 'MyCredentialUserName' - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' - $currentState.Permission[0].State | Should -Be 'Grant' - $currentState.Permission[0].Permission | Should -Be 'ConnectSql' + $currentState.Permission[0].State | Should-Be 'Grant' + $currentState.Permission[0].Permission | Should-Be 'ConnectSql' - $currentState.Reasons | Should -BeNullOrEmpty + $currentState.Reasons | Should-BeFalsy } } } @@ -296,20 +296,20 @@ Describe 'SqlPermission\Get()' -Tag 'Get' { InModuleScope -ScriptBlock { $currentState = $script:mockSqlPermissionInstance.Get() - $currentState.InstanceName | Should -Be 'NamedInstance' - $currentState.Name | Should -Be 'MockUserName' - $currentState.ServerName | Should -Be (Get-ComputerName) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.InstanceName | Should-Be 'NamedInstance' + $currentState.Name | Should-Be 'MockUserName' + $currentState.ServerName | Should-Be (Get-ComputerName) + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' - $currentState.Permission[0].State | Should -Be 'Grant' - $currentState.Permission[0].Permission | Should -Contain 'ConnectSql' - $currentState.Permission[0].Permission | Should -Contain 'AlterAnyEndpoint' + $currentState.Permission[0].State | Should-Be 'Grant' + $currentState.Permission[0].Permission | Should-ContainCollection 'ConnectSql' + $currentState.Permission[0].Permission | Should-ContainCollection 'AlterAnyEndpoint' - $currentState.Reasons | Should -HaveCount 1 - $currentState.Reasons[0].Code | Should -Be 'SqlPermission:SqlPermission:Permission' - $currentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["ConnectSql","AlterAnyEndpoint"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' + $currentState.Reasons | Should-BeCollection -Count 1 + $currentState.Reasons[0].Code | Should-Be 'SqlPermission:SqlPermission:Permission' + $currentState.Reasons[0].Phrase | Should-Be 'The property Permission should be [{"State":"Grant","Permission":["ConnectSql"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["ConnectSql","AlterAnyEndpoint"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]' } } } @@ -340,28 +340,28 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy } } @@ -378,30 +378,30 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeOfType [System.Management.Automation.PSCredential] + $currentState.Credential | Should-HaveType ([System.Management.Automation.PSCredential]) - $currentState.Credential.UserName | Should -Be 'MyCredentialUserName' + $currentState.Credential.UserName | Should-Be 'MyCredentialUserName' - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -BeNullOrEmpty + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeFalsy $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy } } } @@ -452,30 +452,30 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -HaveCount 2 - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-BeCollection -Count 2 + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -BeNullOrEmpty + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-BeFalsy } } } @@ -526,29 +526,29 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'ViewServerState' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'ViewServerState' } } } @@ -604,33 +604,33 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'ViewServerState' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'ViewServerState' - $currentState.PermissionToInclude | Should -HaveCount 1 - $currentState.PermissionToInclude[0].State | Should -Be 'Grant' - $currentState.PermissionToInclude[0].Permission | Should -Be 'AlterAnyEndpoint' + $currentState.PermissionToInclude | Should-BeCollection -Count 1 + $currentState.PermissionToInclude[0].State | Should-Be 'Grant' + $currentState.PermissionToInclude[0].Permission | Should-Be 'AlterAnyEndpoint' } } } @@ -685,33 +685,33 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'ViewServerState' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'ViewServerState' - $currentState.PermissionToInclude | Should -HaveCount 1 - $currentState.PermissionToInclude[0].State | Should -Be 'Grant' - $currentState.PermissionToInclude[0].Permission | Should -BeNullOrEmpty + $currentState.PermissionToInclude | Should-BeCollection -Count 1 + $currentState.PermissionToInclude[0].State | Should-Be 'Grant' + $currentState.PermissionToInclude[0].Permission | Should-BeFalsy } } } @@ -768,33 +768,33 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'ViewServerState' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'ViewServerState' - $currentState.PermissionToExclude | Should -HaveCount 1 - $currentState.PermissionToExclude[0].State | Should -Be 'Grant' - $currentState.PermissionToExclude[0].Permission | Should -Be 'AlterAnyAvailabilityGroup' + $currentState.PermissionToExclude | Should-BeCollection -Count 1 + $currentState.PermissionToExclude[0].State | Should-Be 'Grant' + $currentState.PermissionToExclude[0].Permission | Should-Be 'AlterAnyAvailabilityGroup' } } } @@ -849,33 +849,33 @@ Describe 'SqlPermission\GetCurrentState()' -Tag 'GetCurrentState' { InstanceName = 'NamedInstance' }) - $currentState.Credential | Should -BeNullOrEmpty + $currentState.Credential | Should-BeFalsy - $currentState.Permission.GetType().FullName | Should -Be 'ServerPermission[]' - $currentState.Permission | Should -HaveCount 3 + $currentState.Permission.GetType().FullName | Should-Be 'ServerPermission[]' + $currentState.Permission | Should-BeCollection -Count 3 $grantState = $currentState.Permission.Where({ $_.State -eq 'Grant' }) - $grantState | Should -Not -BeNullOrEmpty - $grantState.State | Should -Be 'Grant' - $grantState.Permission | Should -Contain 'ConnectSql' - $grantState.Permission | Should -Contain 'AlterAnyEndpoint' + $grantState | Should-BeTruthy + $grantState.State | Should-Be 'Grant' + $grantState.Permission | Should-ContainCollection 'ConnectSql' + $grantState.Permission | Should-ContainCollection 'AlterAnyEndpoint' $grantWithGrantState = $currentState.Permission.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantState | Should -Not -BeNullOrEmpty - $grantWithGrantState.State | Should -Be 'GrantWithGrant' - $grantWithGrantState.Permission | Should -BeNullOrEmpty + $grantWithGrantState | Should-BeTruthy + $grantWithGrantState.State | Should-Be 'GrantWithGrant' + $grantWithGrantState.Permission | Should-BeFalsy $denyState = $currentState.Permission.Where({ $_.State -eq 'Deny' }) - $denyState | Should -Not -BeNullOrEmpty - $denyState.State | Should -Be 'Deny' - $denyState.Permission | Should -Contain 'ViewServerState' + $denyState | Should-BeTruthy + $denyState.State | Should-Be 'Deny' + $denyState.Permission | Should-ContainCollection 'ViewServerState' - $currentState.PermissionToExclude | Should -HaveCount 1 - $currentState.PermissionToExclude[0].State | Should -Be 'Grant' - $currentState.PermissionToExclude[0].Permission | Should -BeNullOrEmpty + $currentState.PermissionToExclude | Should-BeCollection -Count 1 + $currentState.PermissionToExclude[0].State | Should-Be 'Grant' + $currentState.PermissionToExclude[0].Permission | Should-BeFalsy } } } @@ -931,7 +931,7 @@ Describe 'SqlPermission\Set()' -Tag 'Set' { InModuleScope -ScriptBlock { $script:mockSqlPermissionInstance.Set() - $script:mockMethodModifyCallCount | Should -Be 0 + $script:mockMethodModifyCallCount | Should-Be 0 } } } @@ -965,7 +965,7 @@ Describe 'SqlPermission\Set()' -Tag 'Set' { InModuleScope -ScriptBlock { $script:mockSqlPermissionInstance.Set() - $script:mockMethodModifyCallCount | Should -Be 1 + $script:mockMethodModifyCallCount | Should-Be 1 } } } @@ -1008,7 +1008,7 @@ Describe 'SqlPermission\Test()' -Tag 'Test' { It 'Should return $true' { InModuleScope -ScriptBlock { - $script:mockSqlPermissionInstance.Test() | Should -BeTrue + $script:mockSqlPermissionInstance.Test() | Should-BeTrue } } } @@ -1040,7 +1040,7 @@ Describe 'SqlPermission\Test()' -Tag 'Test' { It 'Should return $false' { InModuleScope -ScriptBlock { - $script:mockSqlPermissionInstance.Test() | Should -BeFalse + $script:mockSqlPermissionInstance.Test() | Should-BeFalse } } } @@ -1089,7 +1089,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { $mockSqlPermissionInstance.Modify(@{ Permission = [ServerPermission[]] @() }) - } | Should -Throw -ExpectedMessage $mockErrorRecord + } | Should-Throw -ExceptionMessage $mockErrorRecord } } } @@ -1152,7 +1152,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlPermissionInstance.Modify(@{ Permission = [ServerPermission[]] @( [ServerPermission] @{ @@ -1169,18 +1169,18 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Grants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.ConnectSql -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # GrantWithGrants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.AlterAnyEndpoint -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1241,7 +1241,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlPermissionInstance.Modify(@{ Permission = [ServerPermission[]] @( [ServerPermission] @{ @@ -1258,28 +1258,28 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Revoking Grants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.AlterAnyAvailabilityGroup -eq $true -and $Permission.ViewServerState -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Revoking GrantWithGrants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.ControlServer -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Revoking Denies - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.CreateEndpoint -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Adding new Grant - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.ConnectSql -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1342,7 +1342,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlPermissionInstance.Modify(@{ PermissionToInclude = [ServerPermission[]] @( [ServerPermission] @{ @@ -1359,18 +1359,18 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Grants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.ConnectSql -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # GrantWithGrants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Grant' -and $Permission.AlterAnyEndpoint -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1433,7 +1433,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { It 'Should call the correct mock with the correct parameter values' { InModuleScope -ScriptBlock { - { + $null = & ({ $mockSqlPermissionInstance.Modify(@{ PermissionToExclude = [ServerPermission[]] @( [ServerPermission] @{ @@ -1450,18 +1450,18 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Not -Throw + }) } # Revoking Grants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.ConnectSql -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 # Revoking GrantWithGrants - Should -Invoke -CommandName Set-SqlDscServerPermission -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscServerPermission -Exactly -ParameterFilter { $State -eq 'Revoke' -and $Permission.AlterAnyEndpoint -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1553,7 +1553,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorRecord + } | Should-Throw -ExceptionMessage $mockErrorRecord } } } @@ -1644,7 +1644,7 @@ Describe 'SqlPermission\Modify()' -Tag 'Modify' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorRecord + } | Should-Throw -ExceptionMessage $mockErrorRecord } } } @@ -1672,7 +1672,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { Permission = [ServerPermission[]] @([ServerPermission] @{}) PermissionToInclude = [ServerPermission[]] @([ServerPermission] @{}) }) - } | Should -Throw -ExpectedMessage '*DRC0010*' + } | Should-Throw -ExceptionMessage '*DRC0010*' } } } @@ -1685,7 +1685,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { Permission = [ServerPermission[]] @([ServerPermission] @{}) PermissionToExclude = [ServerPermission[]] @([ServerPermission] @{}) }) - } | Should -Throw -ExpectedMessage '*DRC0010*' + } | Should-Throw -ExceptionMessage '*DRC0010*' } } } @@ -1700,7 +1700,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { InModuleScope -ScriptBlock { { $mockSqlPermissionInstance.AssertProperties(@{}) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1733,7 +1733,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1757,7 +1757,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1792,7 +1792,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -1829,7 +1829,7 @@ Describe 'SqlPermission\AssertProperties()' -Tag 'AssertProperties' { } ) }) - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/Classes/SqlReason.Tests.ps1 b/tests/Unit/Classes/SqlReason.Tests.ps1 index 3a15cc492..aad91d1de 100644 --- a/tests/Unit/Classes/SqlReason.Tests.ps1 +++ b/tests/Unit/Classes/SqlReason.Tests.ps1 @@ -55,8 +55,8 @@ Describe 'SqlReason' -Tag 'SqlReason' { } It 'Should be of the correct type' { - $mockSqlReasonInstance | Should -Not -BeNullOrEmpty - $mockSqlReasonInstance.GetType().Name | Should -Be 'SqlReason' + $mockSqlReasonInstance | Should-BeTruthy + $mockSqlReasonInstance.GetType().Name | Should-Be 'SqlReason' } } @@ -73,8 +73,8 @@ Describe 'SqlReason' -Tag 'SqlReason' { } It 'Should be able read the values from instance' { - $mockSqlReasonInstance.Code | Should -Be 'SqlAudit:SqlAudit:Ensure' - $mockSqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' + $mockSqlReasonInstance.Code | Should-Be 'SqlAudit:SqlAudit:Ensure' + $mockSqlReasonInstance.Phrase | Should-Be 'The property Ensure should be "Present", but was "Absent"' } } } diff --git a/tests/Unit/Classes/SqlResourceBase.Tests.ps1 b/tests/Unit/Classes/SqlResourceBase.Tests.ps1 index c2b26827e..307b0b0f8 100644 --- a/tests/Unit/Classes/SqlResourceBase.Tests.ps1 +++ b/tests/Unit/Classes/SqlResourceBase.Tests.ps1 @@ -53,22 +53,22 @@ Describe 'SqlResourceBase' { Context 'When class is instantiated' { It 'Should not throw an exception' { InModuleScope -ScriptBlock { - { [SqlResourceBase]::new() } | Should -Not -Throw + $null = & ({ [SqlResourceBase]::new() }) } } It 'Should have a default constructor' { InModuleScope -ScriptBlock { $instance = [SqlResourceBase]::new() - $instance | Should -Not -BeNullOrEmpty - $instance.SqlServerObject | Should -BeNullOrEmpty + $instance | Should-BeTruthy + $instance.SqlServerObject | Should-BeFalsy } } It 'Should be the correct type' { InModuleScope -ScriptBlock { $instance = [SqlResourceBase]::new() - $instance.GetType().Name | Should -Be 'SqlResourceBase' + $instance.GetType().Name | Should-Be 'SqlResourceBase' } } } @@ -89,9 +89,9 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' { It 'Should call the correct mock' { $result = $mockSqlResourceBaseInstance.GetServerObject() - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Server' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Server' - Should -Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Scope It -Times 1 } Context 'When property Credential is used' { @@ -109,11 +109,11 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' { It 'Should call the correct mock' { $result = $mockSqlResourceBaseInstance.GetServerObject() - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Server' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Server' - Should -Invoke -CommandName Connect-SqlDscDatabaseEngine -ParameterFilter { + Should-Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -ParameterFilter { $PesterBoundParameters.Keys -contains 'Credential' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -130,9 +130,9 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' { It 'Should call the correct mock' { $result = $mockSqlResourceBaseInstance.GetServerObject() - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Server' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Server' - Should -Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Scope It -Times 0 } } } diff --git a/tests/Unit/Classes/StartupParameters.Tests.ps1 b/tests/Unit/Classes/StartupParameters.Tests.ps1 index 8084e701b..f321e9168 100644 --- a/tests/Unit/Classes/StartupParameters.Tests.ps1 +++ b/tests/Unit/Classes/StartupParameters.Tests.ps1 @@ -55,7 +55,7 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { } It 'Should be of the correct type' { - $mockStartupParametersInstance.GetType().Name | Should -Be 'StartupParameters' + $mockStartupParametersInstance.GetType().Name | Should-Be 'StartupParameters' } } @@ -75,13 +75,13 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { } It 'Should be able read the values from instance' { - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy - $mockStartupParametersInstance.DataFilePath | Should -Be $TestDrive - $mockStartupParametersInstance.LogFilePath | Should -Be $TestDrive - $mockStartupParametersInstance.ErrorLogPath | Should -Be $TestDrive - $mockStartupParametersInstance.TraceFlag | Should -Be 4199 - $mockStartupParametersInstance.InternalTraceFlag | Should -Be 8688 + $mockStartupParametersInstance.DataFilePath | Should-Be $TestDrive + $mockStartupParametersInstance.LogFilePath | Should-Be $TestDrive + $mockStartupParametersInstance.ErrorLogPath | Should-Be $TestDrive + $mockStartupParametersInstance.TraceFlag | Should-Be 4199 + $mockStartupParametersInstance.InternalTraceFlag | Should-Be 8688 } } @@ -101,27 +101,27 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { } It 'Should be able read the values from instance' { - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy - $mockStartupParametersInstance.DataFilePath | Should -HaveCount 2 - $mockStartupParametersInstance.DataFilePath | Should -Contain $TestDrive - $mockStartupParametersInstance.DataFilePath | Should -Contain 'C:\Temp' + $mockStartupParametersInstance.DataFilePath | Should-BeCollection -Count 2 + $mockStartupParametersInstance.DataFilePath | Should-ContainCollection $TestDrive + $mockStartupParametersInstance.DataFilePath | Should-ContainCollection 'C:\Temp' - $mockStartupParametersInstance.LogFilePath | Should -HaveCount 2 - $mockStartupParametersInstance.LogFilePath | Should -Contain $TestDrive - $mockStartupParametersInstance.LogFilePath | Should -Contain 'C:\Temp' + $mockStartupParametersInstance.LogFilePath | Should-BeCollection -Count 2 + $mockStartupParametersInstance.LogFilePath | Should-ContainCollection $TestDrive + $mockStartupParametersInstance.LogFilePath | Should-ContainCollection 'C:\Temp' - $mockStartupParametersInstance.ErrorLogPath | Should -HaveCount 2 - $mockStartupParametersInstance.ErrorLogPath | Should -Contain $TestDrive - $mockStartupParametersInstance.ErrorLogPath | Should -Contain 'C:\Temp' + $mockStartupParametersInstance.ErrorLogPath | Should-BeCollection -Count 2 + $mockStartupParametersInstance.ErrorLogPath | Should-ContainCollection $TestDrive + $mockStartupParametersInstance.ErrorLogPath | Should-ContainCollection 'C:\Temp' - $mockStartupParametersInstance.TraceFlag | Should -HaveCount 2 - $mockStartupParametersInstance.TraceFlag | Should -Contain 4199 - $mockStartupParametersInstance.TraceFlag | Should -Contain 3226 + $mockStartupParametersInstance.TraceFlag | Should-BeCollection -Count 2 + $mockStartupParametersInstance.TraceFlag | Should-ContainCollection 4199 + $mockStartupParametersInstance.TraceFlag | Should-ContainCollection 3226 - $mockStartupParametersInstance.InternalTraceFlag | Should -HaveCount 2 - $mockStartupParametersInstance.InternalTraceFlag | Should -Contain 8678 - $mockStartupParametersInstance.InternalTraceFlag | Should -Contain 8688 + $mockStartupParametersInstance.InternalTraceFlag | Should-BeCollection -Count 2 + $mockStartupParametersInstance.InternalTraceFlag | Should-ContainCollection 8678 + $mockStartupParametersInstance.InternalTraceFlag | Should-ContainCollection 8688 } } @@ -134,7 +134,7 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy } It 'Should have the correct value for ' -ForEach @( @@ -151,21 +151,21 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { MockExpectedValue = 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' } ) { - $mockStartupParametersInstance.$MockPropertyName | Should -Be $MockExpectedValue + $mockStartupParametersInstance.$MockPropertyName | Should-Be $MockExpectedValue } It 'Should have the correct value for TraceFlag' { - $mockStartupParametersInstance.TraceFlag | Should -BeNullOrEmpty - $mockStartupParametersInstance.TraceFlag | Should -HaveCount 0 + $mockStartupParametersInstance.TraceFlag | Should-BeFalsy + $mockStartupParametersInstance.TraceFlag | Should-BeCollection -Count 0 } It 'Should have the correct value for InternalTraceFlag' { - $mockStartupParametersInstance.InternalTraceFlag | Should -BeNullOrEmpty - $mockStartupParametersInstance.InternalTraceFlag | Should -HaveCount 0 + $mockStartupParametersInstance.InternalTraceFlag | Should-BeFalsy + $mockStartupParametersInstance.InternalTraceFlag | Should-BeCollection -Count 0 } } - Context 'When there are a single trace flag' { + Context 'When there are a single trace flag passed to constructor' { It 'Should parse the values correctly' { $script:mockStartupParametersInstance = InModuleScope -ScriptBlock { $startupParametersInstance = [StartupParameters]::Parse('-dC:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf;-T4199') @@ -173,7 +173,7 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy } It 'Should have the correct value for ' -ForEach @( @@ -190,12 +190,12 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { MockExpectedValue = 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' } ) { - $mockStartupParametersInstance.$MockPropertyName | Should -Be $MockExpectedValue + $mockStartupParametersInstance.$MockPropertyName | Should-Be $MockExpectedValue } It 'Should have the correct value for TraceFlag' { - $mockStartupParametersInstance.TraceFlag | Should -HaveCount 1 - $mockStartupParametersInstance.TraceFlag | Should -Be 4199 + $mockStartupParametersInstance.TraceFlag | Should-BeCollection -Count 1 + $mockStartupParametersInstance.TraceFlag | Should-Be 4199 } } @@ -207,7 +207,7 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy } It 'Should have the correct value for ' -ForEach @( @@ -224,13 +224,13 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { MockExpectedValue = 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' } ) { - $mockStartupParametersInstance.$MockPropertyName | Should -Be $MockExpectedValue + $mockStartupParametersInstance.$MockPropertyName | Should-Be $MockExpectedValue } It 'Should have the correct value for TraceFlag' { - $mockStartupParametersInstance.TraceFlag | Should -HaveCount 2 - $mockStartupParametersInstance.TraceFlag | Should -Contain 4199 - $mockStartupParametersInstance.TraceFlag | Should -Contain 3226 + $mockStartupParametersInstance.TraceFlag | Should-BeCollection -Count 2 + $mockStartupParametersInstance.TraceFlag | Should-ContainCollection 4199 + $mockStartupParametersInstance.TraceFlag | Should-ContainCollection 3226 } } @@ -242,17 +242,17 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy } # Evaluates that startup parameter '-t' is not also interpreted as '-T'. It 'Should have the correct value for TraceFlag' { - $mockStartupParametersInstance.TraceFlag | Should -HaveCount 0 + $mockStartupParametersInstance.TraceFlag | Should-BeCollection -Count 0 } It 'Should have the correct value for InternalTraceFlag' { - $mockStartupParametersInstance.InternalTraceFlag | Should -HaveCount 1 - $mockStartupParametersInstance.InternalTraceFlag | Should -Be 8688 + $mockStartupParametersInstance.InternalTraceFlag | Should-BeCollection -Count 1 + $mockStartupParametersInstance.InternalTraceFlag | Should-Be 8688 } } @@ -264,13 +264,13 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance | Should -Not -BeNullOrEmpty + $mockStartupParametersInstance | Should-BeTruthy } It 'Should have the correct value for InternalTraceFlag' { - $mockStartupParametersInstance.InternalTraceFlag | Should -HaveCount 2 - $mockStartupParametersInstance.InternalTraceFlag | Should -Contain 8688 - $mockStartupParametersInstance.InternalTraceFlag | Should -Contain 8678 + $mockStartupParametersInstance.InternalTraceFlag | Should-BeCollection -Count 2 + $mockStartupParametersInstance.InternalTraceFlag | Should-ContainCollection 8688 + $mockStartupParametersInstance.InternalTraceFlag | Should-ContainCollection 8678 } } } @@ -292,7 +292,7 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance.ToString() | Should -Be $mockDefaultExpectedValue + $mockStartupParametersInstance.ToString() | Should-Be $mockDefaultExpectedValue } } @@ -309,11 +309,11 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance.ToString() | Should -Be ($mockDefaultExpectedValue + ';-T4199') + $mockStartupParametersInstance.ToString() | Should-Be ($mockDefaultExpectedValue + ';-T4199') } } - Context 'When there are a single trace flag' { + Context 'When there are two trace flags' { It 'Should output the values correctly' { $script:mockStartupParametersInstance = InModuleScope -ScriptBlock { $startupParametersInstance = [StartupParameters]::new() @@ -326,9 +326,9 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance.ToString() | Should -BeLike ($mockDefaultExpectedValue + '*') - $mockStartupParametersInstance.ToString() | Should -MatchExactly ';-T4199' - $mockStartupParametersInstance.ToString() | Should -MatchExactly ';-T3226' + $mockStartupParametersInstance.ToString() | Should-BeLikeString ($mockDefaultExpectedValue + '*') + $mockStartupParametersInstance.ToString() | Should-MatchString -CaseSensitive ';-T4199' + $mockStartupParametersInstance.ToString() | Should-MatchString -CaseSensitive ';-T3226' } } @@ -345,7 +345,7 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance.ToString() | Should -Be ($mockDefaultExpectedValue + ';-t8688') + $mockStartupParametersInstance.ToString() | Should-Be ($mockDefaultExpectedValue + ';-t8688') } } @@ -362,14 +362,14 @@ Describe 'StartupParameters' -Tag 'StartupParameters' { return $startupParametersInstance } - $mockStartupParametersInstance.ToString() | Should -BeLike ($mockDefaultExpectedValue + '*') - $mockStartupParametersInstance.ToString() | Should -MatchExactly ';-t8688' - $mockStartupParametersInstance.ToString() | Should -MatchExactly ';-t8678' + $mockStartupParametersInstance.ToString() | Should-BeLikeString ($mockDefaultExpectedValue + '*') + $mockStartupParametersInstance.ToString() | Should-MatchString -CaseSensitive ';-t8688' + $mockStartupParametersInstance.ToString() | Should-MatchString -CaseSensitive ';-t8678' } It 'Should not have set any ''-T'' parameters' { - $mockStartupParametersInstance.ToString() | Should -Not -MatchExactly ';-T8688' - $mockStartupParametersInstance.ToString() | Should -Not -MatchExactly ';-T8678' + $mockStartupParametersInstance.ToString() | Should-NotMatchString -CaseSensitive ';-T8688' + $mockStartupParametersInstance.ToString() | Should-NotMatchString -CaseSensitive ';-T8678' } } } diff --git a/tests/Unit/DSC_SqlAG.Tests.ps1 b/tests/Unit/DSC_SqlAG.Tests.ps1 index 30f0b4510..9f484762c 100644 --- a/tests/Unit/DSC_SqlAG.Tests.ps1 +++ b/tests/Unit/DSC_SqlAG.Tests.ps1 @@ -247,26 +247,26 @@ Describe 'SqlAG\Get-TargetResource' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.Name | Should -Be 'AbsentAG' - $getTargetResourceResult.ServerName | Should -Be 'Server1' - $getTargetResourceResult.InstanceName | Should -Be 'MSSQLSERVER' - $getTargetResourceResult.Ensure | Should -Be 'Absent' - $getTargetResourceResult.IsActiveNode | Should -BeTrue - $getTargetResourceResult.AutomatedBackupPreference | Should -BeNullOrEmpty - $getTargetResourceResultAvailabilityMode | Should -BeNullOrEmpty - $getTargetResourceResultBackupPriority | Should -BeNullOrEmpty - $getTargetResourceResultConnectionModeInPrimaryRole | Should -BeNullOrEmpty - $getTargetResourceResultConnectionModeInSecondaryRole | Should -BeNullOrEmpty - $getTargetResourceResultFailureConditionLevel | Should -BeNullOrEmpty - $getTargetResourceResultFailoverMode | Should -BeNullOrEmpty - $getTargetResourceResultHealthCheckTimeout | Should -BeNullOrEmpty - $getTargetResourceResultEndpointURL | Should -BeNullOrEmpty - $getTargetResourceResultEndpointPort | Should -BeNullOrEmpty - $getTargetResourceResultEndpointHostName | Should -BeNullOrEmpty - $getTargetResourceResultVersion | Should -BeNullOrEmpty - } - - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + $getTargetResourceResult.Name | Should-Be 'AbsentAG' + $getTargetResourceResult.ServerName | Should-Be 'Server1' + $getTargetResourceResult.InstanceName | Should-Be 'MSSQLSERVER' + $getTargetResourceResult.Ensure | Should-Be 'Absent' + $getTargetResourceResult.IsActiveNode | Should-BeTrue + $getTargetResourceResult.AutomatedBackupPreference | Should-BeFalsy + $getTargetResourceResultAvailabilityMode | Should-BeFalsy + $getTargetResourceResultBackupPriority | Should-BeFalsy + $getTargetResourceResultConnectionModeInPrimaryRole | Should-BeFalsy + $getTargetResourceResultConnectionModeInSecondaryRole | Should-BeFalsy + $getTargetResourceResultFailureConditionLevel | Should-BeFalsy + $getTargetResourceResultFailoverMode | Should-BeFalsy + $getTargetResourceResultHealthCheckTimeout | Should-BeFalsy + $getTargetResourceResultEndpointURL | Should-BeFalsy + $getTargetResourceResultEndpointPort | Should-BeFalsy + $getTargetResourceResultEndpointHostName | Should-BeFalsy + $getTargetResourceResultVersion | Should-BeFalsy + } + + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -282,28 +282,29 @@ Describe 'SqlAG\Get-TargetResource' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.Name | Should -Be 'AG_AllServers' - $getTargetResourceResult.ServerName | Should -Be 'Server1' - $getTargetResourceResult.InstanceName | Should -Be 'MSSQLSERVER' - $getTargetResourceResult.Ensure | Should -Be 'Present' - $getTargetResourceResult.IsActiveNode | Should -Be 'True' - $getTargetResourceResult.AutomatedBackupPreference | Should -Be 'Secondary' - $getTargetResourceResult.AvailabilityMode | Should -Be 'AsynchronousCommit' - $getTargetResourceResult.BackupPriority | Should -Be 50 - $getTargetResourceResult.ConnectionModeInPrimaryRole | Should -Be 'AllowAllConnections' - $getTargetResourceResult.ConnectionModeInSecondaryRole | Should -Be 'AllowNoConnections' - $getTargetResourceResult.FailureConditionLevel | Should -Be 'OnCriticalServerError' - $getTargetResourceResult.FailoverMode | Should -Be 'Manual' - $getTargetResourceResult.HealthCheckTimeout | Should -BeNullOrEmpty - $getTargetResourceResult.EndpointURL | Should -Be 'TCP://Server1:5022' - $getTargetResourceResult.EndpointPort | Should -Be 5022 - $getTargetResourceResult.EndpointHostName | Should -Be 'Server1' - $getTargetResourceResult.BasicAvailabilityGroup | Should -Be 'True' - $getTargetResourceResult.DatabaseHealthTrigger | Should -Be 'True' - $getTargetResourceResult.DtcSupportEnabled | Should -Be 'True' - $getTargetResourceResult.Version | Should -Be 13 + $getTargetResourceResult.Name | Should-Be 'AG_AllServers' + $getTargetResourceResult.ServerName | Should-Be 'Server1' + $getTargetResourceResult.InstanceName | Should-Be 'MSSQLSERVER' + $getTargetResourceResult.Ensure | Should-Be 'Present' + $getTargetResourceResult.IsActiveNode | Should-Be 'True' + $getTargetResourceResult.AutomatedBackupPreference | Should-Be 'Secondary' + $getTargetResourceResult.AvailabilityMode | Should-Be 'AsynchronousCommit' + $getTargetResourceResult.BackupPriority | Should-Be 50 + $getTargetResourceResult.ConnectionModeInPrimaryRole | Should-Be 'AllowAllConnections' + $getTargetResourceResult.ConnectionModeInSecondaryRole | Should-Be 'AllowNoConnections' + $getTargetResourceResult.FailureConditionLevel | Should-Be 'OnCriticalServerError' + $getTargetResourceResult.FailoverMode | Should-Be 'Manual' + $getTargetResourceResult.HealthCheckTimeout | Should-BeFalsy + $getTargetResourceResult.EndpointURL | Should-Be 'TCP://Server1:5022' + $getTargetResourceResult.EndpointPort | Should-Be 5022 + $getTargetResourceResult.EndpointHostName | Should-Be 'Server1' + $getTargetResourceResult.BasicAvailabilityGroup | Should-Be 'True' + $getTargetResourceResult.DatabaseHealthTrigger | Should-Be 'True' + $getTargetResourceResult.DtcSupportEnabled | Should-Be 'True' + $getTargetResourceResult.Version | Should-Be 13 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } Context 'When SQL server version is 12' { @@ -317,28 +318,29 @@ Describe 'SqlAG\Get-TargetResource' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.Name | Should -Be 'AG_AllServers' - $getTargetResourceResult.ServerName | Should -Be 'Server2' - $getTargetResourceResult.InstanceName | Should -Be 'MSSQLSERVER' - $getTargetResourceResult.Ensure | Should -Be 'Present' - $getTargetResourceResult.IsActiveNode | Should -Be 'True' - $getTargetResourceResult.AutomatedBackupPreference | Should -Be 'Secondary' - $getTargetResourceResult.AvailabilityMode | Should -Be 'AsynchronousCommit' - $getTargetResourceResult.BackupPriority | Should -Be 50 - $getTargetResourceResult.ConnectionModeInPrimaryRole | Should -Be 'AllowAllConnections' - $getTargetResourceResult.ConnectionModeInSecondaryRole | Should -Be 'AllowNoConnections' - $getTargetResourceResult.FailureConditionLevel | Should -Be 'OnCriticalServerError' - $getTargetResourceResult.FailoverMode | Should -Be 'Manual' - $getTargetResourceResult.HealthCheckTimeout | Should -BeNullOrEmpty - $getTargetResourceResult.EndpointURL | Should -Be 'TCP://Server2:5022' - $getTargetResourceResult.EndpointPort | Should -Be 5022 - $getTargetResourceResult.EndpointHostName | Should -Be 'Server2' - $getTargetResourceResult.BasicAvailabilityGroup | Should -BeNullOrEmpty - $getTargetResourceResult.DatabaseHealthTrigger | Should -BeNullOrEmpty - $getTargetResourceResult.DtcSupportEnabled | Should -BeNullOrEmpty - $getTargetResourceResult.Version | Should -Be 12 + $getTargetResourceResult.Name | Should-Be 'AG_AllServers' + $getTargetResourceResult.ServerName | Should-Be 'Server2' + $getTargetResourceResult.InstanceName | Should-Be 'MSSQLSERVER' + $getTargetResourceResult.Ensure | Should-Be 'Present' + $getTargetResourceResult.IsActiveNode | Should-Be 'True' + $getTargetResourceResult.AutomatedBackupPreference | Should-Be 'Secondary' + $getTargetResourceResult.AvailabilityMode | Should-Be 'AsynchronousCommit' + $getTargetResourceResult.BackupPriority | Should-Be 50 + $getTargetResourceResult.ConnectionModeInPrimaryRole | Should-Be 'AllowAllConnections' + $getTargetResourceResult.ConnectionModeInSecondaryRole | Should-Be 'AllowNoConnections' + $getTargetResourceResult.FailureConditionLevel | Should-Be 'OnCriticalServerError' + $getTargetResourceResult.FailoverMode | Should-Be 'Manual' + $getTargetResourceResult.HealthCheckTimeout | Should-BeFalsy + $getTargetResourceResult.EndpointURL | Should-Be 'TCP://Server2:5022' + $getTargetResourceResult.EndpointPort | Should-Be 5022 + $getTargetResourceResult.EndpointHostName | Should-Be 'Server2' + $getTargetResourceResult.BasicAvailabilityGroup | Should-BeFalsy + $getTargetResourceResult.DatabaseHealthTrigger | Should-BeFalsy + $getTargetResourceResult.DtcSupportEnabled | Should-BeFalsy + $getTargetResourceResult.Version | Should-Be 12 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -529,18 +531,18 @@ Describe 'SqlAG\Set-TargetResource' { Ensure = 'Absent' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Scope It -Times 1 } } @@ -556,18 +558,18 @@ Describe 'SqlAG\Set-TargetResource' { $mockErrorMessage = Get-InvalidOperationRecord -Message ($script:localizedData.NotPrimaryReplica -f $setTargetResourceParameters.ServerName, $setTargetResourceParameters.Name, 'Server2') - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Scope It -Times 0 } } @@ -593,18 +595,18 @@ Describe 'SqlAG\Set-TargetResource' { ($script:localizedData.FailedRemoveAvailabilityGroup -f $setTargetResourceParameters.Name, $setTargetResourceParameters.InstanceName) + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Scope It -Times 1 } } } @@ -636,12 +638,12 @@ Describe 'SqlAG\Set-TargetResource' { $script:localizedData.HadrNotEnabled # cSpell: disable-line ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'ServerNotEnabled' - } -Times 1 -Exactly + } -Scope It -Times 1 } } @@ -673,12 +675,12 @@ Describe 'SqlAG\Set-TargetResource' { $script:localizedData.DatabaseMirroringEndpointNotFound -f 'ServerWithoutEndpoint\MSSQLSERVER' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'ServerWithoutEndpoint' - } -Times 1 -Exactly + } -Scope It -Times 1 } } @@ -722,30 +724,30 @@ Describe 'SqlAG\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 0 - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroup -Scope It -Times 0 -Exactly + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroup -Exactly -Scope It -Times 0 } Context 'When the endpoint hostname is not defined' { @@ -765,30 +767,30 @@ Describe 'SqlAG\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 0 - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityGRoup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroup -Scope It -Times 0 -Exactly + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityGRoup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroup -Exactly -Scope It -Times 0 } } @@ -820,30 +822,30 @@ Describe 'SqlAG\Set-TargetResource' { ($script:localizedData.FailedCreateAvailabilityGroupReplica -f $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName) + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 0 - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityGRoup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroup -Scope It -Times 0 -Exactly + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityGRoup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroup -Exactly -Scope It -Times 0 } } @@ -875,30 +877,30 @@ Describe 'SqlAG\Set-TargetResource' { ($script:localizedData.FailedCreateAvailabilityGroup -f $setTargetResourceParameters.Name, $setTargetResourceParameters.InstanceName) + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 0 - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityGRoup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroup -Scope It -Times 0 -Exactly + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityGRoup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroup -Exactly -Scope It -Times 0 } } } @@ -956,32 +958,32 @@ Describe 'SqlAG\Set-TargetResource' { $setTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 0 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityGRoup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 0 -Scope It + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityGRoup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } @@ -1041,32 +1043,32 @@ Describe 'SqlAG\Set-TargetResource' { $setTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 0 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityGRoup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroup -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityGRoup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } @@ -1122,10 +1124,10 @@ Describe 'SqlAG\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } @@ -1181,10 +1183,10 @@ Describe 'SqlAG\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } } @@ -1359,9 +1361,11 @@ Describe 'SqlAG\Test-TargetResource' { InstanceName = 'MSSQLSERVER' Ensure = 'Absent' } - Test-TargetResource @testTargetResourceParameters | Should -BeTrue + + Test-TargetResource @testTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 + + Should-Invoke -CommandName Connect-SQL -Exactly -Times 1 } } Context 'When the Availability Group should be present' { @@ -1373,9 +1377,11 @@ Describe 'SqlAG\Test-TargetResource' { InstanceName = 'MSSQLSERVER' Ensure = 'Present' } - Test-TargetResource @testTargetResourceParameters | Should -BeTrue + + Test-TargetResource @testTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 + + Should-Invoke -CommandName Connect-SQL -Exactly -Times 1 } } } @@ -1390,9 +1396,11 @@ Describe 'SqlAG\Test-TargetResource' { InstanceName = 'MSSQLSERVER' Ensure = 'Absent' } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 + + Should-Invoke -CommandName Connect-SQL -Exactly -Times 1 } } Context 'When the Availability Group should be present' { @@ -1403,9 +1411,11 @@ Describe 'SqlAG\Test-TargetResource' { ServerName = 'Server1' InstanceName = 'MSSQLSERVER' } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 + + Should-Invoke -CommandName Connect-SQL -Exactly -Times 1 } } } @@ -1435,10 +1445,10 @@ Describe 'SqlAG\Test-TargetResource' { ProcessOnlyOnActiveNode = $true } - Test-TargetResource @testTargetResourceParameters | Should -BeTrue + Test-TargetResource @testTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1507,10 +1517,10 @@ Describe 'SqlAG\Test-TargetResource' { $testTargetResourceParameters.$MockPropertyName = $MockPropertyValue - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Times 1 } } Context 'When endpoint port differ from the endpoint URL port' { @@ -1539,10 +1549,10 @@ Describe 'SqlAG\Test-TargetResource' { ProcessOnlyOnActiveNode = $true } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1572,10 +1582,10 @@ Describe 'SqlAG\Test-TargetResource' { ProcessOnlyOnActiveNode = $true } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 b/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 index a3b6f8d73..19a99fc5f 100644 --- a/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 +++ b/tests/Unit/DSC_SqlAGDatabase.Tests.ps1 @@ -394,10 +394,10 @@ REVERT' $result = Get-TargetResource @getTargetResourceParameters - $result.ServerName | Should -Be $getTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $getTargetResourceParameters.InstanceName - $result.AvailabilityGroupName | Should -BeNullOrEmpty - $result.DatabaseName | Should -BeNullOrEmpty + $result.ServerName | Should-Be $getTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $getTargetResourceParameters.InstanceName + $result.AvailabilityGroupName | Should-BeFalsy + $result.DatabaseName | Should-BeFalsy Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly Assert-MockCalled -CommandName Import-SqlDscPreferredModule -Scope It -Times 0 -Exactly @@ -408,10 +408,10 @@ REVERT' $result = Get-TargetResource @getTargetResourceParameters - $result.ServerName | Should -Be $getTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $getTargetResourceParameters.InstanceName - $result.AvailabilityGroupName | Should -Be $mockAvailabilityGroupWithoutDatabasesObject.Name - $result.DatabaseName | Should -BeNullOrEmpty + $result.ServerName | Should-Be $getTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $getTargetResourceParameters.InstanceName + $result.AvailabilityGroupName | Should-Be $mockAvailabilityGroupWithoutDatabasesObject.Name + $result.DatabaseName | Should-BeFalsy Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly Assert-MockCalled -CommandName Import-SqlDscPreferredModule -Scope It -Times 0 -Exactly @@ -420,18 +420,18 @@ REVERT' It 'Should return databases when there are databases in the availability group' { $result = Get-TargetResource @getTargetResourceParameters - $result.ServerName | Should -Be $getTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $getTargetResourceParameters.InstanceName - $result.AvailabilityGroupName | Should -Be $mockAvailabilityGroupObject.Name + $result.ServerName | Should-Be $getTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $getTargetResourceParameters.InstanceName + $result.AvailabilityGroupName | Should-Be $mockAvailabilityGroupObject.Name foreach ( $resultDatabaseName in $result.DatabaseName ) { - $mockAvailabilityDatabaseNames -contains $resultDatabaseName | Should -Be $true + $mockAvailabilityDatabaseNames -contains $resultDatabaseName | Should-BeTrue } foreach ( $mockAvailabilityDatabaseName in $mockAvailabilityDatabaseNames ) { - $result.DatabaseName -contains $mockAvailabilityDatabaseName | Should -Be $true + $result.DatabaseName -contains $mockAvailabilityDatabaseName | Should-BeTrue } Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly @@ -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 }) 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 }) 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 }) 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 }) 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 }) 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' } @@ -945,7 +945,7 @@ REVERT' It 'Should throw the correct error when "MatchDatabaseOwner" is $true and the current login does not have impersonate permissions' { Mock -CommandName Test-ImpersonatePermissions -MockWith { $false } -Verifiable - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The login '$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)' is missing impersonate any login, control server, impersonate login, or control login permissions in the instances 'Server2'." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The login '$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)' is missing impersonate any login, control server, impersonate login, or control login permissions in the instances 'Server2'." 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' } @@ -984,17 +984,17 @@ REVERT' $originalValue = $mockServerObject.Databases['DB1'].($prerequisiteCheck.Key) $mockServerObject.Databases['DB1'].($prerequisiteCheck.Key) = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: $($prerequisiteCheck.Key) is not $($prerequisiteCheck.Value)." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: $($prerequisiteCheck.Key) is not $($prerequisiteCheck.Value)." foreach ( $databaseProperty in $prerequisiteChecks.GetEnumerator() ) { if ( $prerequisiteCheck.Key -eq $databaseProperty.Key ) { - $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should -Not -Be ($databaseProperty.Value) + $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should-NotBe ($databaseProperty.Value) } else { - $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should -Be ($databaseProperty.Value) + $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should-Be ($databaseProperty.Value) } } @@ -1026,7 +1026,7 @@ REVERT' It 'Should throw the correct error when the database property "ID" is less than "4"' { $mockSetTargetResourceParameters.DatabaseName = @('master') - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'master' failed with the following errors: The following prerequisite checks failed: The database cannot be a system database." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'master' failed with the following errors: The following prerequisite checks failed: The database cannot be a system database." 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' } @@ -1062,7 +1062,7 @@ REVERT' $originalValue = $mockServerObject.Databases['DB1'].($filestreamProperty.Key) $mockServerObject.Databases['DB1'].($filestreamProperty.Key) = 'On' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Filestream is disabled on the following instances: Server2" + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Filestream is disabled on the following instances: Server2" 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' } @@ -1093,7 +1093,7 @@ REVERT' $originalValue = $mockServerObject.Databases['DB1'].ContainmentType $mockServerObject.Databases['DB1'].ContainmentType = 'Partial' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Contained Database Authentication is not enabled on the following instances: " + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Contained Database Authentication is not enabled on the following instances: " 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' } @@ -1124,7 +1124,7 @@ REVERT' $originalValue = $mockServer2Object.Databases['DB1'].FileGroups.Files.FileName $mockServer2Object.Databases['DB1'].FileGroups.Files.FileName = ( [IO.Path]::Combine( 'X:\', "DB1.mdf" ) ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: The instance 'Server2' is missing the following directories: X:\, F:\SqlLog" + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: The instance 'Server2' is missing the following directories: X:\, F:\SqlLog" 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' } @@ -1155,7 +1155,7 @@ REVERT' $originalValue = $mockServer2Object.Databases['DB1'].LogFiles.FileName $mockServer2Object.Databases['DB1'].LogFiles.FileName = ( [IO.Path]::Combine( 'Y:\', "DB1.ldf" ) ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following directories: E:\SqlData, Y:\' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following directories: E:\SqlData, Y:\' 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' } @@ -1186,7 +1186,7 @@ REVERT' $mockServerObject.Databases['DB1'].DatabaseEncryptionKey = $mockDatabaseEncryptionKeyObject $mockServer2Object.Databases['master'].Certificates = @($mockCertificateObject2) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following certificates: TDE Cert' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following certificates: TDE Cert' 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' } @@ -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 }) 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' } @@ -1244,7 +1244,7 @@ REVERT' It 'Should throw the correct error when it fails to perform a full backup' { Mock -CommandName Backup-SqlDatabase -MockWith { throw } -Verifiable -ParameterFilter { $BackupAction -eq 'Database' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' 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' } @@ -1271,7 +1271,7 @@ REVERT' It 'Should throw the correct error when it fails to perform a log backup' { Mock -CommandName Backup-SqlDatabase -MockWith { throw } -Verifiable -ParameterFilter { $BackupAction -eq 'Log' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' 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' } @@ -1298,7 +1298,7 @@ REVERT' It 'Should throw the correct error when it fails to add the database to the primary replica' { Mock -CommandName Add-SqlAvailabilityDatabase -MockWith { throw } -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' 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 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -1325,7 +1325,7 @@ REVERT' It 'Should throw the correct error when it fails to add the database to the primary replica' { Mock -CommandName Add-SqlAvailabilityDatabase -MockWith { throw } -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' 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 }) 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 }) Assert-MockCalled -CommandName Import-SqlDscPreferredModule -Scope It -Times 1 -Exactly Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly @@ -1491,7 +1491,7 @@ REVERT' It 'Should throw the correct error' { $errorMessage = 'The operation on the database ''DB2'' failed with the following errors: Failed to remove the database from the availability group.' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw $errorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw $errorMessage 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 }) 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 }) 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 }) 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 }) 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 }) 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' } @@ -2005,7 +2005,7 @@ REVERT' It 'Should throw the correct error when "MatchDatabaseOwner" is $true and the current login does not have impersonate permissions' { Mock -CommandName Test-ImpersonatePermissions -MockWith { $false } -Verifiable - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The login '$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)' is missing impersonate any login, control server, impersonate login, or control login permissions in the instances 'Server2'." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The login '$([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)' is missing impersonate any login, control server, impersonate login, or control login permissions in the instances 'Server2'." 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' } @@ -2044,17 +2044,17 @@ REVERT' $originalValue = $mockServerObject.Databases['DB1'].($prerequisiteCheck.Key) $mockServerObject.Databases['DB1'].($prerequisiteCheck.Key) = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: $($prerequisiteCheck.Key) is not $($prerequisiteCheck.Value)." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: $($prerequisiteCheck.Key) is not $($prerequisiteCheck.Value)." foreach ( $databaseProperty in $prerequisiteChecks.GetEnumerator() ) { if ( $prerequisiteCheck.Key -eq $databaseProperty.Key ) { - $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should -Not -Be ($databaseProperty.Value) + $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should-NotBe ($databaseProperty.Value) } else { - $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should -Be ($databaseProperty.Value) + $mockServerObject.Databases['DB1'].($databaseProperty.Key) | Should-Be ($databaseProperty.Value) } } @@ -2086,7 +2086,7 @@ REVERT' It 'Should throw the correct error when the database property "ID" is less than "4"' { $mockSetTargetResourceParameters.DatabaseName = @('master') - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'master' failed with the following errors: The following prerequisite checks failed: The database cannot be a system database." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'master' failed with the following errors: The following prerequisite checks failed: The database cannot be a system database." 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' } @@ -2122,7 +2122,7 @@ REVERT' $originalValue = $mockServerObject.Databases['DB1'].($filestreamProperty.Key) $mockServerObject.Databases['DB1'].($filestreamProperty.Key) = 'On' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Filestream is disabled on the following instances: Server2" + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Filestream is disabled on the following instances: Server2" 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' } @@ -2153,7 +2153,7 @@ REVERT' $originalValue = $mockServerObject.Databases['DB1'].ContainmentType $mockServerObject.Databases['DB1'].ContainmentType = 'Partial' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Contained Database Authentication is not enabled on the following instances: " + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: Contained Database Authentication is not enabled on the following instances: " 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' } @@ -2184,7 +2184,7 @@ REVERT' $originalValue = $mockServer2Object.Databases['DB1'].FileGroups.Files.FileName $mockServer2Object.Databases['DB1'].FileGroups.Files.FileName = ( [IO.Path]::Combine( 'X:\', "DB1.mdf" ) ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: The instance 'Server2' is missing the following directories: X:\, F:\SqlLog" + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "The operation on the database 'DB1' failed with the following errors: The following prerequisite checks failed: The instance 'Server2' is missing the following directories: X:\, F:\SqlLog" 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' } @@ -2215,7 +2215,7 @@ REVERT' $originalValue = $mockServer2Object.Databases['DB1'].LogFiles.FileName $mockServer2Object.Databases['DB1'].LogFiles.FileName = ( [IO.Path]::Combine( 'Y:\', "DB1.ldf" ) ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following directories: E:\SqlData, Y:\' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following directories: E:\SqlData, Y:\' 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' } @@ -2246,7 +2246,7 @@ REVERT' $mockServerObject.Databases['DB1'].DatabaseEncryptionKey = $mockDatabaseEncryptionKeyObject $mockServer2Object.Databases['master'].Certificates = @($mockCertificateObject2) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following certificates: TDE Cert' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: The following prerequisite checks failed: The instance ''Server2'' is missing the following certificates: TDE Cert' 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' } @@ -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 }) 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' } @@ -2309,7 +2309,7 @@ REVERT' It 'Should throw the correct error when it fails to add the database to the primary replica' { Mock -CommandName Add-SqlAvailabilityDatabase -MockWith { throw } -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' 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 0 -Exactly -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } @@ -2336,7 +2336,7 @@ REVERT' It 'Should throw the correct error when it fails to add the database to the primary replica' { Mock -CommandName Add-SqlAvailabilityDatabase -MockWith { throw } -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw 'The operation on the database ''DB1'' failed with the following errors: System.Management.Automation.RuntimeException: ScriptHalted' 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 }) 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' } @@ -2753,7 +2753,7 @@ REVERT' It 'Should return $true when the configuration is in the desired state' { $mockTestTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames.Clone() - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2764,7 +2764,7 @@ REVERT' It 'Should return $false when the specified availability group is not found' { $mockTestTargetResourceParameters.AvailabilityGroupName = 'NonExistentAvailabilityGroup' - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 0 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2775,7 +2775,7 @@ REVERT' It 'Should return $false when no matching databases are found' { $mockTestTargetResourceParameters.DatabaseName = $mockDatabaseNameParameterWithNonExistingDatabases.Clone() - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2784,7 +2784,7 @@ REVERT' } It 'Should return $false when databases are found to add to the availability group' { - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2796,7 +2796,7 @@ REVERT' $mockTestTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames.Clone() $mockTestTargetResourceParameters.AvailabilityGroupName = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 0 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2810,7 +2810,7 @@ REVERT' $mockTestTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames.Clone() $mockTestTargetResourceParameters.ProcessOnlyOnActiveNode = $mockProcessOnlyOnActiveNode - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 0 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2827,7 +2827,7 @@ REVERT' It 'Should return $true when the configuration is in the desired state' { $mockTestTargetResourceParameters.DatabaseName = $mockDatabaseNameParameterWithNonExistingDatabases.Clone() - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2838,7 +2838,7 @@ REVERT' It 'Should return $true when no matching databases are found' { $mockTestTargetResourceParameters.DatabaseName = $mockDatabaseNameParameterWithNonExistingDatabases.Clone() - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2846,7 +2846,7 @@ REVERT' } It 'Should return $false when databases are found to remove from the availability group' { - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2857,7 +2857,7 @@ REVERT' $mockTestTargetResourceParameters.DatabaseName = $mockDatabaseNameParameterWithNonExistingDatabases.Clone() $mockTestTargetResourceParameters.AvailabilityGroupName = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 0 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2873,7 +2873,7 @@ REVERT' It 'Should return $true when the configuration is in the desired state' { $mockTestTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames.Clone() - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2883,7 +2883,7 @@ REVERT' It 'Should return $false when no matching databases are found' { $mockTestTargetResourceParameters.DatabaseName = $mockDatabaseNameParameterWithNonExistingDatabases.Clone() - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2891,7 +2891,7 @@ REVERT' } It 'Should return $false when databases are found to add to the availability group' { - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2899,7 +2899,7 @@ REVERT' } It 'Should return $false when databases are found to remove from the availability group' { - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $false + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 1 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2910,7 +2910,7 @@ REVERT' $mockTestTargetResourceParameters.DatabaseName = $mockAvailabilityDatabaseNames.Clone() $mockTestTargetResourceParameters.AvailabilityGroupName = $mockAvailabilityGroupObjectWithPrimaryReplicaOnAnotherServer.Name - Test-TargetResource @mockTestTargetResourceParameters | Should -Be $true + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 2 -Exactly Assert-MockCalled -CommandName Get-PrimaryReplicaServerObject -Scope It -Times 0 -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } @@ -2935,7 +2935,7 @@ REVERT' foreach ( $result in $results ) { - $mockAvailabilityDatabasePresentResults -contains $result | Should -Be $true + $mockAvailabilityDatabasePresentResults -contains $result | Should-BeTrue } } @@ -2946,14 +2946,14 @@ REVERT' foreach ( $result in $results ) { - $mockPresentDatabaseNames -contains $result | Should -Be $true + $mockPresentDatabaseNames -contains $result | Should-BeTrue } } It 'Should return an empty object when no matches are found' { $getDatabasesToAddToAvailabilityGroup.DatabaseName = @() - Get-DatabasesToAddToAvailabilityGroup @getDatabasesToAddToAvailabilityGroup | Should -BeNullOrEmpty + Get-DatabasesToAddToAvailabilityGroup @getDatabasesToAddToAvailabilityGroup | Should-BeFalsy } } } @@ -2979,7 +2979,7 @@ REVERT' foreach ( $result in $results ) { - $mockAvailabilityDatabaseAbsentResults -contains $result | Should -Be $true + $mockAvailabilityDatabaseAbsentResults -contains $result | Should-BeTrue } } @@ -2990,14 +2990,14 @@ REVERT' foreach ( $result in $results ) { - $mockAvailabilityDatabaseAbsentResults -contains $result | Should -Be $true + $mockAvailabilityDatabaseAbsentResults -contains $result | Should-BeTrue } } It 'Should return an empty object when no matches are found' { $getDatabasesToRemoveFromAvailabilityGroupParameters.DatabaseName = @() - Get-DatabasesToRemoveFromAvailabilityGroup @getDatabasesToRemoveFromAvailabilityGroupParameters | Should -BeNullOrEmpty + Get-DatabasesToRemoveFromAvailabilityGroup @getDatabasesToRemoveFromAvailabilityGroupParameters | Should-BeFalsy } } @@ -3011,7 +3011,7 @@ REVERT' foreach ( $result in $results ) { - $mockAvailabilityDatabaseExactlyRemoveResults -contains $result | Should -Be $true + $mockAvailabilityDatabaseExactlyRemoveResults -contains $result | Should-BeTrue } } @@ -3023,13 +3023,13 @@ REVERT' # Ensure all of the results are in the Availability Databases foreach ( $result in $results ) { - $mockAvailabilityDatabaseNames -contains $result | Should -Be $true + $mockAvailabilityDatabaseNames -contains $result | Should-BeTrue } # Ensure all of the Availability Databases are in the results foreach ( $mockAvailabilityDatabaseName in $mockAvailabilityDatabaseNames ) { - $results -contains $mockAvailabilityDatabaseName | Should -Be $true + $results -contains $mockAvailabilityDatabaseName | Should-BeTrue } } } @@ -3047,13 +3047,13 @@ REVERT' It 'Should throw the correct error when and invalid object type is passed to the method' { $getMatchingDatabaseNamesParameters.ServerObject = $mockBadServerObject - { Get-MatchingDatabaseNames @getMatchingDatabaseNamesParameters } | Should -Throw 'ServerObject' + { Get-MatchingDatabaseNames @getMatchingDatabaseNamesParameters } | Should-Throw 'ServerObject' } It 'Should return an empty object when no matching databases are found' { $getMatchingDatabaseNamesParameters.DatabaseName = @('DatabaseNotHere') - Get-MatchingDatabaseNames @getMatchingDatabaseNamesParameters | Should -BeNullOrEmpty + Get-MatchingDatabaseNames @getMatchingDatabaseNamesParameters | Should-BeFalsy } It 'Should return an array of database names that match the defined databases' { @@ -3061,7 +3061,7 @@ REVERT' foreach ( $result in $results ) { - $mockPresentDatabaseNames -contains $result | Should -Be $true + $mockPresentDatabaseNames -contains $result | Should-BeTrue } } @@ -3072,7 +3072,7 @@ REVERT' foreach ( $result in $results ) { - $mockPresentDatabaseNames -contains $result | Should -Be $true + $mockPresentDatabaseNames -contains $result | Should-BeTrue } } } @@ -3098,7 +3098,7 @@ REVERT' It 'Should return an empty object when no missing databases were identified' { $getDatabaseNamesNotFoundOnTheInstanceParameters.MatchingDatabaseNames = $mockDatabaseNameParameter - Get-DatabaseNamesNotFoundOnTheInstance @getDatabaseNamesNotFoundOnTheInstanceParameters | Should -BeNullOrEmpty + Get-DatabaseNamesNotFoundOnTheInstance @getDatabaseNamesNotFoundOnTheInstanceParameters | Should-BeFalsy } It 'Should return a string array of database names when missing databases are identified' { @@ -3108,7 +3108,7 @@ REVERT' foreach ( $result in $results ) { - $mockMissingDatabases -contains $result | Should -Be $true + $mockMissingDatabases -contains $result | Should-BeTrue } } @@ -3116,7 +3116,7 @@ REVERT' $getDatabaseNamesNotFoundOnTheInstanceParameters.DatabaseName = @() $getDatabaseNamesNotFoundOnTheInstanceParameters.MatchingDatabaseNames = $mockPresentDatabaseNames - Get-DatabaseNamesNotFoundOnTheInstance @getDatabaseNamesNotFoundOnTheInstanceParameters | Should -BeNullOrEmpty + Get-DatabaseNamesNotFoundOnTheInstance @getDatabaseNamesNotFoundOnTheInstanceParameters | Should-BeFalsy } } } diff --git a/tests/Unit/DSC_SqlAGListener.Tests.ps1 b/tests/Unit/DSC_SqlAGListener.Tests.ps1 index 007ad7c78..f45588a1b 100644 --- a/tests/Unit/DSC_SqlAGListener.Tests.ps1 +++ b/tests/Unit/DSC_SqlAGListener.Tests.ps1 @@ -113,7 +113,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } @@ -121,10 +121,10 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.AvailabilityGroup | Should -Be $mockGetTargetResourceParameters.AvailabilityGroup + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.AvailabilityGroup | Should-Be $mockGetTargetResourceParameters.AvailabilityGroup } } @@ -132,7 +132,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IpAddress | Should -BeNullOrEmpty + $result.IpAddress | Should-BeFalsy } } @@ -140,7 +140,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Port | Should -Be 0 + $result.Port | Should-Be 0 } } @@ -148,16 +148,16 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DHCP | Should -BeFalse + $result.DHCP | Should-BeFalse } } It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockGetTargetResourceParameters }) } - Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Scope It -Times 1 } } @@ -187,7 +187,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } @@ -195,10 +195,10 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.AvailabilityGroup | Should -Be $mockGetTargetResourceParameters.AvailabilityGroup + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.AvailabilityGroup | Should-Be $mockGetTargetResourceParameters.AvailabilityGroup } } @@ -206,7 +206,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IpAddress | Should -Be '192.168.0.1/255.255.255.0' + $result.IpAddress | Should-Be '192.168.0.1/255.255.255.0' } } @@ -214,7 +214,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Port | Should -Be 5031 + $result.Port | Should-Be 5031 } } @@ -224,7 +224,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DHCP | Should -BeFalse + $result.DHCP | Should-BeFalse } } @@ -234,17 +234,17 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ProcessOnlyOnActiveNode | Should -BeTrue - $result.IsActiveNode | Should -BeFalse + $result.ProcessOnlyOnActiveNode | Should-BeTrue + $result.IsActiveNode | Should-BeFalse } } It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockGetTargetResourceParameters }) } - Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Scope It -Times 1 } } @@ -274,7 +274,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } @@ -282,10 +282,10 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.AvailabilityGroup | Should -Be $mockGetTargetResourceParameters.AvailabilityGroup + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.AvailabilityGroup | Should-Be $mockGetTargetResourceParameters.AvailabilityGroup } } @@ -293,7 +293,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IpAddress | Should -Be '192.168.0.1/255.255.255.0' + $result.IpAddress | Should-Be '192.168.0.1/255.255.255.0' } } @@ -301,7 +301,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Port | Should -Be 5031 + $result.Port | Should-Be 5031 } } @@ -309,16 +309,16 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DHCP | Should -BeTrue + $result.DHCP | Should-BeTrue } } It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockGetTargetResourceParameters }) } - Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Scope It -Times 1 } } @@ -348,7 +348,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } @@ -356,10 +356,10 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.AvailabilityGroup | Should -Be $mockGetTargetResourceParameters.AvailabilityGroup + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.AvailabilityGroup | Should-Be $mockGetTargetResourceParameters.AvailabilityGroup } } @@ -367,7 +367,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IpAddress | Should -Be '192.168.0.1' + $result.IpAddress | Should-Be '192.168.0.1' } } @@ -375,7 +375,7 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Port | Should -Be 5031 + $result.Port | Should-Be 5031 } } @@ -383,16 +383,16 @@ Describe 'SqlAGListener\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DHCP | Should -BeFalse + $result.DHCP | Should-BeFalse } } It 'Should call the mock function Get-SQLAlwaysOnAvailabilityGroupListener' { InModuleScope -ScriptBlock { - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockGetTargetResourceParameters }) } - Should -Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Exactly -Scope It -Times 1 } } } @@ -433,10 +433,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -453,10 +453,10 @@ Describe 'SqlAGListener\Test-TargetResource' { InModuleScope -ScriptBlock { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -497,10 +497,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -519,10 +519,10 @@ Describe 'SqlAGListener\Test-TargetResource' { InModuleScope -ScriptBlock { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -541,10 +541,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -581,10 +581,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -606,10 +606,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -621,10 +621,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -653,10 +653,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -677,10 +677,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -702,10 +702,10 @@ Describe 'SqlAGListener\Test-TargetResource' { $mockTestTargetResourceParameters.DHCP = $true $mockTestTargetResourceParameters.ProcessOnlyOnActiveNode = $true - Test-TargetResource @mockTestTargetResourceParameters | Should -BeTrue + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -744,10 +744,10 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -791,11 +791,11 @@ 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 }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -868,11 +868,11 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -Parameters $_ -ScriptBlock { $mockSetTargetResourceParameters.$MockPropertyName = $MockExpectedValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -905,11 +905,11 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupNotFound -f 'UnknownAG', 'MSSQLSERVER' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -939,11 +939,11 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupNotFound -f 'UnknownAG', 'MSSQLSERVER' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -974,11 +974,11 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupNotFound -f 'UnknownAG', 'MSSQLSERVER' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -1017,11 +1017,11 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupListenerNotFound -f 'UnknownListener', 'AG01' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1059,11 +1059,11 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupListenerNotFound -f 'UnknownListener', 'AG01' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -1099,12 +1099,12 @@ 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 }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroupListener -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroupListener -Exactly -Scope It -Times 1 } } @@ -1134,14 +1134,14 @@ 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 }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroupListener -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroupListener -Exactly -ParameterFilter { $DhcpSubnet -eq '192.168.10.45/255.255.252.0' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1170,14 +1170,14 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Port = 5031 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroupListener -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroupListener -Exactly -ParameterFilter { $Port -eq 5031 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1206,14 +1206,14 @@ 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 }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityGroupListener -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityGroupListener -Exactly -ParameterFilter { $StaticIp -eq '192.168.10.45/255.255.252.0' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1259,13 +1259,13 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodDropWasRunCount | Should -Be 1 + $mockMethodDropWasRunCount | Should-Be 1 } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1303,12 +1303,12 @@ Describe 'SqlAGListener\Set-TargetResource' { InModuleScope -ScriptBlock { $mockSetTargetResourceParameters.Port = 5030 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Set-SqlAvailabilityGroupListener -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-SqlAvailabilityGroupListener -Exactly -Scope It -Times 1 } } @@ -1329,10 +1329,10 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupListenerIPChangeError -f '192.168.10.45/255.255.255.0', '192.168.0.1/255.255.252.0' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1384,12 +1384,12 @@ Describe 'SqlAGListener\Set-TargetResource' { '192.168.0.1/255.255.252.0' ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Add-SqlAvailabilityGroupListenerStaticIp -Exactly -Scope It -Times 1 } } } @@ -1410,10 +1410,10 @@ Describe 'SqlAGListener\Set-TargetResource' { $mockErrorMessage = $script:localizedData.AvailabilityGroupListenerDHCPChangeError -f $true, $false - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1463,10 +1463,10 @@ Describe 'SqlAGListener\Get-SQLAlwaysOnAvailabilityGroupListener' -Skip:($IsLinu $result = Get-SQLAlwaysOnAvailabilityGroupListener @mockGetSQLAlwaysOnAvailabilityGroupListenerParameters - $result.PortNumber | Should -Be 5031 - $result.AvailabilityGroupListenerIPAddresses.IsDHCP | Should -BeTrue - $result.AvailabilityGroupListenerIPAddresses.IPAddress | Should -Be '192.168.0.1' - $result.AvailabilityGroupListenerIPAddresses.SubnetMask | Should -Be '255.255.255.0' + $result.PortNumber | Should-Be 5031 + $result.AvailabilityGroupListenerIPAddresses.IsDHCP | Should-BeTrue + $result.AvailabilityGroupListenerIPAddresses.IPAddress | Should-Be '192.168.0.1' + $result.AvailabilityGroupListenerIPAddresses.SubnetMask | Should-Be '255.255.255.0' } } } @@ -1483,7 +1483,7 @@ Describe 'SqlAGListener\Get-SQLAlwaysOnAvailabilityGroupListener' -Skip:($IsLinu $result = Get-SQLAlwaysOnAvailabilityGroupListener @mockGetSQLAlwaysOnAvailabilityGroupListenerParameters - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy } } } @@ -1500,7 +1500,7 @@ Describe 'SqlAGListener\Get-SQLAlwaysOnAvailabilityGroupListener' -Skip:($IsLinu $mockErrorMessage = $script:localizedData.AvailabilityGroupNotFound -f 'UnknownAG', 'MSSQLSERVER' - { $result = Get-SQLAlwaysOnAvailabilityGroupListener @mockGetSQLAlwaysOnAvailabilityGroupListenerParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { $result = Get-SQLAlwaysOnAvailabilityGroupListener @mockGetSQLAlwaysOnAvailabilityGroupListenerParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } diff --git a/tests/Unit/DSC_SqlAGReplica.Tests.ps1 b/tests/Unit/DSC_SqlAGReplica.Tests.ps1 index dc0788790..189c36dee 100644 --- a/tests/Unit/DSC_SqlAGReplica.Tests.ps1 +++ b/tests/Unit/DSC_SqlAGReplica.Tests.ps1 @@ -165,25 +165,25 @@ Describe 'SqlAGReplica\Get-TargetResource' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.AvailabilityGroupName | Should -Be 'AbsentAG' - $getTargetResourceResult.AvailabilityMode | Should -BeNullOrEmpty - $getTargetResourceResult.BackupPriority | Should -BeNullOrEmpty - $getTargetResourceResult.ConnectionModeInPrimaryRole | Should -BeNullOrEmpty - $getTargetResourceResult.ConnectionModeInSecondaryRole | Should -BeNullOrEmpty - $getTargetResourceResult.EndpointUrl | Should -BeNullOrEmpty - $getTargetResourceResult.EndpointPort | Should -Be 5022 - $getTargetResourceResult.Ensure | Should -Be 'Absent' - $getTargetResourceResult.FailoverMode | Should -BeNullOrEmpty - $getTargetResourceResult.Name | Should -Be 'Server1' - $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should -BeNullOrEmpty - $getTargetResourceResult.ReadOnlyRoutingList | Should -BeNullOrEmpty - $getTargetResourceResult.ServerName | Should -Be 'Server1' - $getTargetResourceResult.InstanceName | Should -Be 'MSSQLSERVER' - $getTargetResourceResult.EndpointHostName | Should -Be 'Server1' - $getTargetResourceResult.SeedingMode | Should -BeNullOrEmpty - } - - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + $getTargetResourceResult.AvailabilityGroupName | Should-Be 'AbsentAG' + $getTargetResourceResult.AvailabilityMode | Should-BeFalsy + $getTargetResourceResult.BackupPriority | Should-BeFalsy + $getTargetResourceResult.ConnectionModeInPrimaryRole | Should-BeFalsy + $getTargetResourceResult.ConnectionModeInSecondaryRole | Should-BeFalsy + $getTargetResourceResult.EndpointUrl | Should-BeFalsy + $getTargetResourceResult.EndpointPort | Should-Be 5022 + $getTargetResourceResult.Ensure | Should-Be 'Absent' + $getTargetResourceResult.FailoverMode | Should-BeFalsy + $getTargetResourceResult.Name | Should-Be 'Server1' + $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should-BeFalsy + $getTargetResourceResult.ReadOnlyRoutingList | Should-BeFalsy + $getTargetResourceResult.ServerName | Should-Be 'Server1' + $getTargetResourceResult.InstanceName | Should-Be 'MSSQLSERVER' + $getTargetResourceResult.EndpointHostName | Should-Be 'Server1' + $getTargetResourceResult.SeedingMode | Should-BeFalsy + } + + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -199,25 +199,25 @@ Describe 'SqlAGReplica\Get-TargetResource' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.AvailabilityGroupName | Should -Be 'AG_AllServers' - $getTargetResourceResult.AvailabilityMode | Should -Be 'AsynchronousCommit' - $getTargetResourceResult.BackupPriority | Should -Be 50 - $getTargetResourceResult.ConnectionModeInPrimaryRole | Should -Be 'AllowAllConnections' - $getTargetResourceResult.ConnectionModeInSecondaryRole | Should -Be 'AllowNoConnections' - $getTargetResourceResult.EndpointUrl | Should -Be 'TCP://Server1:5022' - $getTargetResourceResult.EndpointPort | Should -Be 5022 - $getTargetResourceResult.Ensure | Should -Be 'Present' - $getTargetResourceResult.FailoverMode | Should -Be 'Manual' - $getTargetResourceResult.Name | Should -Be 'Server1' - $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should -Be 'TCP://Server1.domain.com:1433' - $getTargetResourceResult.ReadOnlyRoutingList | Should -Be @('Server1', 'Server2') - $getTargetResourceResult.ServerName | Should -Be 'Server1' - $getTargetResourceResult.InstanceName | Should -Be 'MSSQLSERVER' - $getTargetResourceResult.EndpointHostName | Should -Be 'Server1' - $getTargetResourceResult.SeedingMode | Should -Be 'Manual' - } - - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + $getTargetResourceResult.AvailabilityGroupName | Should-Be 'AG_AllServers' + $getTargetResourceResult.AvailabilityMode | Should-Be 'AsynchronousCommit' + $getTargetResourceResult.BackupPriority | Should-Be 50 + $getTargetResourceResult.ConnectionModeInPrimaryRole | Should-Be 'AllowAllConnections' + $getTargetResourceResult.ConnectionModeInSecondaryRole | Should-Be 'AllowNoConnections' + $getTargetResourceResult.EndpointUrl | Should-Be 'TCP://Server1:5022' + $getTargetResourceResult.EndpointPort | Should-Be 5022 + $getTargetResourceResult.Ensure | Should-Be 'Present' + $getTargetResourceResult.FailoverMode | Should-Be 'Manual' + $getTargetResourceResult.Name | Should-Be 'Server1' + $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should-Be 'TCP://Server1.domain.com:1433' + $getTargetResourceResult.ReadOnlyRoutingList | Should-Be @('Server1', 'Server2') + $getTargetResourceResult.ServerName | Should-Be 'Server1' + $getTargetResourceResult.InstanceName | Should-Be 'MSSQLSERVER' + $getTargetResourceResult.EndpointHostName | Should-Be 'Server1' + $getTargetResourceResult.SeedingMode | Should-Be 'Manual' + } + + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -520,39 +520,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { Ensure = 'Absent' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName New-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-ClusterPermissions -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } @@ -577,39 +577,40 @@ Describe 'SqlAGReplica\Set-TargetResource' { $mockErrorMessage = Get-InvalidOperationRecord -Message ( ($script:localizedData.FailedRemoveAvailabilityGroupReplica -f $setTargetResourceParameters.Name, $setTargetResourceParameters.AvailabilityGroupName, $setTargetResourceParameters.InstanceName) + "*" ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName New-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-ClusterPermissions -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } } @@ -642,14 +643,14 @@ Describe 'SqlAGReplica\Set-TargetResource' { $script:localizedData.HadrNotEnabled # cSpell: disable-line ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'ServerNotEnabled' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 } } @@ -681,14 +682,14 @@ Describe 'SqlAGReplica\Set-TargetResource' { $script:localizedData.DatabaseMirroringEndpointNotFound -f 'ServerWithoutEndpoint\MSSQLSERVER' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'ServerWithoutEndpoint' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 } } @@ -719,39 +720,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } - - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + } -Scope It -Times 0 + + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } Context 'When the endpoint hostname is not defined' { @@ -776,39 +777,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } @@ -834,39 +835,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } @@ -903,39 +904,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { ($script:localizedData.FailedCreateAvailabilityGroupReplica -f 'Server1', 'AG_PrimaryOnServer2', 'MSSQLSERVER') + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } @@ -972,39 +973,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { ($script:localizedData.FailedJoinAvailabilityGroup -f 'Server1', 'AG_PrimaryOnServer2', 'MSSQLSERVER') + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } @@ -1035,39 +1036,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { ($script:localizedData.AvailabilityGroupNotFound -f 'DoesNotExist', 'MSSQLSERVER') + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName New-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 0 } } } @@ -1100,37 +1101,37 @@ Describe 'SqlAGReplica\Set-TargetResource' { ($script:localizedData.ReplicaNotFound -f 'ReplicaNotFound', 'AG_AllServers', 'MSSQLSERVER') + '*' ) - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorRecord + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorRecord } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName New-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 } } @@ -1200,39 +1201,39 @@ Describe 'SqlAGReplica\Set-TargetResource' { $setTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server1' - } -Times 1 -Exactly + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server2' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Connect-SQL -Scope It -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { $ServerName -eq 'Server3' - } -Times 0 -Exactly + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' - } + } -Scope It -Times 0 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' - } + } -Scope It -Times 1 - Should -Invoke -CommandName Get-PrimaryReplicaServerObject -Scope It -Time 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Get-PrimaryReplicaServerObject -Exactly -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server3' - } - - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Join-SqlAvailabilityGroup -Scope It -Times 0 -Exactly - Should -Invoke -CommandName New-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Remove-SqlAvailabilityReplica -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-ClusterPermissions -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-AvailabilityGroupReplica -ParameterFilter { + } -Scope It -Times 0 + + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Join-SqlAvailabilityGroup -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlAvailabilityReplica -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-ClusterPermissions -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -ParameterFilter { switch ($MockPropertyName) { # ReadOnlyRoutingList is an array, so we have to evaluate it differently. @@ -1260,7 +1261,7 @@ Describe 'SqlAGReplica\Set-TargetResource' { $AvailabilityGroupReplica.$MockPropertyName -eq $MockPropertyValue } } - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1290,10 +1291,10 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } @@ -1323,10 +1324,10 @@ Describe 'SqlAGReplica\Set-TargetResource' { SeedingMode = 'Manual' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } @@ -1382,10 +1383,10 @@ Describe 'SqlAGReplica\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } @@ -1441,10 +1442,10 @@ Describe 'SqlAGReplica\Set-TargetResource' { EndpointHostName = 'Server10' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Update-AvailabilityGroupReplica -Exactly -Scope It -Times 1 } } } @@ -1475,10 +1476,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { InstanceName = 'MSSQLSERVER' } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeTrue + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1506,10 +1507,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { InstanceName = 'MSSQLSERVER' } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeTrue + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1540,10 +1541,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { InstanceName = 'MSSQLSERVER' } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeFalse + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1569,10 +1570,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { InstanceName = 'MSSQLSERVER' } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeFalse + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1603,10 +1604,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { ProcessOnlyOnActiveNode = $true } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeTrue + Test-TargetResource @mockTestTargetResourceParameters | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1688,10 +1689,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { $mockTestTargetResourceParameters.$MockPropertyName = $MockPropertyValue - Test-TargetResource @mockTestTargetResourceParameters | Should -BeFalse + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1723,10 +1724,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { ProcessOnlyOnActiveNode = $true } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeFalse + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1758,10 +1759,10 @@ Describe 'SqlAGReplica\Test-TargetResource' { ProcessOnlyOnActiveNode = $true } - Test-TargetResource @mockTestTargetResourceParameters | Should -BeFalse + Test-TargetResource @mockTestTargetResourceParameters | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/DSC_SqlAgentAlert.Tests.ps1 b/tests/Unit/DSC_SqlAgentAlert.Tests.ps1 index 2126f37db..d2bf777cd 100644 --- a/tests/Unit/DSC_SqlAgentAlert.Tests.ps1 +++ b/tests/Unit/DSC_SqlAgentAlert.Tests.ps1 @@ -127,7 +127,7 @@ Describe 'DSC_SqlAgentAlert\Get-TargetResource' -Tag 'Get' { ) { Get-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -148,10 +148,10 @@ Describe 'DSC_SqlAgentAlert\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -160,8 +160,8 @@ Describe 'DSC_SqlAgentAlert\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.ServerName | Should -Be $mockTestParameters.ServerName - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.ServerName | Should-Be $mockTestParameters.ServerName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } @@ -169,10 +169,10 @@ Describe 'DSC_SqlAgentAlert\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call all verifiable mocks' { @@ -196,10 +196,10 @@ Describe 'DSC_SqlAgentAlert\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -208,11 +208,11 @@ Describe 'DSC_SqlAgentAlert\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.ServerName | Should -Be $mockTestParameters.ServerName - $result.InstanceName | Should -Be $mockTestParameters.InstanceName - $result.Name | Should -Be $mockTestParameters.Name - $result.Severity | Should -Be '17' - $result.MessageId | Should -Be 0 + $result.ServerName | Should-Be $mockTestParameters.ServerName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName + $result.Name | Should-Be $mockTestParameters.Name + $result.Severity | Should-Be '17' + $result.MessageId | Should-Be 0 } } @@ -264,10 +264,10 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -297,10 +297,10 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -331,7 +331,7 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } } @@ -348,7 +348,7 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -381,7 +381,7 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -412,10 +412,10 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } It 'Should return the state as true when desired sql agent alert exists and has the correct severity' { @@ -431,7 +431,7 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -463,7 +463,7 @@ Describe 'DSC_SqlAgentAlert\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -616,7 +616,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { ) { Set-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -640,13 +640,13 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { Severity = '16' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Object -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.Agent.Alert' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } It 'Should not throw when changing the severity' { @@ -660,7 +660,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { Severity = '17' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } } @@ -675,7 +675,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { MessageId = '825' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } } @@ -691,7 +691,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { MessageId = '825' } - { Set-TargetResource @mockTestParameters } | Should -Throw + { Set-TargetResource @mockTestParameters } | Should-Throw } } @@ -706,7 +706,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { MessageId = '7' } - { Set-TargetResource @mockTestParameters } | Should -Throw + { Set-TargetResource @mockTestParameters } | Should-Throw } } @@ -721,7 +721,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { Severity = '999' } - { Set-TargetResource @mockTestParameters } | Should -Throw + { Set-TargetResource @mockTestParameters } | Should-Throw } } @@ -736,7 +736,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { MessageId = '7' } - { Set-TargetResource @mockTestParameters } | Should -Throw + { Set-TargetResource @mockTestParameters } | Should-Throw } } @@ -751,7 +751,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { Severity = '999' } - { Set-TargetResource @mockTestParameters } | Should -Throw + { Set-TargetResource @mockTestParameters } | Should-Throw } } @@ -776,7 +776,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { the mocked exception message on top of the original message. #> { Set-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } $mockInvalidOperationForCreateMethod = $false @@ -802,10 +802,10 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { Ensure = 'Absent' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should throw the correct error when Drop() method was called with invalid operation' { @@ -829,7 +829,7 @@ Describe 'DSC_SqlAgentAlert\Set-TargetResource' -Tag 'Set' { the mocked exception message on top of the original message. #> { Set-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } $mockInvalidOperationForDropMethod = $false diff --git a/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 b/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 index 9fdc3df73..fee21689b 100644 --- a/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 +++ b/tests/Unit/DSC_SqlAgentFailsafe.Tests.ps1 @@ -118,7 +118,7 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { ) { Get-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -139,7 +139,7 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } @@ -149,8 +149,8 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.ServerName | Should -Be $mockTestParameters.ServerName - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.ServerName | Should-Be $mockTestParameters.ServerName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } @@ -158,9 +158,9 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockTestParameters }) - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -186,7 +186,7 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } @@ -196,10 +196,10 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockTestParameters - $result.ServerName | Should -Be $mockTestParameters.ServerName - $result.InstanceName | Should -Be $mockTestParameters.InstanceName - $result.Name | Should -Be $mockTestParameters.Name - $result.NotificationMethod | Should -Be 'NotifyEmail' + $result.ServerName | Should-Be $mockTestParameters.ServerName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName + $result.Name | Should-Be $mockTestParameters.Name + $result.NotificationMethod | Should-Be 'NotifyEmail' } } @@ -207,9 +207,9 @@ Describe 'DSC_SqlAgentFailsafe\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @mockTestParameters }) - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -258,10 +258,10 @@ Describe 'DSC_SqlAgentFailsafe\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -289,10 +289,10 @@ Describe 'DSC_SqlAgentFailsafe\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -319,10 +319,10 @@ Describe 'DSC_SqlAgentFailsafe\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -351,10 +351,10 @@ Describe 'DSC_SqlAgentFailsafe\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -382,10 +382,10 @@ Describe 'DSC_SqlAgentFailsafe\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -412,10 +412,10 @@ Describe 'DSC_SqlAgentFailsafe\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -487,7 +487,7 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { ) { Set-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -512,10 +512,10 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { Ensure = 'Present' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should not throw when changing the severity' { @@ -530,10 +530,10 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { NotificationMethod = 'Pager' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should throw when notification method is not valid' { @@ -548,10 +548,10 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { NotificationMethod = 'Letter' } - { Set-TargetResource @mockTestParameters } | Should -Throw + { Set-TargetResource @mockTestParameters } | Should-Throw } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } It 'Should throw the correct error when Alter() method was called with invalid operation' { @@ -572,10 +572,10 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { ) { Set-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call all verifiable mocks' { @@ -603,10 +603,10 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { Ensure = 'Absent' } - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should throw the correct error when Alter() method was called with invalid operation' { @@ -627,10 +627,10 @@ Describe 'DSC_SqlAgentFailsafe\Set-TargetResource' -Tag 'Set' { ) { Set-TargetResource @mockTestParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call all verifiable mocks' { diff --git a/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 b/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 index 3158d30de..f55d2baae 100644 --- a/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 +++ b/tests/Unit/DSC_SqlAgentOperator.Tests.ps1 @@ -113,10 +113,10 @@ Describe 'DSC_SqlAgentOperator\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -130,11 +130,11 @@ Describe 'DSC_SqlAgentOperator\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @testParameters - $result.ServerName | Should -Be $testParameters.ServerName - $result.InstanceName | Should -Be $testParameters.InstanceName + $result.ServerName | Should-Be $testParameters.ServerName + $result.InstanceName | Should-Be $testParameters.InstanceName } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -150,10 +150,10 @@ Describe 'DSC_SqlAgentOperator\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @testParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -167,12 +167,12 @@ Describe 'DSC_SqlAgentOperator\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @testParameters - $result.ServerName | Should -Be $testParameters.ServerName - $result.InstanceName | Should -Be $testParameters.InstanceName - $result.Name | Should -Be $testParameters.Name + $result.ServerName | Should-Be $testParameters.ServerName + $result.InstanceName | Should-Be $testParameters.InstanceName + $result.Name | Should-Be $testParameters.Name } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -194,7 +194,7 @@ Describe 'DSC_SqlAgentOperator\Get-TargetResource' -Tag 'Get' { $errorMessage = $script:localizedData.ConnectServerFailed -f $mockServerName, $mockInstanceName - { Get-TargetResource @testParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + { Get-TargetResource @testParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } } } @@ -244,10 +244,10 @@ Describe 'DSC_SqlAgentOperator\Test-TargetResource' -Tag 'Test' { } $result = Test-TargetResource @testParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -276,10 +276,10 @@ Describe 'DSC_SqlAgentOperator\Test-TargetResource' -Tag 'Test' { } $result = Test-TargetResource @testParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -307,10 +307,10 @@ Describe 'DSC_SqlAgentOperator\Test-TargetResource' -Tag 'Test' { } $result = Test-TargetResource @testParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -340,10 +340,10 @@ Describe 'DSC_SqlAgentOperator\Test-TargetResource' -Tag 'Test' { } $result = Test-TargetResource @testParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -372,10 +372,10 @@ Describe 'DSC_SqlAgentOperator\Test-TargetResource' -Tag 'Test' { } $result = Test-TargetResource @testParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -403,10 +403,10 @@ Describe 'DSC_SqlAgentOperator\Test-TargetResource' -Tag 'Test' { } $result = Test-TargetResource @testParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -512,13 +512,13 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Ensure = 'Present' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Object -Exactly -Times 1 -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.Agent.Operator' - } -Scope It + } -Scope It -Times 1 } } @@ -546,7 +546,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Ensure = 'Present' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setParameters }) } } } @@ -563,10 +563,10 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { EmailAddress = 'newemail@contoso.com' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -585,10 +585,10 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { Ensure = 'Absent' } - { Set-TargetResource @setParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -614,7 +614,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { the mocked exception message on top of the original message. #> { Set-TargetResource @setParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } $mockInvalidOperationForCreateMethod = $false @@ -644,7 +644,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { the mocked exception message on top of the original message. #> { Set-TargetResource @setParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } $mockInvalidOperationForAlterMethod = $false @@ -673,7 +673,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { the mocked exception message on top of the original message. #> { Set-TargetResource @setParameters } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } $mockInvalidOperationForDropMethod = $false @@ -698,7 +698,7 @@ Describe 'DSC_SqlAgentOperator\Set-TargetResource' -Tag 'Set' { $errorMessage = $script:localizedData.ConnectServerFailed -f $mockServerName, $mockInstanceName - { Set-TargetResource @setParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + { Set-TargetResource @setParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } } } diff --git a/tests/Unit/DSC_SqlAlias.Tests.ps1 b/tests/Unit/DSC_SqlAlias.Tests.ps1 index a2d9c1db9..ac086b1ac 100644 --- a/tests/Unit/DSC_SqlAlias.Tests.ps1 +++ b/tests/Unit/DSC_SqlAlias.Tests.ps1 @@ -133,36 +133,36 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -Be 'SqlNode.company.local' - $result.Protocol | Should -Be 'TCP' - $result.TcpPort | Should -BeExactly 1433 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Present' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be 'SqlNode.company.local' + $result.Protocol | Should-Be 'TCP' + $result.TcpPort | Should-BeString -CaseSensitive 1433 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -187,36 +187,36 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -BeNullOrEmpty - $result.Protocol | Should -Be '' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Absent' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-BeFalsy + $result.Protocol | Should-Be '' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -243,36 +243,36 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -Be 'SqlNode.company.local' - $result.Protocol | Should -Be 'TCP' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $true - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Present' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be 'SqlNode.company.local' + $result.Protocol | Should-Be 'TCP' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $true + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -297,36 +297,36 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -BeNullOrEmpty - $result.Protocol | Should -Be '' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Absent' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-BeFalsy + $result.Protocol | Should-Be '' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -370,36 +370,36 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -BeNullOrEmpty - $result.Protocol | Should -Be 'NP' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '\\SqlNode\PIPE\sql\query' + $result.Ensure | Should-Be 'Present' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-BeFalsy + $result.Protocol | Should-Be 'NP' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '\\SqlNode\PIPE\sql\query' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -424,36 +424,36 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -BeNullOrEmpty - $result.Protocol | Should -Be '' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Absent' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-BeFalsy + $result.Protocol | Should-Be '' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -485,28 +485,28 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -BeNullOrEmpty - $result.Protocol | Should -Be '' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Absent' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-BeFalsy + $result.Protocol | Should-Be '' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } } @@ -538,28 +538,28 @@ Describe 'SqlAlias\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.ServerName | Should -BeNullOrEmpty - $result.Protocol | Should -Be '' - $result.TcpPort | Should -BeExactly 0 - $result.UseDynamicTcpPort | Should -Be $false - $result.PipeName | Should -Be '' + $result.Ensure | Should-Be 'Absent' + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-BeFalsy + $result.Protocol | Should-Be '' + $result.TcpPort | Should-BeString -CaseSensitive 0 + $result.UseDynamicTcpPort | Should-Be $false + $result.PipeName | Should-Be '' } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } } } @@ -612,12 +612,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -647,12 +647,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -680,12 +680,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } } @@ -717,12 +717,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } } @@ -753,12 +753,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -789,12 +789,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -810,12 +810,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -845,12 +845,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -880,12 +880,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -916,12 +916,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -952,12 +952,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } } @@ -989,12 +989,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -1023,12 +1023,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -1057,12 +1057,12 @@ Describe 'SqlAlias\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } } @@ -1124,32 +1124,32 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.TcpPort = 1433 $script:mockSetTargetResourceParameters.ServerName = 'SqlNode.company.local' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Remove-ItemProperty -Exactly -Times 0 -Scope Context + Should-Invoke -CommandName Remove-ItemProperty -Exactly -Scope Context -Times 0 - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -1164,32 +1164,32 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.UseDynamicTcpPort = $true $script:mockSetTargetResourceParameters.ServerName = 'SqlNode.company.local' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Remove-ItemProperty -Exactly -Times 0 -Scope Context + Should-Invoke -CommandName Remove-ItemProperty -Exactly -Scope Context -Times 0 - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -1203,32 +1203,32 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.Protocol = 'NP' $script:mockSetTargetResourceParameters.ServerName = 'SqlNode.company.local' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Remove-ItemProperty -Exactly -Times 0 -Scope Context + Should-Invoke -CommandName Remove-ItemProperty -Exactly -Scope Context -Times 0 - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 } else { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 } } } @@ -1248,35 +1248,35 @@ Describe 'SqlAlias\Set-TargetResource' { $script:mockSetTargetResourceParameters.Ensure = 'Absent' $script:mockSetTargetResourceParameters.Name = 'MyAlias' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } It 'Should call the correct mocks' { - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { $ClassName -eq 'win32_OperatingSystem' - } -Exactly -Times 1 -Scope Context + } -Scope Context -Times 1 - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPath - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 if ($OSArchitecture -eq '64-bit') { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 - Should -Invoke -CommandName Remove-ItemProperty -Exactly -Times 2 -Scope Context + Should-Invoke -CommandName Remove-ItemProperty -Exactly -Scope Context -Times 2 } else { - Should -Invoke -CommandName Set-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Set-ItemProperty -Exactly -ParameterFilter { $Path -eq $mockRegistryPathWow6432Node - } -Exactly -Times 0 -Scope Context + } -Scope Context -Times 0 - Should -Invoke -CommandName Remove-ItemProperty -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Remove-ItemProperty -Exactly -Scope Context -Times 1 } } } diff --git a/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 b/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 index 735438d7e..ca5bd4a3b 100644 --- a/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 +++ b/tests/Unit/DSC_SqlAlwaysOnService.Tests.ps1 @@ -119,10 +119,10 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -131,8 +131,8 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -142,8 +142,8 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be $mockGetTargetResourceParameters.Ensure - $result.RestartTimeout | Should -Not -BeNullOrEmpty + $result.Ensure | Should-Be $mockGetTargetResourceParameters.Ensure + $result.RestartTimeout | Should-BeTruthy } } } @@ -170,10 +170,10 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -182,8 +182,8 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -193,8 +193,8 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be $mockGetTargetResourceParameters.Ensure - $result.RestartTimeout | Should -Not -BeNullOrEmpty + $result.Ensure | Should-Be $mockGetTargetResourceParameters.Ensure + $result.RestartTimeout | Should-BeTruthy } } } @@ -221,10 +221,10 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return that HADR is disabled' { @@ -234,10 +234,10 @@ Describe 'SqlAlwaysOnService\Get-TargetResource' { # Get the current state $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -292,10 +292,10 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -320,10 +320,10 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -361,10 +361,10 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -389,10 +389,10 @@ Describe 'SqlAlwaysOnService\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -446,12 +446,12 @@ 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 - Should -Invoke -CommandName Disable-SqlAlwaysOn -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Restart-SqlService -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disable-SqlAlwaysOn -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -470,12 +470,12 @@ 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 - Should -Invoke -CommandName Enable-SqlAlwaysOn -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Restart-SqlService -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Enable-SqlAlwaysOn -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -500,7 +500,7 @@ Describe 'SqlAlwaysOnService\Set-TargetResource' { $script:mockSetTargetResourceParameters.InstanceName ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } diff --git a/tests/Unit/DSC_SqlConfiguration.Tests.ps1 b/tests/Unit/DSC_SqlConfiguration.Tests.ps1 index c9296f25e..933e41a28 100644 --- a/tests/Unit/DSC_SqlConfiguration.Tests.ps1 +++ b/tests/Unit/DSC_SqlConfiguration.Tests.ps1 @@ -102,17 +102,17 @@ Describe 'SqlConfiguration\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.OptionName | Should -Be $mockGetTargetResourceParameters.OptionName - $result.OptionValue | Should -Be $mockGetTargetResourceParameters.OptionValue - $result.RestartService | Should -Be $mockGetTargetResourceParameters.RestartService - $result.RestartTimeout | Should -Be $mockGetTargetResourceParameters.RestartTimeout + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.OptionName | Should-Be $mockGetTargetResourceParameters.OptionName + $result.OptionValue | Should-Be $mockGetTargetResourceParameters.OptionValue + $result.RestartService | Should-Be $mockGetTargetResourceParameters.RestartService + $result.RestartTimeout | Should-Be $mockGetTargetResourceParameters.RestartTimeout } } It 'Should call Connect-SQL mock when getting the current state' { - Should -Invoke -CommandName Connect-SQL -Scope Context -Times 1 + Should-Invoke -CommandName Connect-SQL -Scope Context -Times 1 } } @@ -132,7 +132,7 @@ Describe 'SqlConfiguration\Get-TargetResource' { $errorMessage = ($script:localizedData.ConfigurationOptionNotFound -f $mockGetTargetResourceParameters.OptionName) + " (Parameter 'OptionName')" - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage $errorMessage + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage $errorMessage } } } @@ -168,10 +168,10 @@ Describe 'SqlConfiguration\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Scope It -Times 1 + Should-Invoke -CommandName Get-TargetResource -Scope It -Times 1 } } @@ -191,10 +191,10 @@ Describe 'SqlConfiguration\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Scope It -Times 1 + Should-Invoke -CommandName Get-TargetResource -Scope It -Times 1 } } } @@ -258,20 +258,20 @@ Describe 'SqlConfiguration\Set-TargetResource' { RestartTimeout = 120 } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $script:mockAlterMethodCallCount | Should -Be 1 + $script:mockAlterMethodCallCount | Should-Be 1 } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 if ($IsDynamic) { - Should -Invoke -CommandName Write-Warning -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 0 } else { - Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 1 } } @@ -289,18 +289,18 @@ Describe 'SqlConfiguration\Set-TargetResource' { RestartTimeout = 120 } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } if ($IsDynamic) { - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Write-Warning -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 0 } else { - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Write-Warning -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 0 } } } @@ -343,7 +343,7 @@ Describe 'SqlConfiguration\Set-TargetResource' { $errorMessage = ($script:localizedData.ConfigurationOptionNotFound -f 'InvalidOptionName') + " (Parameter 'OptionName')" - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage $errorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage $errorMessage } } } diff --git a/tests/Unit/DSC_SqlDatabase.Tests.ps1 b/tests/Unit/DSC_SqlDatabase.Tests.ps1 index 18c6d6747..e9d48e02b 100644 --- a/tests/Unit/DSC_SqlDatabase.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabase.Tests.ps1 @@ -121,10 +121,10 @@ Describe 'SqlDatabase\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -133,9 +133,9 @@ Describe 'SqlDatabase\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -145,10 +145,10 @@ Describe 'SqlDatabase\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Collation | Should -BeNullOrEmpty - $result.CompatibilityLevel | Should -BeNullOrEmpty - $result.RecoveryModel | Should -BeNullOrEmpty - $result.Owner | Should -BeNullOrEmpty + $result.Collation | Should-BeFalsy + $result.CompatibilityLevel | Should-BeFalsy + $result.RecoveryModel | Should-BeFalsy + $result.Owner | Should-BeFalsy } } } @@ -166,10 +166,10 @@ Describe 'SqlDatabase\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -178,9 +178,9 @@ Describe 'SqlDatabase\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -190,10 +190,10 @@ Describe 'SqlDatabase\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Collation | Should -Be 'SQL_Latin1_General_CP1_CS_AS' - $result.CompatibilityLevel | Should -Be 'Version130' - $result.RecoveryModel | Should -Be 'Full' - $result.OwnerName | Should -Be 'sa' + $result.Collation | Should-Be 'SQL_Latin1_General_CP1_CS_AS' + $result.CompatibilityLevel | Should-Be 'Version130' + $result.RecoveryModel | Should-Be 'Full' + $result.OwnerName | Should-Be 'sa' } } } @@ -243,10 +243,10 @@ Describe 'SqlDatabase\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -272,10 +272,10 @@ Describe 'SqlDatabase\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -320,10 +320,10 @@ Describe 'SqlDatabase\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -353,10 +353,10 @@ Describe 'SqlDatabase\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -384,10 +384,10 @@ Describe 'SqlDatabase\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -432,10 +432,10 @@ Describe 'SqlDatabase\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -592,12 +592,12 @@ 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 + $script:newObjectMethodCreateWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } Context 'When creating the database and setting property ' -ForEach @( @@ -628,17 +628,17 @@ 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 + $script:newObjectMethodCreateWasCalled | Should-Be 1 if ($PropertyName -eq 'OwnerName') { - $script:newObjectMethodSetOwnerWasCalled | Should -Be 1 + $script:newObjectMethodSetOwnerWasCalled | Should-Be 1 } } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should throw the correct error message when method Create() fails' { @@ -653,7 +653,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $mockErrorMessage = $script:localizedData.FailedToCreateDatabase -f 'NewDatabase' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw ('*' + $mockErrorMessage + '*') } $mockInvalidOperationForCreateMethod = $false @@ -672,12 +672,12 @@ Describe 'SqlDatabase\Set-TargetResource' { $script:mockSetTargetResourceParameters['Ensure'] = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $script:methodDropWasCalled | Should -Be 1 + $script:methodDropWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should throw the correct error if the database cannot be dropped' { @@ -690,10 +690,10 @@ Describe 'SqlDatabase\Set-TargetResource' { $mockErrorMessage = $script:localizedData.FailedToDropDatabase -f 'AdventureWorks' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 $mockInvalidOperationForDropMethod = $false } @@ -723,12 +723,12 @@ Describe 'SqlDatabase\Set-TargetResource' { $script:mockSetTargetResourceParameters[$PropertyName] = $PropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $script:methodAlterWasCalled | Should -Be 1 + $script:methodAlterWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should throw the correct error message when method Alter() fails' { @@ -743,7 +743,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $mockErrorMessage = $script:localizedData.FailedToUpdateDatabase -f 'AdventureWorks' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw ('*' + $mockErrorMessage + '*') } $mockInvalidOperationForAlterMethod = $false @@ -759,7 +759,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $mockErrorMessage = $script:localizedData.InvalidCompatibilityLevel -f $mockSetTargetResourceParameters.CompatibilityLevel, 'MSSQLSERVER' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw ('*' + $mockErrorMessage) } } } @@ -773,7 +773,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $mockErrorMessage = $script:localizedData.InvalidCollation -f $mockSetTargetResourceParameters.Collation, 'MSSQLSERVER' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw ('*' + $mockErrorMessage) } } } @@ -795,7 +795,7 @@ Describe 'SqlDatabase\Set-TargetResource' { $mockErrorMessage = $script:localizedData.FailedToUpdateOwner -f 'NewOwner', 'AdventureWorks' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw ('*' + $mockErrorMessage + '*') } } } diff --git a/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 index a6de856ba..d13154852 100644 --- a/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseDefaultLocation.Tests.ps1 @@ -137,14 +137,14 @@ Describe 'SqlDatabaseDefaultLocation\Get-TargetResource' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters -Type $Type -Path $Path # Ending backslash is removed because of regression test for issue #1307. - $getTargetResourceResult.Path | Should -Be $Path - $getTargetResourceResult.Type | Should -Be $Type - $getTargetResourceResult.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $getTargetResourceResult.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $getTargetResourceResult.IsActiveNode | Should -BeTrue + $getTargetResourceResult.Path | Should-Be $Path + $getTargetResourceResult.Type | Should-Be $Type + $getTargetResourceResult.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $getTargetResourceResult.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $getTargetResourceResult.IsActiveNode | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -201,10 +201,10 @@ Describe 'SqlDatabaseDefaultLocation\Test-TargetResource' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters -Type $Type -Path $Path - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -238,10 +238,10 @@ Describe 'SqlDatabaseDefaultLocation\Test-TargetResource' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -280,10 +280,10 @@ Describe 'SqlDatabaseDefaultLocation\Test-TargetResource' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters -Type $Type -Path $Path - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -319,10 +319,10 @@ Describe 'SqlDatabaseDefaultLocation\Test-TargetResource' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -Be $ExpectedReturnValue + $testTargetResourceResult | Should-Be $ExpectedReturnValue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -401,12 +401,12 @@ 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 }) - $script:methodAlterWasCalled | Should -Be 1 + $script:methodAlterWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -419,12 +419,12 @@ Describe 'SqlDatabaseDefaultLocation\Set-TargetResource' { $mockErrorMessage = $script:localizedData.ChangingPathFailed - { Set-TargetResource @mockGetTargetResourceParameters -Type 'Data' -Path 'C:\AnyPath' } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockGetTargetResourceParameters -Type 'Data' -Path 'C:\AnyPath' } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:methodAlterWasCalled | Should -Be 0 + $script:methodAlterWasCalled | Should-Be 0 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 $mockInvalidOperationForAlterMethod = $false } @@ -443,12 +443,12 @@ Describe 'SqlDatabaseDefaultLocation\Set-TargetResource' { $mockGetTargetResourceParameters.Path = 'C:\AnyPath' $mockGetTargetResourceParameters.RestartService = $true - { Set-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockGetTargetResourceParameters }) - $script:methodAlterWasCalled | Should -Be 1 + $script:methodAlterWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -465,12 +465,12 @@ Describe 'SqlDatabaseDefaultLocation\Set-TargetResource' { $mockErrorMessage = $script:localizedData.InvalidPath -f 'C:\AnyPath' - { Set-TargetResource @mockGetTargetResourceParameters -Type 'Data' -Path 'C:\AnyPath' } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockGetTargetResourceParameters -Type 'Data' -Path 'C:\AnyPath' } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:methodAlterWasCalled | Should -Be 0 + $script:methodAlterWasCalled | Should-Be 0 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } } } diff --git a/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 index f9803e2ee..eb50110ca 100644 --- a/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseMail.Tests.ps1 @@ -172,40 +172,40 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Ensure | Should -Be 'Absent' + $getTargetResourceResult.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return $null for the rest of the properties' { InModuleScope -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.AccountName | Should -BeNullOrEmpty - $getTargetResourceResult.EmailAddress | Should -BeNullOrEmpty - $getTargetResourceResult.MailServerName | Should -BeNullOrEmpty - $getTargetResourceResult.LoggingLevel | Should -BeNullOrEmpty - $getTargetResourceResult.ProfileName | Should -BeNullOrEmpty - $getTargetResourceResult.DisplayName | Should -BeNullOrEmpty - $getTargetResourceResult.ReplyToAddress | Should -BeNullOrEmpty - $getTargetResourceResult.Description | Should -BeNullOrEmpty - $getTargetResourceResult.TcpPort | Should -BeNullOrEmpty - $getTargetResourceResult.UseDefaultCredentials | Should -BeNullOrEmpty + $getTargetResourceResult.AccountName | Should-BeFalsy + $getTargetResourceResult.EmailAddress | Should-BeFalsy + $getTargetResourceResult.MailServerName | Should-BeFalsy + $getTargetResourceResult.LoggingLevel | Should-BeFalsy + $getTargetResourceResult.ProfileName | Should-BeFalsy + $getTargetResourceResult.DisplayName | Should-BeFalsy + $getTargetResourceResult.ReplyToAddress | Should-BeFalsy + $getTargetResourceResult.Description | Should-BeFalsy + $getTargetResourceResult.TcpPort | Should-BeFalsy + $getTargetResourceResult.UseDefaultCredentials | Should-BeFalsy } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call all verifiable mocks' { @@ -241,21 +241,21 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Ensure | Should -Be 'Present' + $getTargetResourceResult.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { InModuleScope -ScriptBlock { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the correct values for the rest of the properties' { @@ -275,19 +275,19 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -Parameters $inModuleScopeParameters -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.AccountName | Should -Be $MockAccountName - $getTargetResourceResult.EmailAddress | Should -Be $MockEmailAddress - $getTargetResourceResult.MailServerName | Should -Be $MockMailServerName - $getTargetResourceResult.LoggingLevel | Should -Be $MockLoggingLevel - $getTargetResourceResult.ProfileName | Should -Be $MockProfileName - $getTargetResourceResult.DisplayName | Should -Be $MockDisplayName - $getTargetResourceResult.ReplyToAddress | Should -Be $MockReplyToAddress - $getTargetResourceResult.Description | Should -Be $MockDescription - $getTargetResourceResult.TcpPort | Should -Be $MockTcpPort - $getTargetResourceResult.UseDefaultCredentials | Should -Be $MockUseDefaultCredentials + $getTargetResourceResult.AccountName | Should-Be $MockAccountName + $getTargetResourceResult.EmailAddress | Should-Be $MockEmailAddress + $getTargetResourceResult.MailServerName | Should-Be $MockMailServerName + $getTargetResourceResult.LoggingLevel | Should-Be $MockLoggingLevel + $getTargetResourceResult.ProfileName | Should-Be $MockProfileName + $getTargetResourceResult.DisplayName | Should-Be $MockDisplayName + $getTargetResourceResult.ReplyToAddress | Should-Be $MockReplyToAddress + $getTargetResourceResult.Description | Should-Be $MockDescription + $getTargetResourceResult.TcpPort | Should-Be $MockTcpPort + $getTargetResourceResult.UseDefaultCredentials | Should-Be $MockUseDefaultCredentials } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -335,7 +335,7 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -Parameters $inModuleScopeParameters -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.LoggingLevel | Should -Be $MockLoggingLevel + $getTargetResourceResult.LoggingLevel | Should-Be $MockLoggingLevel } } } @@ -351,7 +351,7 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Description | Should -BeNullOrEmpty + $getTargetResourceResult.Description | Should-BeFalsy } } } @@ -367,8 +367,8 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Ensure | Should -Be 'Absent' - $getTargetResourceResult.AccountName | Should -BeNullOrEmpty + $getTargetResourceResult.Ensure | Should-Be 'Absent' + $getTargetResourceResult.AccountName | Should-BeFalsy } } } @@ -399,7 +399,7 @@ Describe 'DSC_SqlDatabaseMail\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Ensure | Should -Be 'Absent' + $getTargetResourceResult.Ensure | Should-Be 'Absent' } } } @@ -449,10 +449,10 @@ Describe 'DSC_SqlDatabaseMail\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -498,10 +498,10 @@ Describe 'DSC_SqlDatabaseMail\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -522,10 +522,10 @@ Describe 'DSC_SqlDatabaseMail\Test-TargetResource' -Tag 'Test' { $testTargetResourceParameters.Ensure = 'Absent' $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -607,10 +607,10 @@ Describe 'DSC_SqlDatabaseMail\Test-TargetResource' -Tag 'Test' { $testTargetResourceParameters.$Property = $PropertyValue $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } It 'Should return the state as $false when is wrong' -ForEach $testCase { @@ -624,10 +624,10 @@ Describe 'DSC_SqlDatabaseMail\Test-TargetResource' -Tag 'Test' { $testTargetResourceParameters.$Property = $PropertyValue $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -861,23 +861,23 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters.AccountName = 'MissingAccount' $setTargetResourceParameters.ProfileName = 'MissingProfile' - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw - - $script:MailAccountCreateMethodCallCount | Should -Be 0 - $script:MailServerRenameMethodCallCount | Should -Be 0 - $script:MailServerAlterMethodCallCount | Should -Be 0 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 - $script:MailProfileDropMethodCallCount | Should -Be 0 - $script:MailAccountDropMethodCallCount | Should -Be 0 + $null = & ({ Set-TargetResource @setTargetResourceParameters }) + + $script:MailAccountCreateMethodCallCount | Should-Be 0 + $script:MailServerRenameMethodCallCount | Should-Be 0 + $script:MailServerAlterMethodCallCount | Should-Be 0 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 + $script:MailProfileDropMethodCallCount | Should-Be 0 + $script:MailAccountDropMethodCallCount | Should-Be 0 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -905,23 +905,23 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters['TcpPort'] = $MockTcpPort $setTargetResourceParameters['UseDefaultCredentials'] = $MockUseDefaultCredentials - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw - - $script:MailAccountCreateMethodCallCount | Should -Be 0 - $script:MailServerRenameMethodCallCount | Should -Be 0 - $script:MailServerAlterMethodCallCount | Should -Be 0 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 - $script:MailProfileDropMethodCallCount | Should -Be 0 - $script:MailAccountDropMethodCallCount | Should -Be 0 + $null = & ({ Set-TargetResource @setTargetResourceParameters }) + + $script:MailAccountCreateMethodCallCount | Should-Be 0 + $script:MailServerRenameMethodCallCount | Should-Be 0 + $script:MailServerAlterMethodCallCount | Should-Be 0 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 + $script:MailProfileDropMethodCallCount | Should-Be 0 + $script:MailAccountDropMethodCallCount | Should-Be 0 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -937,11 +937,11 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters = $mockDefaultParameters.Clone() $setTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:JobServerAlterMethodCallCount | Should -Be 1 - $script:MailProfileDropMethodCallCount | Should -Be 1 - $script:MailAccountDropMethodCallCount | Should -Be 1 + $script:JobServerAlterMethodCallCount | Should-Be 1 + $script:MailProfileDropMethodCallCount | Should-Be 1 + $script:MailAccountDropMethodCallCount | Should-Be 1 } } } @@ -966,10 +966,10 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters = $mockDefaultParameters.Clone() Set-TargetResource @setTargetResourceParameters - } | Should -Throw $mockErrorRecord.Exception.Message + } | Should-Throw $mockErrorRecord.Exception.Message } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -995,21 +995,21 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters['TcpPort'] = 2525 $setTargetResourceParameters['UseDefaultCredentials'] = $true - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw - - $script:MailAccountCreateMethodCallCount | Should -Be 1 - $script:MailServerRenameMethodCallCount | Should -Be 1 - $script:MailServerAlterMethodCallCount | Should -Be 1 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 1 - $script:MailProfileAlterMethodCallCount | Should -Be 1 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 1 - $script:MailProfileAddAccountMethodCallCount | Should -Be 1 - $script:JobServerAlterMethodCallCount | Should -Be 1 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 + $null = & ({ Set-TargetResource @setTargetResourceParameters }) + + $script:MailAccountCreateMethodCallCount | Should-Be 1 + $script:MailServerRenameMethodCallCount | Should-Be 1 + $script:MailServerAlterMethodCallCount | Should-Be 1 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 1 + $script:MailProfileAlterMethodCallCount | Should-Be 1 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 1 + $script:MailProfileAddAccountMethodCallCount | Should-Be 1 + $script:JobServerAlterMethodCallCount | Should-Be 1 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1070,73 +1070,73 @@ Describe 'DSC_SqlDatabaseMail\Set-TargetResource' -Tag 'Set' { $setTargetResourceParameters.$Property = $PropertyValue - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:MailAccountCreateMethodCallCount | Should -Be 0 + $script:MailAccountCreateMethodCallCount | Should-Be 0 if ($Property -eq 'MailServerName') { - $script:MailServerRenameMethodCallCount | Should -Be 1 - $script:MailServerAlterMethodCallCount | Should -Be 1 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 + $script:MailServerRenameMethodCallCount | Should-Be 1 + $script:MailServerAlterMethodCallCount | Should-Be 1 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 } elseif ($Property -eq 'TcpPort') { - $script:MailServerRenameMethodCallCount | Should -Be 0 - $script:MailServerAlterMethodCallCount | Should -Be 1 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 + $script:MailServerRenameMethodCallCount | Should-Be 0 + $script:MailServerAlterMethodCallCount | Should-Be 1 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 } elseif ($Property -eq 'UseDefaultCredentials') { - $script:MailServerRenameMethodCallCount | Should -Be 0 - $script:MailServerAlterMethodCallCount | Should -Be 1 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 + $script:MailServerRenameMethodCallCount | Should-Be 0 + $script:MailServerAlterMethodCallCount | Should-Be 1 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 } elseif ($Property -eq 'LoggingLevel') { - $script:MailServerRenameMethodCallCount | Should -Be 0 - $script:MailServerAlterMethodCallCount | Should -Be 0 - $script:MailAccountAlterMethodCallCount | Should -Be 0 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 1 + $script:MailServerRenameMethodCallCount | Should-Be 0 + $script:MailServerAlterMethodCallCount | Should-Be 0 + $script:MailAccountAlterMethodCallCount | Should-Be 0 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 1 } else { - $script:MailServerRenameMethodCallCount | Should -Be 0 - $script:MailServerAlterMethodCallCount | Should -Be 0 - $script:MailAccountAlterMethodCallCount | Should -Be 1 - $script:MailProfileCreateMethodCallCount | Should -Be 0 - $script:MailProfileAlterMethodCallCount | Should -Be 0 - $script:MailProfileAddPrincipalMethodCallCount | Should -Be 0 - $script:MailProfileAddAccountMethodCallCount | Should -Be 0 - $script:JobServerAlterMethodCallCount | Should -Be 0 - $script:LoggingLevelAlterMethodCallCount | Should -Be 0 + $script:MailServerRenameMethodCallCount | Should-Be 0 + $script:MailServerAlterMethodCallCount | Should-Be 0 + $script:MailAccountAlterMethodCallCount | Should-Be 1 + $script:MailProfileCreateMethodCallCount | Should-Be 0 + $script:MailProfileAlterMethodCallCount | Should-Be 0 + $script:MailProfileAddPrincipalMethodCallCount | Should-Be 0 + $script:MailProfileAddAccountMethodCallCount | Should-Be 0 + $script:JobServerAlterMethodCallCount | Should-Be 0 + $script:LoggingLevelAlterMethodCallCount | Should-Be 0 } } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 index 6a85b692b..99509711c 100644 --- a/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 @@ -252,13 +252,13 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.ServerName | Should -Be $env:COMPUTERNAME - $getTargetResourceResult.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $getTargetResourceResult.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $getTargetResourceResult.SchemaName | Should -Be $mockGetTargetResourceParameters.SchemaName - $getTargetResourceResult.ObjectName | Should -Be $mockGetTargetResourceParameters.ObjectName - $getTargetResourceResult.ObjectType | Should -Be $mockGetTargetResourceParameters.ObjectType - $getTargetResourceResult.Name | Should -Be $mockGetTargetResourceParameters.Name + $getTargetResourceResult.ServerName | Should-Be $env:COMPUTERNAME + $getTargetResourceResult.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $getTargetResourceResult.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $getTargetResourceResult.SchemaName | Should-Be $mockGetTargetResourceParameters.SchemaName + $getTargetResourceResult.ObjectName | Should-Be $mockGetTargetResourceParameters.ObjectName + $getTargetResourceResult.ObjectType | Should-Be $mockGetTargetResourceParameters.ObjectType + $getTargetResourceResult.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -268,20 +268,20 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Permission | Should -HaveCount 3 - $getTargetResourceResult.Permission[0] | Should -BeOfType 'CimInstance' - $getTargetResourceResult.Permission[1] | Should -BeOfType 'CimInstance' - $getTargetResourceResult.Permission[2] | Should -BeOfType 'CimInstance' + $getTargetResourceResult.Permission | Should-BeCollection -Count 3 + $getTargetResourceResult.Permission[0] | Should-HaveType 'CimInstance' + $getTargetResourceResult.Permission[1] | Should-HaveType 'CimInstance' + $getTargetResourceResult.Permission[2] | Should-HaveType 'CimInstance' $grantPermission = $getTargetResourceResult.Permission | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Ensure[2] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 3 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') - $grantPermission.Permission | Should -Contain @('Insert') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Ensure[2] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 3 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') + $grantPermission.Permission | Should-ContainCollection @('Insert') } } } @@ -430,13 +430,13 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.ServerName | Should -Be $env:COMPUTERNAME - $getTargetResourceResult.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $getTargetResourceResult.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $getTargetResourceResult.SchemaName | Should -Be $mockGetTargetResourceParameters.SchemaName - $getTargetResourceResult.ObjectName | Should -Be $mockGetTargetResourceParameters.ObjectName - $getTargetResourceResult.ObjectType | Should -Be $mockGetTargetResourceParameters.ObjectType - $getTargetResourceResult.Name | Should -Be $mockGetTargetResourceParameters.Name + $getTargetResourceResult.ServerName | Should-Be $env:COMPUTERNAME + $getTargetResourceResult.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $getTargetResourceResult.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $getTargetResourceResult.SchemaName | Should-Be $mockGetTargetResourceParameters.SchemaName + $getTargetResourceResult.ObjectName | Should-Be $mockGetTargetResourceParameters.ObjectName + $getTargetResourceResult.ObjectType | Should-Be $mockGetTargetResourceParameters.ObjectType + $getTargetResourceResult.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -446,14 +446,14 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Permission | Should -HaveCount 1 - $getTargetResourceResult.Permission[0] | Should -BeOfType 'CimInstance' + $getTargetResourceResult.Permission | Should-BeCollection -Count 1 + $getTargetResourceResult.Permission[0] | Should-HaveType 'CimInstance' $grantPermission = $getTargetResourceResult.Permission | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') } } } @@ -496,13 +496,13 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.ServerName | Should -Be $env:COMPUTERNAME - $getTargetResourceResult.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $getTargetResourceResult.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $getTargetResourceResult.SchemaName | Should -Be $mockGetTargetResourceParameters.SchemaName - $getTargetResourceResult.ObjectName | Should -Be $mockGetTargetResourceParameters.ObjectName - $getTargetResourceResult.ObjectType | Should -Be $mockGetTargetResourceParameters.ObjectType - $getTargetResourceResult.Name | Should -Be $mockGetTargetResourceParameters.Name + $getTargetResourceResult.ServerName | Should-Be $env:COMPUTERNAME + $getTargetResourceResult.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $getTargetResourceResult.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $getTargetResourceResult.SchemaName | Should-Be $mockGetTargetResourceParameters.SchemaName + $getTargetResourceResult.ObjectName | Should-Be $mockGetTargetResourceParameters.ObjectName + $getTargetResourceResult.ObjectType | Should-Be $mockGetTargetResourceParameters.ObjectType + $getTargetResourceResult.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -512,14 +512,14 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Permission | Should -HaveCount 1 - $getTargetResourceResult.Permission[0] | Should -BeOfType 'CimInstance' + $getTargetResourceResult.Permission | Should-BeCollection -Count 1 + $getTargetResourceResult.Permission[0] | Should-HaveType 'CimInstance' $grantPermission = $getTargetResourceResult.Permission | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') } } } @@ -562,13 +562,13 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.ServerName | Should -Be $env:COMPUTERNAME - $getTargetResourceResult.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $getTargetResourceResult.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $getTargetResourceResult.SchemaName | Should -Be $mockGetTargetResourceParameters.SchemaName - $getTargetResourceResult.ObjectName | Should -Be $mockGetTargetResourceParameters.ObjectName - $getTargetResourceResult.ObjectType | Should -Be $mockGetTargetResourceParameters.ObjectType - $getTargetResourceResult.Name | Should -Be $mockGetTargetResourceParameters.Name + $getTargetResourceResult.ServerName | Should-Be $env:COMPUTERNAME + $getTargetResourceResult.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $getTargetResourceResult.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $getTargetResourceResult.SchemaName | Should-Be $mockGetTargetResourceParameters.SchemaName + $getTargetResourceResult.ObjectName | Should-Be $mockGetTargetResourceParameters.ObjectName + $getTargetResourceResult.ObjectType | Should-Be $mockGetTargetResourceParameters.ObjectType + $getTargetResourceResult.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -578,15 +578,15 @@ Describe 'SqlDatabaseObjectPermission\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Permission | Should -HaveCount 1 - $getTargetResourceResult.Permission[0] | Should -BeOfType 'CimInstance' + $getTargetResourceResult.Permission | Should-BeCollection -Count 1 + $getTargetResourceResult.Permission[0] | Should-HaveType 'CimInstance' $grantPermission = $getTargetResourceResult.Permission | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Not -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-NotContainCollection @('Delete') } } } @@ -644,9 +644,9 @@ Describe 'SqlDatabaseObjectPermission\Test-TargetResource' -Tag 'Test' { Set-StrictMode -Version 1.0 $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } } @@ -668,9 +668,9 @@ Describe 'SqlDatabaseObjectPermission\Test-TargetResource' -Tag 'Test' { Set-StrictMode -Version 1.0 $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } } @@ -741,67 +741,67 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare It 'Should return the correct metadata for the permission property' { $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeTrue # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 4 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Actual[1] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Actual[2] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Actual[3] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 4 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Actual[1] | Should-HaveType 'CimInstance' + $comparedReturnValue.Actual[2] | Should-HaveType 'CimInstance' + $comparedReturnValue.Actual[3] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Drop') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Drop') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 4 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[2] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[3] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 4 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[2] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[3] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Drop') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Drop') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -863,39 +863,39 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty + $comparedReturnValue | Should-BeTruthy - $comparedReturnValue.Actual | Should -HaveCount 4 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Actual[1] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Actual[2] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Actual[3] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 4 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Actual[1] | Should-HaveType 'CimInstance' + $comparedReturnValue.Actual[2] | Should-HaveType 'CimInstance' + $comparedReturnValue.Actual[3] | Should-HaveType 'CimInstance' # Actual permissions $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Drop') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Drop') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } Context 'When the permission state ''Grant'' is ''Present'' but desired state is ''Absent''' { @@ -938,40 +938,40 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse - $comparedReturnValue.Expected | Should -HaveCount 4 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[2] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[3] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 4 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[2] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[3] | Should-HaveType 'CimInstance' # Expected permissions $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Absent' - $grantPermission.Ensure[1] | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Absent' + $grantPermission.Ensure[1] | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Drop') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Drop') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1015,40 +1015,40 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse - $comparedReturnValue.Expected | Should -HaveCount 4 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[2] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[3] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 4 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[2] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[3] | Should-HaveType 'CimInstance' # Expected permissions $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Drop') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Drop') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1092,40 +1092,40 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse - $comparedReturnValue.Expected | Should -HaveCount 4 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[2] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[3] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 4 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[2] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[3] | Should-HaveType 'CimInstance' # Expected permissions $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Absent' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Delete') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Absent' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Delete') $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Drop') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Drop') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1154,23 +1154,23 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' # Expected permissions $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('CreateTable') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('CreateTable') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1199,23 +1199,23 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' # Expected permissions $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('CreateTable') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('CreateTable') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1244,23 +1244,23 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' # Expected permissions $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('CreateTable') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('CreateTable') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1312,29 +1312,29 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -BeNullOrEmpty + $comparedReturnValue.Actual | Should-BeFalsy # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 2 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 2 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1384,29 +1384,29 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -BeNullOrEmpty + $comparedReturnValue.Actual | Should-BeFalsy # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 2 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 2 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1456,29 +1456,29 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -BeNullOrEmpty + $comparedReturnValue.Actual | Should-BeFalsy # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 2 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' - $comparedReturnValue.Expected[1] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 2 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' + $comparedReturnValue.Expected[1] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure[0] | Should -Be 'Present' - $grantPermission.Ensure[1] | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 2 - $grantPermission.Permission | Should -Contain @('Select') - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure[0] | Should-Be 'Present' + $grantPermission.Ensure[1] | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 2 + $grantPermission.Permission | Should-ContainCollection @('Select') + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1531,33 +1531,33 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 1 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 1 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1608,33 +1608,33 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 1 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 1 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1685,33 +1685,33 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 1 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 1 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1764,33 +1764,33 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 1 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 1 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Update') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1841,33 +1841,33 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 1 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 1 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Update') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'GrantWithGrant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1918,33 +1918,33 @@ Describe 'SqlDatabaseObjectPermission\Compare-TargetResourceState' -Tag 'Compare } $compareTargetResourceStateResult = Compare-TargetResourceState @mockCompareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult | Where-Object -FilterScript { $_.ParameterName -eq 'Permission' } - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.InDesiredState | Should-BeFalse # Actual permissions - $comparedReturnValue.Actual | Should -HaveCount 1 - $comparedReturnValue.Actual[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Actual | Should-BeCollection -Count 1 + $comparedReturnValue.Actual[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Actual | Where-Object -FilterScript { $_.State -eq 'Grant' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Select') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Select') # Expected permissions - $comparedReturnValue.Expected | Should -HaveCount 1 - $comparedReturnValue.Expected[0] | Should -BeOfType 'CimInstance' + $comparedReturnValue.Expected | Should-BeCollection -Count 1 + $comparedReturnValue.Expected[0] | Should-HaveType 'CimInstance' $grantPermission = $comparedReturnValue.Expected | Where-Object -FilterScript { $_.State -eq 'Deny' } - $grantPermission | Should -Not -BeNullOrEmpty - $grantPermission.Ensure | Should -Be 'Present' - $grantPermission.Permission | Should -HaveCount 1 - $grantPermission.Permission | Should -Contain @('Update') + $grantPermission | Should-BeTruthy + $grantPermission.Ensure | Should-Be 'Present' + $grantPermission.Permission | Should-BeCollection -Count 1 + $grantPermission.Permission | Should-ContainCollection @('Update') - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -2008,9 +2008,9 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 0 } } @@ -2073,7 +2073,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DatabaseName ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw $mockErrorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw $mockErrorMessage } } @@ -2168,12 +2168,12 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodGrantRanTimes | Should -Be 1 - $script:mockMethodDenyRanTimes | Should -Be 0 + $script:mockMethodGrantRanTimes | Should-Be 1 + $script:mockMethodDenyRanTimes | Should-Be 0 } # Regression test for issue #1602. @@ -2215,7 +2215,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DatabaseName ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw } } @@ -2225,13 +2225,13 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodRevokeRanTimes | Should -Be 1 - $script:mockMethodGrantRanTimes | Should -Be 1 - $script:mockMethodDenyRanTimes | Should -Be 0 + $script:mockMethodRevokeRanTimes | Should-Be 1 + $script:mockMethodGrantRanTimes | Should-Be 1 + $script:mockMethodDenyRanTimes | Should-Be 0 } } } @@ -2293,12 +2293,12 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodGrantRanTimes | Should -Be 1 - $script:mockMethodDenyRanTimes | Should -Be 0 + $script:mockMethodGrantRanTimes | Should-Be 1 + $script:mockMethodDenyRanTimes | Should-Be 0 } } @@ -2358,12 +2358,12 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodGrantRanTimes | Should -Be 0 - $script:mockMethodDenyRanTimes | Should -Be 1 + $script:mockMethodGrantRanTimes | Should-Be 0 + $script:mockMethodDenyRanTimes | Should-Be 1 } } @@ -2436,12 +2436,12 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodGrantRanTimes | Should -Be 0 - $script:mockMethodDenyRanTimes | Should -Be 1 + $script:mockMethodGrantRanTimes | Should-Be 0 + $script:mockMethodDenyRanTimes | Should-Be 1 } } } @@ -2529,11 +2529,11 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodRevokeRanTimes | Should -Be 1 + $script:mockMethodRevokeRanTimes | Should-Be 1 } } @@ -2582,11 +2582,11 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodRevokeRanTimes | Should -Be 1 + $script:mockMethodRevokeRanTimes | Should-Be 1 } } @@ -2635,11 +2635,11 @@ 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 }) - Should -Invoke -CommandName Get-DatabaseObject -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-DatabaseObject -Exactly -Scope It -Times 1 - $script:mockMethodRevokeRanTimes | Should -Be 1 + $script:mockMethodRevokeRanTimes | Should-Be 1 } } } @@ -2720,7 +2720,7 @@ Describe 'SqlDatabaseObjectPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DatabaseName ) - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw $mockErrorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw $mockErrorMessage } } } @@ -2787,7 +2787,7 @@ Describe 'SqlDatabaseObjectPermission\Get-DatabaseObject' -Tag 'Helper' { } # The methods that was mocked returns the expect object type. - Get-DatabaseObject @getDatabaseObjectParameters | Should -Be $ObjectType + Get-DatabaseObject @getDatabaseObjectParameters | Should-Be $ObjectType } } } diff --git a/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 index 875035e79..b02df389f 100644 --- a/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 @@ -151,12 +151,12 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $errorMessage = $script:localizedData.DatabaseNotFound -f $mockGetTargetResourceParameters.DatabaseName - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } } It 'Should call the mock function Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } @@ -173,10 +173,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as null' { @@ -184,10 +184,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Members | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -195,13 +195,13 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -218,14 +218,14 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call the mock function Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } @@ -243,10 +243,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as null' { @@ -255,10 +255,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Members | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -267,13 +267,13 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return $false for the property DatabaseIsUpdateable' { @@ -282,7 +282,7 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseIsUpdateable | Should -BeFalse + $result.DatabaseIsUpdateable | Should-BeFalse } } } @@ -307,12 +307,12 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $errorMessage = $script:localizedData.EnumDatabaseRoleMemberNamesError -f 'MyRole', 'AdventureWorks' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage + '*') + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage + '*') } } It 'Should call the mock function Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } @@ -330,10 +330,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return MembersInDesiredState as True' { @@ -341,10 +341,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.MembersInDesiredState | Should -BeTrue + $result.MembersInDesiredState | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as not null' { @@ -352,10 +352,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Members | Should -Be $mockGetTargetResourceParameters.Members + $result.Members | Should-Be $mockGetTargetResourceParameters.Members } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as string array' { @@ -363,10 +363,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - ($result.Members -is [System.String[]]) | Should -BeTrue + ($result.Members -is [System.String[]]) | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -374,14 +374,14 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.Members | Should -Be $mockGetTargetResourceParameters.Members + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.Members | Should-Be $mockGetTargetResourceParameters.Members } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -399,10 +399,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return MembersInDesiredState as False' { @@ -410,10 +410,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.MembersInDesiredState | Should -BeFalse + $result.MembersInDesiredState | Should-BeFalse } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as string array' { @@ -421,10 +421,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - ($result.Members -is [System.String[]]) | Should -BeTrue + ($result.Members -is [System.String[]]) | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -444,12 +444,12 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $errorMessage = $script:localizedData.MembersToIncludeAndExcludeParamMustBeNull - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } } It 'Should call the mock function Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } @@ -467,10 +467,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return MembersInDesiredState as True' { @@ -478,10 +478,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.MembersInDesiredState | Should -BeTrue + $result.MembersInDesiredState | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as not null' { @@ -489,10 +489,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Members | Should -Not -BeNullOrEmpty + $result.Members | Should-BeTruthy } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as string array' { @@ -500,10 +500,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - ($result.Members -is [System.String[]]) | Should -BeTrue + ($result.Members -is [System.String[]]) | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -511,14 +511,14 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.MembersToInclude | Should -Be $mockGetTargetResourceParameters.MembersToInclude + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.MembersToInclude | Should-Be $mockGetTargetResourceParameters.MembersToInclude } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -536,10 +536,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return MembersInDesiredState as False' { @@ -547,10 +547,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.MembersInDesiredState | Should -BeFalse + $result.MembersInDesiredState | Should-BeFalse } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as string array' { @@ -558,10 +558,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - ($result.Members -is [System.String[]]) | Should -BeTrue + ($result.Members -is [System.String[]]) | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -582,12 +582,12 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { $errorMessage = $script:localizedData.MembersToIncludeAndExcludeParamMustBeNull - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } } It 'Should call the mock function Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } @@ -605,10 +605,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return MembersInDesiredState as True' { @@ -616,10 +616,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.MembersInDesiredState | Should -BeTrue + $result.MembersInDesiredState | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the same values as passed as parameters' { @@ -627,14 +627,14 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.MembersToExclude | Should -Be $mockGetTargetResourceParameters.MembersToExclude + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.MembersToExclude | Should-Be $mockGetTargetResourceParameters.MembersToExclude } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -652,10 +652,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return MembersInDesiredState as False' { @@ -663,10 +663,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.MembersInDesiredState | Should -BeFalse + $result.MembersInDesiredState | Should-BeFalse } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return the members as string array' { @@ -674,10 +674,10 @@ Describe 'SqlDatabaseRole\Get-TargetResource' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - ($result.Members -is [System.String[]]) | Should -BeTrue + ($result.Members -is [System.String[]]) | Should-BeTrue } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -720,10 +720,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -747,10 +747,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -777,10 +777,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -805,10 +805,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -833,10 +833,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -861,10 +861,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'the database is not updatable' + $result | Should-BeTrue -Because 'the database is not updatable' } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -888,10 +888,10 @@ Describe 'SqlDatabaseRole\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'the database is not updatable' + $result | Should-BeTrue -Because 'the database is not updatable' } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -999,12 +999,12 @@ 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 + $mockMethodDropWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1023,10 +1023,10 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $errorMessage +'*Mock Drop method was called with invalid operation.*') + } | Should-Throw -ExceptionMessage ('*' + $errorMessage +'*Mock Drop method was called with invalid operation.*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 $mockInvalidOperationForDropMethod = $false } @@ -1041,16 +1041,16 @@ 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 + $mockMethodCreateWasCalled | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 - Should -Invoke -CommandName New-Object -Exactly -Times 1 -ParameterFilter { + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.DatabaseRole' - } -Scope Context + } -Scope Context -Times 1 } } @@ -1069,10 +1069,10 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $errorMessage +'*Mock Create method was called with invalid operation.*') + } | Should-Throw -ExceptionMessage ('*' + $errorMessage +'*Mock Create method was called with invalid operation.*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 $mockInvalidOperationForCreateMethod = $false } @@ -1093,10 +1093,10 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1115,10 +1115,10 @@ Describe 'SqlDatabaseRole\Set-TargetResource' -Tag 'Set' { { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1141,18 +1141,18 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Add-SqlDscDatabaseRoleMember -ParameterFilter { + Should-Invoke -CommandName Add-SqlDscDatabaseRoleMember -Exactly -ParameterFilter { $MemberName -eq 'CONTOSO\SQLAdmin' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Remove-SqlDscDatabaseRoleMember -ParameterFilter { + Should-Invoke -CommandName Remove-SqlDscDatabaseRoleMember -Exactly -ParameterFilter { $MemberName -eq 'CONTOSO\KingJulian' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1175,16 +1175,16 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Add-SqlDscDatabaseRoleMember -ParameterFilter { + Should-Invoke -CommandName Add-SqlDscDatabaseRoleMember -Exactly -ParameterFilter { $MemberName -eq 'CONTOSO\SQLAdmin' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Remove-SqlDscDatabaseRoleMember -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Remove-SqlDscDatabaseRoleMember -Exactly -Scope It -Times 0 } } @@ -1207,14 +1207,14 @@ 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 - Should -Invoke -CommandName Add-SqlDscDatabaseRoleMember -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Remove-SqlDscDatabaseRoleMember -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Add-SqlDscDatabaseRoleMember -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Remove-SqlDscDatabaseRoleMember -Exactly -ParameterFilter { $MemberName -eq 'CONTOSO\KingJulian' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1272,7 +1272,7 @@ Describe 'Add-SqlDscDatabaseRoleMember' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.DatabaseRoleOrUserNotFound -f 'MissingRole', 'MissingUser', 'AdventureWorks' { Add-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MissingRole' -MemberName 'MissingUser' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -1288,11 +1288,11 @@ Describe 'Add-SqlDscDatabaseRoleMember' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { + $null = & ({ Add-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'John' - } | Should -Not -Throw + }) - $mockMethodAddMemberWasCalled | Should -Be 1 + $mockMethodAddMemberWasCalled | Should-Be 1 } } } @@ -1318,7 +1318,7 @@ Describe 'Add-SqlDscDatabaseRoleMember' -Tag 'Helper' { { Add-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'John' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*Mock AddMember Method was called with invalid operation.*') + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*Mock AddMember Method was called with invalid operation.*') } } } @@ -1379,11 +1379,11 @@ Describe 'Remove-SqlDscDatabaseRoleMember' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { + $null = & ({ Remove-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'MyRole' - } | Should -Not -Throw + }) - $mockMethodDropMemberWasCalled | Should -Be 1 + $mockMethodDropMemberWasCalled | Should-Be 1 } } } @@ -1409,7 +1409,7 @@ Describe 'Remove-SqlDscDatabaseRoleMember' -Tag 'Helper' { { Remove-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name 'MyRole' -MemberName 'MyRole' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*Mock DropMember Method was called with invalid operation.*') + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*Mock DropMember Method was called with invalid operation.*') } } } diff --git a/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 index a61786929..5a3410c02 100644 --- a/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseUser.Tests.ps1 @@ -122,7 +122,7 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { } AfterEach { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } Context 'When the system is in the desired state' { @@ -139,7 +139,7 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Ensure | Should -Be 'Absent' + $getTargetResourceResult.Ensure | Should-Be 'Absent' } } @@ -149,10 +149,10 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be 'MissingUser1' + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be 'MissingUser1' } } @@ -162,12 +162,12 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.LoginName | Should -BeNullOrEmpty - $getTargetResourceResult.AsymmetricKeyName | Should -BeNullOrEmpty - $getTargetResourceResult.CertificateName | Should -BeNullOrEmpty - $getTargetResourceResult.AuthenticationType | Should -BeNullOrEmpty - $getTargetResourceResult.LoginType | Should -BeNullOrEmpty - $getTargetResourceResult.UserType | Should -BeNullOrEmpty + $getTargetResourceResult.LoginName | Should-BeFalsy + $getTargetResourceResult.AsymmetricKeyName | Should-BeFalsy + $getTargetResourceResult.CertificateName | Should-BeFalsy + $getTargetResourceResult.AuthenticationType | Should-BeFalsy + $getTargetResourceResult.LoginType | Should-BeFalsy + $getTargetResourceResult.UserType | Should-BeFalsy } } @@ -177,7 +177,7 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.DatabaseIsUpdateable | Should -BeTrue + $getTargetResourceResult.DatabaseIsUpdateable | Should-BeTrue } } } @@ -189,7 +189,7 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Ensure | Should -Be 'Present' + $getTargetResourceResult.Ensure | Should-Be 'Present' } } @@ -199,10 +199,10 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.DatabaseName | Should -Be $mockGetTargetResourceParameters.DatabaseName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.DatabaseName | Should-Be $mockGetTargetResourceParameters.DatabaseName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name } } @@ -212,12 +212,12 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.LoginName | Should -Be 'CONTOSO\Login1' - $getTargetResourceResult.AsymmetricKeyName | Should -Be 'AsymmetricKey1' - $getTargetResourceResult.CertificateName | Should -Be 'Certificate1' - $getTargetResourceResult.AuthenticationType | Should -Be 'Windows' - $getTargetResourceResult.LoginType | Should -Be 'WindowsUser' - $getTargetResourceResult.UserType | Should -Be 'Login' + $getTargetResourceResult.LoginName | Should-Be 'CONTOSO\Login1' + $getTargetResourceResult.AsymmetricKeyName | Should-Be 'AsymmetricKey1' + $getTargetResourceResult.CertificateName | Should-Be 'Certificate1' + $getTargetResourceResult.AuthenticationType | Should-Be 'Windows' + $getTargetResourceResult.LoginType | Should-Be 'WindowsUser' + $getTargetResourceResult.UserType | Should-Be 'Login' } } @@ -227,7 +227,7 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.DatabaseIsUpdateable | Should -BeTrue + $getTargetResourceResult.DatabaseIsUpdateable | Should-BeTrue } } } @@ -250,7 +250,7 @@ Describe 'SqlDatabaseUser\Get-TargetResource' -Tag 'Get' { { Get-TargetResource @mockGetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -308,10 +308,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -347,10 +347,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -387,10 +387,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -417,10 +417,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -451,10 +451,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -483,10 +483,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { Set-StrictMode -Version 1.0 $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -516,10 +516,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -549,10 +549,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -583,10 +583,10 @@ Describe 'SqlDatabaseUser\Test-TargetResource' -Tag 'Test' { $testTargetResourceResult = Test-TargetResource @mockTestTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -647,11 +647,11 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 0 } } @@ -685,11 +685,11 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 0 } } } @@ -724,13 +724,13 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('DROP USER [{0}];' -f 'DatabaseUser1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } Context 'When trying to drop a database user but Invoke-SqlDscQuery fails' { @@ -753,11 +753,11 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.FailedDropDatabaseUser -f 'DatabaseUser1', 'TestDB' { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw ('*' + $mockErrorMessage + '*') + } | Should-Throw ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } } @@ -800,17 +800,17 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR LOGIN [{1}];' -f 'DatabaseUser1', 'CONTOSO\Login1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Assert-SqlLogin -ParameterFilter { + Should-Invoke -CommandName Assert-SqlLogin -Exactly -ParameterFilter { $ServerName -eq (Get-ComputerName) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -832,17 +832,17 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR LOGIN [{1}];' -f 'DatabaseUser1', 'CONTOSO\Login1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Assert-SqlLogin -ParameterFilter { + Should-Invoke -CommandName Assert-SqlLogin -Exactly -ParameterFilter { $ServerName -eq 'host.company.local' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -858,13 +858,13 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] WITHOUT LOGIN;' -f 'DatabaseUser1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -880,13 +880,13 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR CERTIFICATE [{1}];' -f 'DatabaseUser1', 'Certificate1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -902,13 +902,13 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR ASYMMETRIC KEY [{1}];' -f 'DatabaseUser1', 'AsymmetricKey1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -933,11 +933,11 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } } @@ -980,17 +980,17 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('ALTER USER [{0}] WITH NAME = [{1}], LOGIN = [{2}];' -f 'DatabaseUser1', 'DatabaseUser1', 'OtherLogin1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Assert-SqlLogin -ParameterFilter { + Should-Invoke -CommandName Assert-SqlLogin -Exactly -ParameterFilter { $ServerName -eq (Get-ComputerName) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1012,17 +1012,17 @@ Describe 'DSC_SqlDatabaseUser\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 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('ALTER USER [{0}] WITH NAME = [{1}], LOGIN = [{2}];' -f 'DatabaseUser1', 'DatabaseUser1', 'OtherLogin1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Assert-SqlLogin -ParameterFilter { + Should-Invoke -CommandName Assert-SqlLogin -Exactly -ParameterFilter { $ServerName -eq 'host.company.local' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1047,11 +1047,11 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.FailedUpdateDatabaseUser -f 'DatabaseUser1', 'TestDB', 'Login' { Set-TargetResource @mockSetTargetResourceParameters - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } } @@ -1087,18 +1087,18 @@ Describe 'DSC_SqlDatabaseUser\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 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('DROP USER [{0}];' -f 'DatabaseUser1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR ASYMMETRIC KEY [{1}];' -f 'DatabaseUser1', 'OtherAsymmetricKey1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1133,22 +1133,22 @@ Describe 'DSC_SqlDatabaseUser\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 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('DROP USER [{0}];' -f 'DatabaseUser1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR CERTIFICATE [{1}];' -f 'DatabaseUser1', 'OtherCertificate1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } - Context 'When the database user has the wrong certificate name' { + Context 'When the database user has the wrong certificate name for login' { BeforeAll { Mock -CommandName Get-TargetResource -MockWith { return @{ @@ -1179,18 +1179,18 @@ Describe 'DSC_SqlDatabaseUser\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 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('DROP USER [{0}];' -f 'DatabaseUser1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $Query -eq ('CREATE USER [{0}] FOR LOGIN [{1}];' -f 'DatabaseUser1', 'OtherLogin1') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1226,11 +1226,11 @@ Describe 'DSC_SqlDatabaseUser\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.ForceNotEnabled - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 0 } } } @@ -1247,7 +1247,7 @@ Describe 'Assert-Parameters' -Tag 'Helper' { { Assert-Parameters -LoginName 'AnyValue' -UserType 'NoLogin' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") } } } @@ -1261,7 +1261,7 @@ Describe 'Assert-Parameters' -Tag 'Helper' { { Assert-Parameters -CertificateName 'AnyValue' -UserType 'NoLogin' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") } } } @@ -1275,7 +1275,7 @@ Describe 'Assert-Parameters' -Tag 'Helper' { { Assert-Parameters -AsymmetricKeyName 'AnyValue' -UserType 'NoLogin' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") } } } @@ -1289,7 +1289,7 @@ Describe 'Assert-Parameters' -Tag 'Helper' { { Assert-Parameters -UserType 'Login' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") } } } @@ -1303,7 +1303,7 @@ Describe 'Assert-Parameters' -Tag 'Helper' { { Assert-Parameters -UserType 'AsymmetricKey' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") } } } @@ -1317,7 +1317,7 @@ Describe 'Assert-Parameters' -Tag 'Helper' { { Assert-Parameters -UserType 'Certificate' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + " (Parameter 'Action')") } } } @@ -1362,7 +1362,7 @@ Describe 'ConvertTo-UserType' -Tag 'Helper' { $convertToUserTypeResult = ConvertTo-UserType -AuthenticationType $AuthenticationType -LoginType $LoginType - $convertToUserTypeResult | Should -Be $ExpectedResult + $convertToUserTypeResult | Should-Be $ExpectedResult } } @@ -1374,7 +1374,7 @@ Describe 'ConvertTo-UserType' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.UnknownAuthenticationType -f 'UnsupportedValue', 'SqlLogin' { ConvertTo-UserType -AuthenticationType 'UnsupportedValue' -LoginType 'SqlLogin' - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -1410,7 +1410,7 @@ Describe 'Assert-SqlLogin' -Tag 'Helper' { Verbose = $true } - { Assert-SqlLogin @assertSqlLoginParameters } | Should -Not -Throw + $null = & ({ Assert-SqlLogin @assertSqlLoginParameters }) } } } @@ -1430,7 +1430,7 @@ Describe 'Assert-SqlLogin' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.SqlLoginNotFound -f 'AnyValue' { Assert-SqlLogin @assertSqlLoginParameters - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -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 }) } } } @@ -1502,7 +1502,7 @@ Describe 'Assert-DatabaseCertificate' -Tag 'Helper' { $mockErrorMessage = ($script:localizedData.CertificateNotFound -f 'AnyValue', 'TestDB') { Assert-DatabaseCertificate @assertDatabaseCertificateParameters - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -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 }) } } } @@ -1575,7 +1575,7 @@ Describe 'Assert-DatabaseAsymmetricKey' -Tag 'Helper' { { Assert-DatabaseAsymmetricKey @assertDatabaseAsymmetricKeyParameters - } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } diff --git a/tests/Unit/DSC_SqlEndpoint.Tests.ps1 b/tests/Unit/DSC_SqlEndpoint.Tests.ps1 index 1b0f031e2..c84d0c53c 100644 --- a/tests/Unit/DSC_SqlEndpoint.Tests.ps1 +++ b/tests/Unit/DSC_SqlEndpoint.Tests.ps1 @@ -153,7 +153,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } @@ -163,9 +163,9 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.EndpointType | Should -Be $mockGetTargetResourceParameters.EndpointType + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.EndpointType | Should-Be $mockGetTargetResourceParameters.EndpointType } } @@ -175,13 +175,13 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.EndpointName | Should -Be '' - $result.Port | Should -Be '' - $result.IpAddress | Should -Be '' - $result.Owner | Should -Be '' - $result.State | Should -BeNullOrEmpty - $result.IsMessageForwardingEnabled | Should -BeNullOrEmpty - $result.MessageForwardingSize | Should -BeNullOrEmpty + $result.EndpointName | Should-Be '' + $result.Port | Should-Be '' + $result.IpAddress | Should-Be '' + $result.Owner | Should-Be '' + $result.State | Should-BeFalsy + $result.IsMessageForwardingEnabled | Should-BeFalsy + $result.MessageForwardingSize | Should-BeFalsy } } @@ -189,10 +189,10 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -210,7 +210,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } @@ -220,9 +220,9 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.EndpointType | Should -Be $mockGetTargetResourceParameters.EndpointType + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.EndpointType | Should-Be $mockGetTargetResourceParameters.EndpointType } } @@ -232,13 +232,13 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.EndpointName | Should -Be 'DefaultEndpointMirror' - $result.Port | Should -Be 5022 - $result.IpAddress | Should -Be '0.0.0.0' - $result.Owner | Should -Be 'sa' - $result.State | Should -Be 'Started' - $result.IsMessageForwardingEnabled | Should -BeNullOrEmpty - $result.MessageForwardingSize | Should -BeNullOrEmpty + $result.EndpointName | Should-Be 'DefaultEndpointMirror' + $result.Port | Should-Be 5022 + $result.IpAddress | Should-Be '0.0.0.0' + $result.Owner | Should-Be 'sa' + $result.State | Should-Be 'Started' + $result.IsMessageForwardingEnabled | Should-BeFalsy + $result.MessageForwardingSize | Should-BeFalsy } } @@ -246,10 +246,10 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -267,7 +267,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.EndpointFoundButWrongType -f $mockGetTargetResourceParameters.EndpointName, 'DatabaseMirroring', 'ServiceBroker' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -336,7 +336,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } @@ -346,9 +346,9 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.EndpointType | Should -Be $mockGetTargetResourceParameters.EndpointType + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.EndpointType | Should-Be $mockGetTargetResourceParameters.EndpointType } } @@ -358,13 +358,13 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.EndpointName | Should -Be '' - $result.Port | Should -Be '' - $result.IpAddress | Should -Be '' - $result.Owner | Should -Be '' - $result.State | Should -BeNullOrEmpty - $result.IsMessageForwardingEnabled | Should -BeNullOrEmpty - $result.MessageForwardingSize | Should -BeNullOrEmpty + $result.EndpointName | Should-Be '' + $result.Port | Should-Be '' + $result.IpAddress | Should-Be '' + $result.Owner | Should-Be '' + $result.State | Should-BeFalsy + $result.IsMessageForwardingEnabled | Should-BeFalsy + $result.MessageForwardingSize | Should-BeFalsy } } @@ -372,10 +372,10 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -393,7 +393,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } @@ -403,9 +403,9 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.EndpointType | Should -Be $mockGetTargetResourceParameters.EndpointType + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.EndpointType | Should-Be $mockGetTargetResourceParameters.EndpointType } } @@ -415,13 +415,13 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.EndpointName | Should -Be 'SSBR' - $result.Port | Should -Be 5023 - $result.IpAddress | Should -Be '192.168.0.20' - $result.Owner | Should -Be 'COMPANY\OtherAcct' - $result.State | Should -Be 'Started' - $result.IsMessageForwardingEnabled | Should -BeTrue - $result.MessageForwardingSize | Should -Be 2 + $result.EndpointName | Should-Be 'SSBR' + $result.Port | Should-Be 5023 + $result.IpAddress | Should-Be '192.168.0.20' + $result.Owner | Should-Be 'COMPANY\OtherAcct' + $result.State | Should-Be 'Started' + $result.IsMessageForwardingEnabled | Should-BeTrue + $result.MessageForwardingSize | Should-Be 2 } } @@ -429,10 +429,10 @@ 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 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -450,7 +450,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.EndpointFoundButWrongType -f $mockGetTargetResourceParameters.EndpointName, 'ServiceBroker', 'DatabaseMirroring' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -477,7 +477,7 @@ Describe 'SqlEndpoint\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.NotConnectedToInstance -f $mockGetTargetResourceParameters.ServerName, $mockGetTargetResourceParameters.InstanceName - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -531,7 +531,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -564,7 +564,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -600,7 +600,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -633,7 +633,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -691,7 +691,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -743,7 +743,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -780,7 +780,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -813,7 +813,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -849,7 +849,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -882,7 +882,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -936,7 +936,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -988,7 +988,7 @@ Describe 'DSC_SqlEndpoint\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -1166,14 +1166,14 @@ 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 - $script:mockMethodStopWasRun | Should -Be 0 - $script:mockMethodAlterWasRun | Should -Be 0 - $script:mockMethodDropWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 + $script:mockMethodCreateWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 1 + $script:mockMethodStopWasRun | Should-Be 0 + $script:mockMethodAlterWasRun | Should-Be 0 + $script:mockMethodDropWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 } } } @@ -1197,33 +1197,33 @@ 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 - $script:mockMethodDropWasRun | Should -Be 0 + $script:mockMethodCreateWasRun | Should-Be 1 + $script:mockMethodAlterWasRun | Should-Be 0 + $script:mockMethodDropWasRun | Should-Be 0 switch ($MockState) { 'Disabled' { - $script:mockMethodDisableWasRun | Should -Be 1 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodDisableWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 } 'Started' { - $script:mockMethodStartWasRun | Should -Be 1 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodStartWasRun | Should-Be 1 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 } 'Stopped' { - $script:mockMethodStopWasRun | Should -Be 1 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 + $script:mockMethodStopWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 } } } @@ -1260,21 +1260,21 @@ 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 - $script:mockMethodDropWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodCreateWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 1 + $script:mockMethodDropWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 if ($MockParameterName -eq 'Owner') { - $script:mockMethodAlterWasRun | Should -Be 0 + $script:mockMethodAlterWasRun | Should-Be 0 } else { - $script:mockMethodAlterWasRun | Should -Be 1 + $script:mockMethodAlterWasRun | Should-Be 1 } } } @@ -1318,21 +1318,21 @@ 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 - $script:mockMethodDropWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodCreateWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 1 + $script:mockMethodDropWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 if ($MockParameterName -eq 'Owner') { - $script:mockMethodAlterWasRun | Should -Be 0 + $script:mockMethodAlterWasRun | Should-Be 0 } else { - $script:mockMethodAlterWasRun | Should -Be 1 + $script:mockMethodAlterWasRun | Should-Be 1 } } } @@ -1390,10 +1390,10 @@ 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 + $script:mockMethodCreateWasRun | Should-Be 0 + $script:mockMethodDropWasRun | Should-Be 0 if ($MockParameterName -eq 'State') { @@ -1401,29 +1401,29 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { { 'Disabled' { - $script:mockMethodDisableWasRun | Should -Be 1 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodDisableWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 } 'Started' { - $script:mockMethodStartWasRun | Should -Be 1 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodStartWasRun | Should-Be 1 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 } 'Stopped' { - $script:mockMethodStopWasRun | Should -Be 1 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 + $script:mockMethodStopWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 } } } else { - $script:mockMethodAlterWasRun | Should -Be 1 + $script:mockMethodAlterWasRun | Should-Be 1 } } } @@ -1479,10 +1479,10 @@ 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 + $script:mockMethodCreateWasRun | Should-Be 0 + $script:mockMethodDropWasRun | Should-Be 0 if ($MockParameterName -eq 'State') { @@ -1490,29 +1490,29 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { { 'Disabled' { - $script:mockMethodDisableWasRun | Should -Be 1 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodDisableWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 } 'Started' { - $script:mockMethodStartWasRun | Should -Be 1 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 + $script:mockMethodStartWasRun | Should-Be 1 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 } 'Stopped' { - $script:mockMethodStopWasRun | Should -Be 1 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 + $script:mockMethodStopWasRun | Should-Be 1 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 } } } else { - $script:mockMethodAlterWasRun | Should -Be 1 + $script:mockMethodAlterWasRun | Should-Be 1 } } } @@ -1527,14 +1527,14 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.EndpointNotFound -f 'UnknownEndpointMirror' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:mockMethodDropWasRun | Should -Be 0 - $script:mockMethodCreateWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 - $script:mockMethodAlterWasRun | Should -Be 0 + $script:mockMethodDropWasRun | Should-Be 0 + $script:mockMethodCreateWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 + $script:mockMethodAlterWasRun | Should-Be 0 } } } @@ -1557,14 +1557,14 @@ 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 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 - $script:mockMethodAlterWasRun | Should -Be 0 + $script:mockMethodDropWasRun | Should-Be 1 + $script:mockMethodCreateWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 + $script:mockMethodAlterWasRun | Should-Be 0 } } @@ -1579,14 +1579,14 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.EndpointNotFound -f 'UnknownEndpointMirror' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:mockMethodDropWasRun | Should -Be 0 - $script:mockMethodCreateWasRun | Should -Be 0 - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodStartWasRun | Should -Be 0 - $script:mockMethodStopWasRun | Should -Be 0 - $script:mockMethodAlterWasRun | Should -Be 0 + $script:mockMethodDropWasRun | Should-Be 0 + $script:mockMethodCreateWasRun | Should-Be 0 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodStartWasRun | Should-Be 0 + $script:mockMethodStopWasRun | Should-Be 0 + $script:mockMethodAlterWasRun | Should-Be 0 } } } @@ -1614,7 +1614,7 @@ Describe 'SqlEndpoint\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.NotConnectedToInstance -f 'localhost', 'MSSQLSERVER' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } diff --git a/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 b/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 index 8ef5c3801..2330cf83f 100644 --- a/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 +++ b/tests/Unit/DSC_SqlEndpointPermission.Tests.ps1 @@ -136,11 +136,11 @@ Describe 'SqlEndpointPermission\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.Principal | Should -Be $mockGetTargetResourceParameters.Principal - $result.Permission | Should -Be 'CONNECT' + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.Principal | Should-Be $mockGetTargetResourceParameters.Principal + $result.Permission | Should-Be 'CONNECT' } } } @@ -154,11 +154,11 @@ Describe 'SqlEndpointPermission\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.Principal | Should -Be $mockGetTargetResourceParameters.Principal - $result.Permission | Should -BeNullOrEmpty + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.Principal | Should-Be $mockGetTargetResourceParameters.Principal + $result.Permission | Should-BeFalsy } } } @@ -183,7 +183,7 @@ Describe 'SqlEndpointPermission\Get-TargetResource' -Tag 'Get' { ($script:localizedData.EndpointNotFound -f 'MissingEndpoint') ) - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } } @@ -231,7 +231,7 @@ Describe 'SqlEndpointPermission\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -259,7 +259,7 @@ Describe 'SqlEndpointPermission\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -288,7 +288,7 @@ Describe 'SqlEndpointPermission\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -329,9 +329,9 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Principal = 'COMPANY\Account' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -352,9 +352,9 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' $mockSetTargetResourceParameters.Principal = 'COMPANY\MissingAccount' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -430,13 +430,13 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Principal = 'COMPANY\Account' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 - $mockMethodGrantWasRun | Should -Be 1 - $mockMethodRevokeWasRun | Should -Be 0 + $mockMethodGrantWasRun | Should-Be 1 + $mockMethodRevokeWasRun | Should-Be 0 } } } @@ -457,13 +457,13 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' $mockSetTargetResourceParameters.Principal = 'COMPANY\MissingAccount' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 - $mockMethodRevokeWasRun | Should -Be 1 - $mockMethodGrantWasRun | Should -Be 0 + $mockMethodRevokeWasRun | Should-Be 1 + $mockMethodGrantWasRun | Should-Be 0 } } } @@ -487,7 +487,7 @@ Describe 'SqlEndpointPermission\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.EndpointNotFound -f 'MissingEndpoint' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } diff --git a/tests/Unit/DSC_SqlLogin.Tests.ps1 b/tests/Unit/DSC_SqlLogin.Tests.ps1 index c104f7beb..fd42b5ce3 100644 --- a/tests/Unit/DSC_SqlLogin.Tests.ps1 +++ b/tests/Unit/DSC_SqlLogin.Tests.ps1 @@ -138,19 +138,19 @@ Describe 'SqlLogin\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.LoginType | Should -Be $MockLoginType - $result.Disabled | Should -BeTrue - $result.DefaultDatabase | Should -Be 'master' + $result.Ensure | Should-Be 'Present' + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.LoginType | Should-Be $MockLoginType + $result.Disabled | Should-BeTrue + $result.DefaultDatabase | Should-Be 'master' if ($MockLoginType -eq 'SqlLogin') { - $result.LoginMustChangePassword | Should -BeTrue - $result.LoginPasswordExpirationEnabled | Should -BeTrue - $result.LoginPasswordPolicyEnforced | Should -BeTrue + $result.LoginMustChangePassword | Should-BeTrue + $result.LoginPasswordExpirationEnabled | Should-BeTrue + $result.LoginPasswordPolicyEnforced | Should-BeTrue } else { @@ -159,9 +159,9 @@ Describe 'SqlLogin\Get-TargetResource' -Tag 'Get' { in the hashtable. This is put here so the tests wil be fixed when the code is fixed. #> - $result | Should -Not -Contain 'LoginMustChangePassword' - $result | Should -Not -Contain 'LoginPasswordExpirationEnabled' - $result | Should -Not -Contain 'LoginPasswordPolicyEnforced' + $result | Should-NotContainCollection 'LoginMustChangePassword' + $result | Should-NotContainCollection 'LoginPasswordExpirationEnabled' + $result | Should-NotContainCollection 'LoginPasswordPolicyEnforced' } } } @@ -219,19 +219,19 @@ Describe 'SqlLogin\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.Name | Should -Be $mockGetTargetResourceParameters.Name - $result.LoginType | Should -BeNullOrEmpty - $result.Disabled | Should -BeFalse - $result.DefaultDatabase | Should -BeNullOrEmpty + $result.Ensure | Should-Be 'Absent' + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.Name | Should-Be $mockGetTargetResourceParameters.Name + $result.LoginType | Should-BeFalsy + $result.Disabled | Should-BeFalse + $result.DefaultDatabase | Should-BeFalsy if ($MockLoginType -eq 'SqlLogin') { - $result.LoginMustChangePassword | Should -BeFalse - $result.LoginPasswordExpirationEnabled | Should -BeFalse - $result.LoginPasswordPolicyEnforced | Should -BeFalse + $result.LoginMustChangePassword | Should-BeFalse + $result.LoginPasswordExpirationEnabled | Should-BeFalse + $result.LoginPasswordPolicyEnforced | Should-BeFalse } else { @@ -240,9 +240,9 @@ Describe 'SqlLogin\Get-TargetResource' -Tag 'Get' { in the hashtable. This is put here so the tests wil be fixed when the code is fixed. #> - $result | Should -Not -Contain 'LoginMustChangePassword' - $result | Should -Not -Contain 'LoginPasswordExpirationEnabled' - $result | Should -Not -Contain 'LoginPasswordPolicyEnforced' + $result | Should-NotContainCollection 'LoginMustChangePassword' + $result | Should-NotContainCollection 'LoginPasswordExpirationEnabled' + $result | Should-NotContainCollection 'LoginPasswordPolicyEnforced' } } } @@ -286,10 +286,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -311,10 +311,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -342,10 +342,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -380,10 +380,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -407,10 +407,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -432,10 +432,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -482,10 +482,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -531,10 +531,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -570,10 +570,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -607,10 +607,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -645,10 +645,10 @@ Describe 'SqlLogin\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = $script:localizedData.PasswordValidationError - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -705,21 +705,21 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Name = $MockLoginName $mockSetTargetResourceParameters.LoginType = $MockLoginType - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq $MockLoginName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { -not $PesterBoundParameters.ContainsKey('LoginCreateOptions') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { -not $PesterBoundParameters.ContainsKey('LoginCreateOptions') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -746,13 +746,13 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.DefaultDatabase = 'NewDatabase' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq 'Windows\Login1' -and $Login.DefaultDatabase -eq 'NewDatabase' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -800,16 +800,16 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.Disabled = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $script:mockMethodDisableWasRun | Should -Be 1 + $script:mockMethodDisableWasRun | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq 'Windows\Login1' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -839,25 +839,25 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq 'SqlLogin1' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 <# When a SqlLogin is created there are additional parameters used. This make sure the mock is called with the correct parameters. #> - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $PesterBoundParameters.ContainsKey('LoginCreateOptions') -and $LoginCreateOptions -eq [Microsoft.SqlServer.Management.Smo.LoginCreateOptions]::MustChange - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $PesterBoundParameters.ContainsKey('SecureString') - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -887,21 +887,21 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq 'SqlLogin1' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 <# When a SqlLogin is created there are additional parameters used. This make sure the mock is called with the correct parameters. #> - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $PesterBoundParameters.ContainsKey('LoginCreateOptions') -and $LoginCreateOptions -eq [Microsoft.SqlServer.Management.Smo.LoginCreateOptions]::None - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -931,13 +931,13 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq 'SqlLogin1' -and $Login.DefaultDatabase -eq 'NewDatabase' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -988,16 +988,16 @@ 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 }) - $script:mockMethodDisableWasRun | Should -Be 1 + $script:mockMethodDisableWasRun | Should-Be 1 } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-SQLServerLogin -Exactly -ParameterFilter { $Login.Name -eq 'SqlLogin1' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1027,10 +1027,10 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.IncorrectLoginMode -f 'localhost', 'MSSQLSERVER', 'Integrated' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1057,10 +1057,10 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.LoginCredentialNotFound -f 'SqlLogin1' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1103,10 +1103,10 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Name = $MockLoginName $mockSetTargetResourceParameters.LoginType = $MockLoginType - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + ($script:localizedData.LoginTypeNotImplemented -f $MockLoginType)) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + ($script:localizedData.LoginTypeNotImplemented -f $MockLoginType)) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -1136,11 +1136,11 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' $mockSetTargetResourceParameters.Name = 'SqlLogin1' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-SQLServerLogin -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-SQLServerLogin -Exactly -Scope It -Times 1 } } } @@ -1195,21 +1195,21 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.Disabled = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) if ($MockPropertyValue) { - $script:mockMethodDisableWasRun | Should -Be 1 - $script:mockMethodEnableWasRun | Should -Be 0 + $script:mockMethodDisableWasRun | Should-Be 1 + $script:mockMethodEnableWasRun | Should-Be 0 } else { - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodEnableWasRun | Should -Be 1 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodEnableWasRun | Should-Be 1 } } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1245,13 +1245,13 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'WindowsUser' $mockSetTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-SQLServerLogin -Exactly -ParameterFilter { $Login.$MockPropertyName -eq $MockPropertyValue - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -1305,12 +1305,12 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-SQLServerLogin -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-SQLServerLogin -Exactly -Scope It -Times 1 } } @@ -1363,21 +1363,21 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.Disabled = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) if ($MockPropertyValue) { - $script:mockMethodDisableWasRun | Should -Be 1 - $script:mockMethodEnableWasRun | Should -Be 0 + $script:mockMethodDisableWasRun | Should-Be 1 + $script:mockMethodEnableWasRun | Should-Be 0 } else { - $script:mockMethodDisableWasRun | Should -Be 0 - $script:mockMethodEnableWasRun | Should -Be 1 + $script:mockMethodDisableWasRun | Should-Be 0 + $script:mockMethodEnableWasRun | Should-Be 1 } } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1414,13 +1414,13 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.LoginType = 'SqlLogin' $mockSetTargetResourceParameters.$MockPropertyName = $MockPropertyValue - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Update-SQLServerLogin -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Update-SQLServerLogin -Exactly -ParameterFilter { $Login.$MockPropertyName -eq $MockPropertyValue - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1453,10 +1453,10 @@ Describe 'SqlLogin\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.MustChangePasswordCannotBeChanged - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1489,11 +1489,11 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Set-SQLServerLoginPassword -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-SQLServerLoginPassword -Exactly -Scope It -Times 1 } } } @@ -1520,9 +1520,9 @@ Describe 'SqlLogin\Update-SQLServerLogin' { $mockLogin.LoginType = 'WindowsUser' - { Update-SQLServerLogin -Login $mockLogin } | Should -Not -Throw + $null = & ({ Update-SQLServerLogin -Login $mockLogin }) - $script:mockMethodAlterWasRun | Should -Be 1 + $script:mockMethodAlterWasRun | Should-Be 1 } } @@ -1541,9 +1541,9 @@ Describe 'SqlLogin\Update-SQLServerLogin' { $mockErrorMessage = $script:localizedData.AlterLoginFailed -f $mockLogin.Name - { Update-SQLServerLogin -Login $mockLogin } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Update-SQLServerLogin -Login $mockLogin } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:mockMethodAlterWasRun | Should -Be 1 + $script:mockMethodAlterWasRun | Should-Be 1 } } } @@ -1569,9 +1569,9 @@ Describe 'SqlLogin\New-SQLServerLogin' { $mockLogin.LoginType = 'WindowsUser' - { New-SQLServerLogin -Login $mockLogin } | Should -Not -Throw + $null = & ({ New-SQLServerLogin -Login $mockLogin }) - $script:mockMethodCreateWasRun | Should -Be 1 + $script:mockMethodCreateWasRun | Should-Be 1 } } @@ -1593,9 +1593,9 @@ Describe 'SqlLogin\New-SQLServerLogin' { LoginCreateOptions = 'None' } - { New-SQLServerLogin @createLoginParameters } | Should -Not -Throw + $null = & ({ New-SQLServerLogin @createLoginParameters }) - $script:mockMethodCreateWasRun | Should -Be 1 + $script:mockMethodCreateWasRun | Should-Be 1 } } @@ -1615,9 +1615,9 @@ Describe 'SqlLogin\New-SQLServerLogin' { $mockErrorMessage = $script:localizedData.CreateLoginFailed -f $mockLogin.Name - { New-SQLServerLogin -Login $mockLogin } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { New-SQLServerLogin -Login $mockLogin } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:mockMethodCreateWasRun | Should -Be 1 + $script:mockMethodCreateWasRun | Should-Be 1 } } @@ -1642,7 +1642,7 @@ Describe 'SqlLogin\New-SQLServerLogin' { $mockErrorMessage = $script:localizedData.CreateLoginFailedOnPassword -f $mockLogin.Name - { New-SQLServerLogin @createLoginParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { New-SQLServerLogin @createLoginParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } @@ -1668,9 +1668,9 @@ Describe 'SqlLogin\New-SQLServerLogin' { $mockErrorMessage = $script:localizedData.CreateLoginFailed -f $mockLogin.Name - { New-SQLServerLogin @createLoginParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { New-SQLServerLogin @createLoginParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:mockMethodCreateWasRun | Should -Be 1 + $script:mockMethodCreateWasRun | Should-Be 1 } } @@ -1696,7 +1696,7 @@ Describe 'SqlLogin\New-SQLServerLogin' { $mockErrorMessage = $script:localizedData.CreateLoginFailed -f $mockLogin.Name - { New-SQLServerLogin @createLoginParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { New-SQLServerLogin @createLoginParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } } @@ -1722,9 +1722,9 @@ Describe 'SqlLogin\Remove-SQLServerLogin' { $mockLogin.LoginType = 'WindowsUser' - { Remove-SQLServerLogin -Login $mockLogin } | Should -Not -Throw + $null = & ({ Remove-SQLServerLogin -Login $mockLogin }) - $script:mockMethodDropWasRun | Should -Be 1 + $script:mockMethodDropWasRun | Should-Be 1 } } @@ -1744,9 +1744,9 @@ Describe 'SqlLogin\Remove-SQLServerLogin' { $mockErrorMessage = $script:localizedData.DropLoginFailed -f $mockLogin.Name - { Remove-SQLServerLogin -Login $mockLogin } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Remove-SQLServerLogin -Login $mockLogin } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') - $script:mockMethodDropWasRun | Should -Be 1 + $script:mockMethodDropWasRun | Should-Be 1 } } } @@ -1775,9 +1775,9 @@ 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 }) - $mockMethodChangePasswordWasRun | Should -Be 1 + $mockMethodChangePasswordWasRun | Should-Be 1 } } @@ -1797,7 +1797,7 @@ Describe 'SqlLogin\Set-SQLServerLoginPassword' { $mockErrorMessage = $script:localizedData.SetPasswordValidationFailed -f $setPasswordParameters.Login.Name - { Set-SQLServerLoginPassword @setPasswordParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-SQLServerLoginPassword @setPasswordParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } @@ -1806,7 +1806,7 @@ Describe 'SqlLogin\Set-SQLServerLoginPassword' { that is mocked in the stub file SMO.cs. It uses the code in the mocked method ChangePassword() to throw the correct exception. #> - It 'Should throw the correct error when changing the password fails' { + It 'Should throw the correct error when changing to the previous password fails' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -1817,7 +1817,7 @@ Describe 'SqlLogin\Set-SQLServerLoginPassword' { $mockErrorMessage = $script:localizedData.SetPasswordFailed -f $setPasswordParameters.Login.Name - { Set-SQLServerLoginPassword @setPasswordParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-SQLServerLoginPassword @setPasswordParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } @@ -1837,14 +1837,8 @@ Describe 'SqlLogin\Set-SQLServerLoginPassword' { $mockErrorMessage = $script:localizedData.SetPasswordFailed -f $setPasswordParameters.Login.Name - { Set-SQLServerLoginPassword @setPasswordParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-SQLServerLoginPassword @setPasswordParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } } } - -# } -# finally -# { -# Invoke-TestCleanup -# } diff --git a/tests/Unit/DSC_SqlMaxDop.Tests.ps1 b/tests/Unit/DSC_SqlMaxDop.Tests.ps1 index 29f7e5304..a4268184c 100644 --- a/tests/Unit/DSC_SqlMaxDop.Tests.ps1 +++ b/tests/Unit/DSC_SqlMaxDop.Tests.ps1 @@ -129,18 +129,18 @@ Describe 'SqlMaxDop\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -BeNullOrEmpty - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.MaxDop | Should -Be 4 - $result.IsActiveNode | Should -BeFalse - $result.ProcessOnlyOnActiveNode | Should -BeNullOrEmpty - $result.DynamicAlloc | Should -BeNullOrEmpty + $result.Ensure | Should-BeFalsy + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.MaxDop | Should-Be 4 + $result.IsActiveNode | Should-BeFalse + $result.ProcessOnlyOnActiveNode | Should-BeFalsy + $result.DynamicAlloc | Should-BeFalsy } } } - Context 'When getting the current state of max degree of parallelism' { + Context 'When getting the current state of max degree of parallelism without existing instance' { BeforeEach { Mock -CommandName Connect-SQL -MockWith { return $null @@ -157,13 +157,13 @@ Describe 'SqlMaxDop\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -BeNullOrEmpty - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.MaxDop | Should -BeNullOrEmpty - $result.IsActiveNode | Should -BeNullOrEmpty - $result.ProcessOnlyOnActiveNode | Should -BeNullOrEmpty - $result.DynamicAlloc | Should -BeNullOrEmpty + $result.Ensure | Should-BeFalsy + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.MaxDop | Should-BeFalsy + $result.IsActiveNode | Should-BeFalsy + $result.ProcessOnlyOnActiveNode | Should-BeFalsy + $result.DynamicAlloc | Should-BeFalsy } } } @@ -206,7 +206,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -229,7 +229,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -256,7 +256,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -279,7 +279,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MaxDop'')' -f $script:localizedData.MaxDopParamMustBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -305,7 +305,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -328,7 +328,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -355,7 +355,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -378,7 +378,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -419,7 +419,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MaxDop'')' -f $script:localizedData.MaxDopParamMustBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -469,9 +469,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.MaxDopSetError - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*Mock Alter Method was called with invalid operation.*') + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*Mock Alter Method was called with invalid operation.*') - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -524,9 +524,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -579,9 +579,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxDop = 4 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -638,9 +638,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DynamicAlloc = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -682,7 +682,7 @@ Describe 'Get-SqlDscDynamicMaxDop' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxDop - $result | Should -Be 1 + $result | Should-Be 1 } } } @@ -708,7 +708,7 @@ Describe 'Get-SqlDscDynamicMaxDop' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxDop - $result | Should -Be 2 + $result | Should-Be 2 } } } @@ -740,7 +740,7 @@ Describe 'Get-SqlDscDynamicMaxDop' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxDop - $result | Should -Be 4 + $result | Should-Be 4 } } } @@ -771,7 +771,7 @@ Describe 'Get-SqlDscDynamicMaxDop' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxDop - $result | Should -Be 8 + $result | Should-Be 8 } } } @@ -802,7 +802,7 @@ Describe 'Get-SqlDscDynamicMaxDop' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxDop - $result | Should -Be 8 + $result | Should-Be 8 } } } diff --git a/tests/Unit/DSC_SqlMemory.Tests.ps1 b/tests/Unit/DSC_SqlMemory.Tests.ps1 index 3aca2dc6f..b2fdb05a3 100644 --- a/tests/Unit/DSC_SqlMemory.Tests.ps1 +++ b/tests/Unit/DSC_SqlMemory.Tests.ps1 @@ -137,11 +137,11 @@ Describe 'SqlMaxDop\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be $mockGetTargetResourceParameters.ServerName - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $result.MinMemory | Should -Be 2048 - $result.MaxMemory | Should -Be 10300 - $result.IsActiveNode | Should -BeFalse + $result.ServerName | Should-Be $mockGetTargetResourceParameters.ServerName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $result.MinMemory | Should-Be 2048 + $result.MaxMemory | Should-Be 10300 + $result.IsActiveNode | Should-BeFalse } } } @@ -191,7 +191,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MaxMemory'')' -f $script:localizedData.MaxMemoryParamMustBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -222,7 +222,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MaxMemoryPercent'')' -f $script:localizedData.MaxMemoryPercentParamMustBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -253,7 +253,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MaxMemoryPercent'')' -f $script:localizedData.MaxMemoryPercentParamMustBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -284,7 +284,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MinMemoryPercent'')' -f $script:localizedData.MinMemoryPercentParamMustBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -314,7 +314,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MaxMemory'')' -f $script:localizedData.MaxMemoryParamMustNotBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -344,7 +344,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $mockErrorMessage = '{0} (Parameter ''MaxMemory'')' -f $script:localizedData.MaxMemoryParamMustNotBeNull - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -372,7 +372,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -398,7 +398,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -424,7 +424,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -455,7 +455,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -485,7 +485,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -515,7 +515,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -543,7 +543,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -569,7 +569,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -595,7 +595,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -626,7 +626,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -656,7 +656,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -686,7 +686,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -717,7 +717,7 @@ Describe 'SqlMaxDop\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -759,7 +759,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MaxMemory'')' -f $script:localizedData.MaxMemoryParamMustBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -774,7 +774,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MaxMemoryPercent'')' -f $script:localizedData.MaxMemoryPercentParamMustBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -789,7 +789,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MaxMemoryPercent'')' -f $script:localizedData.MaxMemoryPercentParamMustBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -804,7 +804,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MinMemoryPercent'')' -f $script:localizedData.MinMemoryPercentParamMustBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -818,7 +818,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MaxMemory'')' -f $script:localizedData.MaxMemoryParamMustNotBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -832,7 +832,7 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '{0} (Parameter ''MaxMemory'')' -f $script:localizedData.MaxMemoryParamMustNotBeNull - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -905,9 +905,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.Ensure = 'Absent' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -922,9 +922,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemory = 15000 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -939,9 +939,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MinMemory = 4096 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -962,9 +962,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MaxMemoryPercent = 50 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -985,9 +985,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.MinMemoryPercent = 50 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1008,9 +1008,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.DynamicAlloc = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1032,9 +1032,9 @@ 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 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1060,9 +1060,9 @@ 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 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1084,9 +1084,9 @@ 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 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1102,9 +1102,9 @@ 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 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1126,9 +1126,9 @@ 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 + $mockMethodAlterWasRun | Should-Be 1 } } } @@ -1144,9 +1144,9 @@ Describe 'SqlMaxDop\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = '*{0}*Mock InvalidOperationException*' -f ($script:localizedData.AlterServerMemoryFailed -f 'localhost', 'MSSQLSERVER') - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage - $mockMethodAlterWasRun | Should -Be 1 + $mockMethodAlterWasRun | Should-Be 1 } $script:mockInvalidOperationAlterMethod = $false @@ -1207,7 +1207,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 14560 + $result | Should-Be 14560 } } } @@ -1229,7 +1229,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 16896 + $result | Should-Be 16896 } } } @@ -1251,7 +1251,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 25646 + $result | Should-Be 25646 } } } @@ -1294,7 +1294,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { It 'Should return the correct max memory (in megabytes) value' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 25134 + $result | Should-Be 25134 } } } @@ -1324,7 +1324,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { It 'Should return the correct max memory (in megabytes) value' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 25390 + $result | Should-Be 25390 } } } @@ -1354,7 +1354,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { It 'Should return the correct max memory (in megabytes) value' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 24622 + $result | Should-Be 24622 } } } @@ -1396,7 +1396,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { It 'Should return the correct max memory (in megabytes) value' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 24078 + $result | Should-Be 24078 } } } @@ -1426,7 +1426,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { It 'Should return the correct max memory (in megabytes) value' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 24350 + $result | Should-Be 24350 } } } @@ -1456,7 +1456,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { It 'Should return the correct max memory (in megabytes) value' { $result = Get-SqlDscDynamicMaxMemory - $result | Should -Be 23534 + $result | Should-Be 23534 } } } @@ -1476,7 +1476,7 @@ Describe 'SqlMemory\Get-SqlDscDynamicMaxMemory' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.ErrorGetDynamicMaxMemory - { Get-SqlDscDynamicMaxMemory } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Get-SqlDscDynamicMaxMemory } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } } @@ -1501,7 +1501,7 @@ Describe 'SqlMemory\Get-SqlDscPercentMemory' -Tag 'Helper' { $result = Get-SqlDscPercentMemory -PercentMemory 80 - $result | Should -Be 16384 + $result | Should-Be 16384 } } } @@ -1523,7 +1523,7 @@ Describe 'SqlMemory\Get-SqlDscPercentMemory' -Tag 'Helper' { $result = Get-SqlDscPercentMemory -PercentMemory 50 - $result | Should -Be 762 + $result | Should-Be 762 } } } @@ -1542,7 +1542,7 @@ Describe 'SqlMemory\Get-SqlDscPercentMemory' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.ErrorGetPercentMemory - { Get-SqlDscPercentMemory -PercentMemory 80 } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Get-SqlDscPercentMemory -PercentMemory 80 } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } } diff --git a/tests/Unit/DSC_SqlProtocol.Tests.ps1 b/tests/Unit/DSC_SqlProtocol.Tests.ps1 index 3d7773a1f..68514a0e0 100644 --- a/tests/Unit/DSC_SqlProtocol.Tests.ps1 +++ b/tests/Unit/DSC_SqlProtocol.Tests.ps1 @@ -113,17 +113,17 @@ Describe 'SqlProtocol\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.ProtocolName | Should -Be 'TcpIp' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.ProtocolName | Should-Be 'TcpIp' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeFalse - $getTargetResourceResult.ListenOnAllIpAddresses | Should -BeFalse - $getTargetResourceResult.KeepAlive | Should -Be 0 - $getTargetResourceResult.PipeName | Should -BeNullOrEmpty - $getTargetResourceResult.HasMultiIPAddresses | Should -BeFalse + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeFalse + $getTargetResourceResult.ListenOnAllIpAddresses | Should-BeFalse + $getTargetResourceResult.KeepAlive | Should-Be 0 + $getTargetResourceResult.PipeName | Should-BeFalsy + $getTargetResourceResult.HasMultiIPAddresses | Should-BeFalse } } } @@ -159,17 +159,17 @@ Describe 'SqlProtocol\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.ProtocolName | Should -Be 'TcpIp' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.ProtocolName | Should-Be 'TcpIp' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeTrue - $getTargetResourceResult.ListenOnAllIpAddresses | Should -BeTrue - $getTargetResourceResult.KeepAlive | Should -Be 30000 - $getTargetResourceResult.PipeName | Should -BeNullOrEmpty - $getTargetResourceResult.HasMultiIPAddresses | Should -BeTrue + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeTrue + $getTargetResourceResult.ListenOnAllIpAddresses | Should-BeTrue + $getTargetResourceResult.KeepAlive | Should-Be 30000 + $getTargetResourceResult.PipeName | Should-BeFalsy + $getTargetResourceResult.HasMultiIPAddresses | Should-BeTrue } } } @@ -206,17 +206,17 @@ Describe 'SqlProtocol\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.ProtocolName | Should -Be 'NamedPipes' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.ProtocolName | Should-Be 'NamedPipes' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeTrue - $getTargetResourceResult.ListenOnAllIpAddresses | Should -BeFalse - $getTargetResourceResult.KeepAlive | Should -Be 0 - $getTargetResourceResult.PipeName | Should -Be $MockPipeName - $getTargetResourceResult.HasMultiIPAddresses | Should -BeFalse + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeTrue + $getTargetResourceResult.ListenOnAllIpAddresses | Should-BeFalse + $getTargetResourceResult.KeepAlive | Should-Be 0 + $getTargetResourceResult.PipeName | Should-Be $MockPipeName + $getTargetResourceResult.HasMultiIPAddresses | Should-BeFalse } } } @@ -243,17 +243,17 @@ Describe 'SqlProtocol\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.ProtocolName | Should -Be 'SharedMemory' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.ProtocolName | Should-Be 'SharedMemory' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeTrue - $getTargetResourceResult.ListenOnAllIpAddresses | Should -BeFalse - $getTargetResourceResult.KeepAlive | Should -Be 0 - $getTargetResourceResult.PipeName | Should -BeNullOrEmpty - $getTargetResourceResult.HasMultiIPAddresses | Should -BeFalse + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeTrue + $getTargetResourceResult.ListenOnAllIpAddresses | Should-BeFalse + $getTargetResourceResult.KeepAlive | Should-Be 0 + $getTargetResourceResult.PipeName | Should-BeFalsy + $getTargetResourceResult.HasMultiIPAddresses | Should-BeFalse } } } @@ -282,10 +282,10 @@ Describe 'SqlProtocol\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.ProtocolName | Should -Be 'SharedMemory' - $getTargetResourceResult.SuppressRestart | Should -BeTrue - $getTargetResourceResult.RestartTimeout | Should -Be 300 + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.ProtocolName | Should-Be 'SharedMemory' + $getTargetResourceResult.SuppressRestart | Should-BeTrue + $getTargetResourceResult.RestartTimeout | Should-Be 300 } } } @@ -316,10 +316,10 @@ Describe 'SqlProtocol\Test-TargetResource' -Tag 'Test' { } $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } @@ -345,10 +345,10 @@ Describe 'SqlProtocol\Test-TargetResource' -Tag 'Test' { } $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } } @@ -373,7 +373,7 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { PipeName = 'any pipe name' } - { Compare-ResourcePropertyState @testTargetResourceParameters } | Should -Throw + { Compare-ResourcePropertyState @testTargetResourceParameters } | Should-Throw } } @@ -389,7 +389,7 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { PipeName = 'any pipe name' } - { Compare-ResourcePropertyState @testTargetResourceParameters } | Should -Throw + { Compare-ResourcePropertyState @testTargetResourceParameters } | Should-Throw } } } @@ -406,7 +406,7 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { PipeName = 'any pipe name' } - { Compare-ResourcePropertyState @testTargetResourceParameters } | Should -Throw + { Compare-ResourcePropertyState @testTargetResourceParameters } | Should-Throw } } @@ -421,7 +421,7 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { KeepAlive = 30000 } - { Compare-ResourcePropertyState @testTargetResourceParameters } | Should -Throw + { Compare-ResourcePropertyState @testTargetResourceParameters } | Should-Throw } } @@ -436,7 +436,7 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { ListenOnAllIpAddresses = $true } - { Compare-ResourcePropertyState @testTargetResourceParameters } | Should -Throw + { Compare-ResourcePropertyState @testTargetResourceParameters } | Should-Throw } } } @@ -468,28 +468,28 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'ListenOnAllIpAddresses' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'KeepAlive' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be 30000 - $comparedReturnValue.Actual | Should -Be 30000 - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be 30000 + $comparedReturnValue.Actual | Should-Be 30000 + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -523,22 +523,22 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 2 + $compareTargetResourceStateResult | Should-BeCollection -Count 2 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'PipeName' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be $MockPipeName - $comparedReturnValue.Actual | Should -Be $MockPipeName - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be $MockPipeName + $comparedReturnValue.Actual | Should-Be $MockPipeName + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -564,16 +564,16 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -605,28 +605,28 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'ListenOnAllIpAddresses' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'KeepAlive' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be 50000 - $comparedReturnValue.Actual | Should -Be 30000 - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be 50000 + $comparedReturnValue.Actual | Should-Be 30000 + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -662,22 +662,22 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 2 + $compareTargetResourceStateResult | Should-BeCollection -Count 2 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'PipeName' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be $mockExpectedPipeName - $comparedReturnValue.Actual | Should -Be $MockPipeName - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be $mockExpectedPipeName + $comparedReturnValue.Actual | Should-Be $MockPipeName + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -703,16 +703,16 @@ Describe 'SqlProtocol\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -752,7 +752,7 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { } { Set-TargetResource @setTargetResourceParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -778,10 +778,10 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) } - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } @@ -851,12 +851,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -910,12 +910,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -969,12 +969,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $false } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1035,12 +1035,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { KeepAlive = 50000 } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } } @@ -1096,13 +1096,13 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { SuppressRestart = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 1 } } } @@ -1163,12 +1163,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1220,12 +1220,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { Enabled = $true } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1277,12 +1277,12 @@ Describe 'SqlProtocol\Set-TargetResource' -Tag 'Set' { PipeName = '\\.\pipe\$$\CLU01A\MSSQL$SQL2014\sql\query' } - { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @setTargetResourceParameters }) - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } } } diff --git a/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 b/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 index 78219adb1..c9977854d 100644 --- a/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 +++ b/tests/Unit/DSC_SqlProtocolTcpIp.Tests.ps1 @@ -96,20 +96,20 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName # IP address group should always be returned with the correct casing. - $getTargetResourceResult.IpAddressGroup | Should -BeExactly 'IPAll' + $getTargetResourceResult.IpAddressGroup | Should-BeString -CaseSensitive 'IPAll' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeFalse - $getTargetResourceResult.IPAddress | Should -BeNullOrEmpty - $getTargetResourceResult.UseTcpDynamicPort | Should -BeFalse - $getTargetResourceResult.TcpPort | Should -BeNullOrEmpty - $getTargetResourceResult.IsActive | Should -BeFalse - $getTargetResourceResult.AddressFamily | Should -BeNullOrEmpty - $getTargetResourceResult.TcpDynamicPort | Should -BeNullOrEmpty + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeFalse + $getTargetResourceResult.IPAddress | Should-BeFalsy + $getTargetResourceResult.UseTcpDynamicPort | Should-BeFalse + $getTargetResourceResult.TcpPort | Should-BeFalsy + $getTargetResourceResult.IsActive | Should-BeFalse + $getTargetResourceResult.AddressFamily | Should-BeFalsy + $getTargetResourceResult.TcpDynamicPort | Should-BeFalsy } } } @@ -140,10 +140,10 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { IpAddressGroup = 'IP2' } - { Get-TargetResource @getTargetResourceParameters } | Should -Not -Throw + $null = & ({ Get-TargetResource @getTargetResourceParameters }) } - Should -Invoke -CommandName Write-Warning + Should-Invoke -CommandName Write-Warning } } } @@ -182,19 +182,19 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.IpAddressGroup | Should -BeExactly 'IPAll' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.IpAddressGroup | Should-BeString -CaseSensitive 'IPAll' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeFalse - $getTargetResourceResult.IPAddress | Should -BeNullOrEmpty - $getTargetResourceResult.UseTcpDynamicPort | Should -BeTrue - $getTargetResourceResult.TcpPort | Should -BeNullOrEmpty - $getTargetResourceResult.IsActive | Should -BeFalse - $getTargetResourceResult.AddressFamily | Should -BeNullOrEmpty - $getTargetResourceResult.TcpDynamicPort | Should -BeExactly '0' + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeFalse + $getTargetResourceResult.IPAddress | Should-BeFalsy + $getTargetResourceResult.UseTcpDynamicPort | Should-BeTrue + $getTargetResourceResult.TcpPort | Should-BeFalsy + $getTargetResourceResult.IsActive | Should-BeFalse + $getTargetResourceResult.AddressFamily | Should-BeFalsy + $getTargetResourceResult.TcpDynamicPort | Should-BeString -CaseSensitive '0' } } } @@ -231,19 +231,19 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.IpAddressGroup | Should -BeExactly 'IPAll' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.IpAddressGroup | Should-BeString -CaseSensitive 'IPAll' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeFalse - $getTargetResourceResult.IPAddress | Should -BeNullOrEmpty - $getTargetResourceResult.UseTcpDynamicPort | Should -BeFalse - $getTargetResourceResult.TcpPort | Should -BeExactly '1433,1500,1501' - $getTargetResourceResult.IsActive | Should -BeFalse - $getTargetResourceResult.AddressFamily | Should -BeNullOrEmpty - $getTargetResourceResult.TcpDynamicPort | Should -BeNullOrEmpty + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeFalse + $getTargetResourceResult.IPAddress | Should-BeFalsy + $getTargetResourceResult.UseTcpDynamicPort | Should-BeFalse + $getTargetResourceResult.TcpPort | Should-BeString -CaseSensitive '1433,1500,1501' + $getTargetResourceResult.IsActive | Should-BeFalse + $getTargetResourceResult.AddressFamily | Should-BeFalsy + $getTargetResourceResult.TcpDynamicPort | Should-BeFalsy } } } @@ -292,19 +292,19 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.IpAddressGroup | Should -BeExactly 'IP1' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.IpAddressGroup | Should-BeString -CaseSensitive 'IP1' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeTrue - $getTargetResourceResult.IPAddress | Should -Be 'fe80::7894:a6b6:59dd:c8ff%9' - $getTargetResourceResult.UseTcpDynamicPort | Should -BeTrue - $getTargetResourceResult.TcpPort | Should -BeNullOrEmpty - $getTargetResourceResult.IsActive | Should -BeTrue - $getTargetResourceResult.AddressFamily | Should -Be 'InterNetworkV6' - $getTargetResourceResult.TcpDynamicPort | Should -BeExactly '0' + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeTrue + $getTargetResourceResult.IPAddress | Should-Be 'fe80::7894:a6b6:59dd:c8ff%9' + $getTargetResourceResult.UseTcpDynamicPort | Should-BeTrue + $getTargetResourceResult.TcpPort | Should-BeFalsy + $getTargetResourceResult.IsActive | Should-BeTrue + $getTargetResourceResult.AddressFamily | Should-Be 'InterNetworkV6' + $getTargetResourceResult.TcpDynamicPort | Should-BeString -CaseSensitive '0' } } } @@ -351,19 +351,19 @@ Describe 'SqlProtocolTcpIp\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @getTargetResourceParameters - $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName - $getTargetResourceResult.IpAddressGroup | Should -BeExactly 'IP1' + $getTargetResourceResult.InstanceName | Should-Be $mockInstanceName + $getTargetResourceResult.IpAddressGroup | Should-BeString -CaseSensitive 'IP1' # Use the helper function from inside the module (DscResource.Common). - $getTargetResourceResult.ServerName | Should -Be (Get-ComputerName) - $getTargetResourceResult.SuppressRestart | Should -BeFalse - $getTargetResourceResult.RestartTimeout | Should -Be 120 - $getTargetResourceResult.Enabled | Should -BeTrue - $getTargetResourceResult.IPAddress | Should -Be 'fe80::7894:a6b6:59dd:c8ff%9' - $getTargetResourceResult.UseTcpDynamicPort | Should -BeFalse - $getTargetResourceResult.TcpPort | Should -BeExactly '1433,1500,1501' - $getTargetResourceResult.IsActive | Should -BeTrue - $getTargetResourceResult.AddressFamily | Should -Be 'InterNetworkV6' - $getTargetResourceResult.TcpDynamicPort | Should -BeNullOrEmpty + $getTargetResourceResult.ServerName | Should-Be (Get-ComputerName) + $getTargetResourceResult.SuppressRestart | Should-BeFalse + $getTargetResourceResult.RestartTimeout | Should-Be 120 + $getTargetResourceResult.Enabled | Should-BeTrue + $getTargetResourceResult.IPAddress | Should-Be 'fe80::7894:a6b6:59dd:c8ff%9' + $getTargetResourceResult.UseTcpDynamicPort | Should-BeFalse + $getTargetResourceResult.TcpPort | Should-BeString -CaseSensitive '1433,1500,1501' + $getTargetResourceResult.IsActive | Should-BeTrue + $getTargetResourceResult.AddressFamily | Should-Be 'InterNetworkV6' + $getTargetResourceResult.TcpDynamicPort | Should-BeFalsy } } } @@ -394,10 +394,10 @@ Describe 'SqlProtocolTcpIp\Test-TargetResource' -Tag 'Test' { } $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeTrue + $testTargetResourceResult | Should-BeTrue } - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } @@ -423,10 +423,10 @@ Describe 'SqlProtocolTcpIp\Test-TargetResource' -Tag 'Test' { } $testTargetResourceResult = Test-TargetResource @testTargetResourceParameters - $testTargetResourceResult | Should -BeFalse + $testTargetResourceResult | Should-BeFalse } - Should -Invoke -CommandName Compare-TargetResourceState -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } } @@ -450,7 +450,7 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { TcpPort = '1433' } - { Compare-ResourcePropertyState @testTargetResourceParameters } | Should -Throw + { Compare-ResourcePropertyState @testTargetResourceParameters } | Should-Throw } } } @@ -482,16 +482,16 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'UseTcpDynamicPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -520,16 +520,16 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'TcpPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be '1433' - $comparedReturnValue.Actual | Should -Be '1433' - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be '1433' + $comparedReturnValue.Actual | Should-Be '1433' + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -568,28 +568,28 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'UseTcpDynamicPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'IPAddress' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be $MockIPAddress - $comparedReturnValue.Actual | Should -Be $MockIPAddress - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be $MockIPAddress + $comparedReturnValue.Actual | Should-Be $MockIPAddress + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -626,28 +626,28 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'TcpPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be '1433' - $comparedReturnValue.Actual | Should -Be '1433' - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be '1433' + $comparedReturnValue.Actual | Should-Be '1433' + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'IPAddress' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be $mockIpAddress - $comparedReturnValue.Actual | Should -Be $mockIpAddress - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be $mockIpAddress + $comparedReturnValue.Actual | Should-Be $mockIpAddress + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -680,16 +680,16 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'UseTcpDynamicPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -718,16 +718,16 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'TcpPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be '1433' - $comparedReturnValue.Actual | Should -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be '1433' + $comparedReturnValue.Actual | Should-BeFalsy + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -766,28 +766,28 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'UseTcpDynamicPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'IPAddress' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be $mockIpAddress - $comparedReturnValue.Actual | Should -Be $mockIpAddress - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be $mockIpAddress + $comparedReturnValue.Actual | Should-Be $mockIpAddress + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -824,28 +824,28 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'TcpPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be '1433' - $comparedReturnValue.Actual | Should -BeNullOrEmpty - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be '1433' + $comparedReturnValue.Actual | Should-BeFalsy + $comparedReturnValue.InDesiredState | Should-BeFalse $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'IPAddress' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be $mockIpAddress - $comparedReturnValue.Actual | Should -Be $mockIpAddress - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be $mockIpAddress + $comparedReturnValue.Actual | Should-Be $mockIpAddress + $comparedReturnValue.InDesiredState | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -876,28 +876,28 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 3 + $compareTargetResourceStateResult | Should-BeCollection -Count 3 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'TcpPort' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be '1433' - $comparedReturnValue.Actual | Should -Be '1433' - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be '1433' + $comparedReturnValue.Actual | Should-Be '1433' + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeTrue - $comparedReturnValue.InDesiredState | Should -BeTrue + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeTrue + $comparedReturnValue.InDesiredState | Should-BeTrue $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'IPAddress' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -Be 'fe80::7894:a6b6:59dd:c8ff%9' - $comparedReturnValue.Actual | Should -Be '10.0.0.1' - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-Be 'fe80::7894:a6b6:59dd:c8ff%9' + $comparedReturnValue.Actual | Should-Be '10.0.0.1' + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -926,16 +926,16 @@ Describe 'SqlProtocolTcpIp\Compare-TargetResourceState' -Tag 'Compare' { } $compareTargetResourceStateResult = Compare-TargetResourceState @compareTargetResourceParameters - $compareTargetResourceStateResult | Should -HaveCount 1 + $compareTargetResourceStateResult | Should-BeCollection -Count 1 $comparedReturnValue = $compareTargetResourceStateResult.Where( { $_.ParameterName -eq 'Enabled' }) - $comparedReturnValue | Should -Not -BeNullOrEmpty - $comparedReturnValue.Expected | Should -BeTrue - $comparedReturnValue.Actual | Should -BeFalse - $comparedReturnValue.InDesiredState | Should -BeFalse + $comparedReturnValue | Should-BeTruthy + $comparedReturnValue.Expected | Should-BeTrue + $comparedReturnValue.Actual | Should-BeFalse + $comparedReturnValue.InDesiredState | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -976,7 +976,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { } { Set-TargetResource @setTargetResourceParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -1019,7 +1019,7 @@ Describe 'SqlProtocolTcpIp\Set-TargetResource' -Tag 'Set' { } { Set-TargetResource @setTargetResourceParameters } | - Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -1044,10 +1044,10 @@ 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 + Should-Invoke -CommandName Compare-TargetResourceState -Exactly -Scope It -Times 1 } } @@ -1112,16 +1112,16 @@ 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 object is set correctly. #> - $script:wasMethodAlterCalled | Should -BeTru + $script:wasMethodAlterCalled | Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1185,16 +1185,16 @@ 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 object is set correctly. #> - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1256,16 +1256,16 @@ 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 object is set correctly. #> - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1326,16 +1326,16 @@ 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 object is set correctly. #> - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1402,16 +1402,16 @@ 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 object is set correctly. #> - $script:wasMethodAlterCalled | Should -BeTrue + $script:wasMethodAlterCalled | Should-BeTrue } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -1455,11 +1455,11 @@ 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 - Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/DSC_SqlRS.Tests.ps1 b/tests/Unit/DSC_SqlRS.Tests.ps1 index 151b53c1c..39879feef 100644 --- a/tests/Unit/DSC_SqlRS.Tests.ps1 +++ b/tests/Unit/DSC_SqlRS.Tests.ps1 @@ -186,11 +186,11 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockDefaultParameters - $resultGetTargetResource.InstanceName | Should -Be $mockNamedInstanceName - $resultGetTargetResource.DatabaseServerName | Should -Be $mockReportingServicesDatabaseServerName - $resultGetTargetResource.DatabaseInstanceName | Should -Be $mockReportingServicesDatabaseNamedInstanceName - $resultGetTargetResource.Encrypt | Should -Be 'Optional' - $resultGetTargetResource | Should -BeOfType [System.Collections.Hashtable] + $resultGetTargetResource.InstanceName | Should-Be $mockNamedInstanceName + $resultGetTargetResource.DatabaseServerName | Should-Be $mockReportingServicesDatabaseServerName + $resultGetTargetResource.DatabaseInstanceName | Should-Be $mockReportingServicesDatabaseNamedInstanceName + $resultGetTargetResource.Encrypt | Should-Be 'Optional' + $resultGetTargetResource | Should-HaveType ([System.Collections.Hashtable]) } } @@ -205,17 +205,17 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockDefaultParameters - $resultGetTargetResource.IsInitialized | Should -BeTrue - $resultGetTargetResource.ReportServerVirtualDirectory | Should -Be $mockVirtualDirectoryReportServerName - $resultGetTargetResource.ReportsVirtualDirectory | Should -Be $mockVirtualDirectoryReportManagerName - $resultGetTargetResource.ReportServerReservedUrl | Should -Be $mockReportServerApplicationUrl - $resultGetTargetResource.ReportsReservedUrl | Should -Be $mockReportsApplicationUrl - $resultGetTargetResource.UseSsl | Should -BeFalse + $resultGetTargetResource.IsInitialized | Should-BeTrue + $resultGetTargetResource.ReportServerVirtualDirectory | Should-Be $mockVirtualDirectoryReportServerName + $resultGetTargetResource.ReportsVirtualDirectory | Should-Be $mockVirtualDirectoryReportManagerName + $resultGetTargetResource.ReportServerReservedUrl | Should-Be $mockReportServerApplicationUrl + $resultGetTargetResource.ReportsReservedUrl | Should-Be $mockReportsApplicationUrl + $resultGetTargetResource.UseSsl | Should-BeFalse } - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ListReservedUrls' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } Context 'When SSL is not used' { @@ -229,7 +229,7 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockDefaultParameters - $resultGetTargetResource.UseSsl | Should -BeFalse + $resultGetTargetResource.UseSsl | Should-BeFalse } } } @@ -245,7 +245,7 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockDefaultParameters - $resultGetTargetResource.UseSsl | Should -BeTrue + $resultGetTargetResource.UseSsl | Should-BeTrue } } } @@ -280,10 +280,10 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @testParameters - $resultGetTargetResource.InstanceName | Should -Be $mockDefaultInstanceName - $resultGetTargetResource.DatabaseServerName | Should -Be $mockReportingServicesDatabaseServerName - $resultGetTargetResource.DatabaseInstanceName | Should -Be $mockReportingServicesDatabaseDefaultInstanceName - $resultGetTargetResource | Should -BeOfType [System.Collections.Hashtable] + $resultGetTargetResource.InstanceName | Should-Be $mockDefaultInstanceName + $resultGetTargetResource.DatabaseServerName | Should-Be $mockReportingServicesDatabaseServerName + $resultGetTargetResource.DatabaseInstanceName | Should-Be $mockReportingServicesDatabaseDefaultInstanceName + $resultGetTargetResource | Should-HaveType ([System.Collections.Hashtable]) } } @@ -293,16 +293,16 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @testParameters - $resultGetTargetResource.IsInitialized | Should -BeFalse - $resultGetTargetResource.ReportServerVirtualDirectory | Should -BeNullOrEmpty - $resultGetTargetResource.ReportsVirtualDirectory | Should -BeNullOrEmpty - $resultGetTargetResource.ReportServerReservedUrl | Should -BeNullOrEmpty - $resultGetTargetResource.ReportsReservedUrl | Should -BeNullOrEmpty + $resultGetTargetResource.IsInitialized | Should-BeFalse + $resultGetTargetResource.ReportServerVirtualDirectory | Should-BeFalsy + $resultGetTargetResource.ReportsVirtualDirectory | Should-BeFalsy + $resultGetTargetResource.ReportServerReservedUrl | Should-BeFalsy + $resultGetTargetResource.ReportsReservedUrl | Should-BeFalsy } - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ListReservedUrls' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 } # Regression test for issue #822. @@ -317,7 +317,7 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @testParameters - $resultGetTargetResource.IsInitialized | Should -BeFalse + $resultGetTargetResource.IsInitialized | Should-BeFalse } } } @@ -334,7 +334,7 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @testParameters - $resultGetTargetResource.IsInitialized | Should -BeFalse + $resultGetTargetResource.IsInitialized | Should-BeFalse } } } @@ -353,7 +353,7 @@ Describe 'SqlRS\Get-TargetResource' -Tag 'Get' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-TargetResource @mockDefaultParameters } | Should -Throw -ExpectedMessage ('*' + ($script:localizedData.ReportingServicesNotFound -f $mockDefaultParameters.InstanceName)) + { Get-TargetResource @mockDefaultParameters } | Should-Throw -ExceptionMessage ('*' + ($script:localizedData.ReportingServicesNotFound -f $mockDefaultParameters.InstanceName)) } } } @@ -588,52 +588,52 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { UseSsl = $true } - { Set-TargetResource @mockDefaultParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockDefaultParameters }) } - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'InitializeReportServer' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetDatabaseConnection' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseRightsScript' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseCreationScript' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 2 -Scope It - Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 2 + Should-Invoke -CommandName Restart-ReportingServicesService -Exactly -Scope It -Times 2 } Context 'When there is no Reporting Services instance after Set-TargetResource has been called' { @@ -655,11 +655,11 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Encrypt = 'Mandatory' } - { Set-TargetResource @mockDefaultParameters } | Should -Throw -ExpectedMessage ('*' + $script:localizedData.TestFailedAfterSet) + { Set-TargetResource @mockDefaultParameters } | Should-Throw -ExceptionMessage ('*' + $script:localizedData.TestFailedAfterSet) - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $PesterBoundParameters.Keys -contains 'Encrypt' - } -Times 2 -Exactly -Scope It + } -Scope It -Times 2 } } } @@ -682,7 +682,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { UseSsl = $true } - { Set-TargetResource @mockDefaultParameters } | Should -Throw ('*' + 'Unable to find WMI object Win32_OperatingSystem.') + { Set-TargetResource @mockDefaultParameters } | Should-Throw ('*' + 'Unable to find WMI object Win32_OperatingSystem.') } } } @@ -730,55 +730,55 @@ 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 { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'InitializeReportServer' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetDatabaseConnection' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseRightsScript' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseCreationScript' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Restart-ReportingServicesService -Exactly -Scope It -Times 1 } } @@ -825,55 +825,55 @@ 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 { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'InitializeReportServer' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetDatabaseConnection' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseRightsScript' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseCreationScript' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 2 -Scope It + } -Scope It -Times 2 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Restart-ReportingServicesService -Exactly -Scope It -Times 0 } } @@ -910,51 +910,51 @@ 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 { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'InitializeReportServer' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetDatabaseConnection' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseRightsScript' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseCreationScript' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationNameLegacy - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationNameLegacy - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 2 -Scope It - Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 2 + Should-Invoke -CommandName Restart-ReportingServicesService -Exactly -Scope It -Times 2 - Should -Invoke -CommandName Invoke-SqlDscQuery -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -ParameterFilter { $PesterBoundParameters.Keys -notcontains 'Encrypt' - } -Times 2 -Exactly -Scope It + } -Scope It -Times 2 } } } @@ -1009,51 +1009,51 @@ 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 { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetSecureConnectionLevel' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'RemoveURL' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'InitializeReportServer' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetDatabaseConnection' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseRightsScript' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'GenerateDatabaseCreationScript' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'SetVirtualDirectory' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-RsCimMethod -Exactly -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Invoke-SqlDscQuery -Exactly -Times 2 -Scope It - Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 2 + Should-Invoke -CommandName Restart-ReportingServicesService -Exactly -Scope It -Times 1 } } } @@ -1082,7 +1082,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1110,7 +1110,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1138,7 +1138,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1167,7 +1167,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { } $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1197,7 +1197,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1225,7 +1225,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1253,7 +1253,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1281,7 +1281,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @testParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -1308,7 +1308,7 @@ Describe 'SqlRS\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @defaultParameters - $resultTestTargetResource | Should -BeTrue + $resultTestTargetResource | Should-BeTrue } } } @@ -1357,12 +1357,12 @@ Describe 'SqlRS\Invoke-RsCimMethod' -Tag 'Helper' { } $resultTestTargetResource = Invoke-RsCimMethod @invokeRsCimMethodParameters - $resultTestTargetResource.HRESULT | Should -Be 0 # cSpell: disable-line + $resultTestTargetResource.HRESULT | Should-Be 0 # cSpell: disable-line } - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'AnyMethod' -and $Arguments -eq $null - } -Exactly -Times 1 + } -Times 1 } } @@ -1380,12 +1380,12 @@ Describe 'SqlRS\Invoke-RsCimMethod' -Tag 'Helper' { } $resultTestTargetResource = Invoke-RsCimMethod @invokeRsCimMethodParameters - $resultTestTargetResource.HRESULT | Should -Be 0 # cSpell: disable-line + $resultTestTargetResource.HRESULT | Should-Be 0 # cSpell: disable-line } - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'AnyMethod' -and $Arguments.Argument1 -eq 'ArgumentValue1' - } -Exactly -Times 1 + } -Times 1 } } } @@ -1411,12 +1411,12 @@ Describe 'SqlRS\Invoke-RsCimMethod' -Tag 'Helper' { } # cSpell: disable-next - { Invoke-RsCimMethod @invokeRsCimMethodParameters } | Should -Throw 'Method AnyMethod() failed with an error. Error: Something went wrong (HRESULT:1)' + { Invoke-RsCimMethod @invokeRsCimMethodParameters } | Should-Throw 'Method AnyMethod() failed with an error. Error: Something went wrong (HRESULT:1)' } - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'AnyMethod' - } -Exactly -Times 1 + } -Times 1 } } @@ -1439,12 +1439,12 @@ Describe 'SqlRS\Invoke-RsCimMethod' -Tag 'Helper' { } # cSpell: disable-next - { Invoke-RsCimMethod @invokeRsCimMethodParameters } | Should -Throw 'Method AnyMethod() failed with an error. Error: Something went wrong;Another thing went wrong (HRESULT:1)' + { Invoke-RsCimMethod @invokeRsCimMethodParameters } | Should-Throw 'Method AnyMethod() failed with an error. Error: Something went wrong;Another thing went wrong (HRESULT:1)' } - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'AnyMethod' - } -Exactly -Times 1 + } -Times 1 } } } @@ -1556,26 +1556,22 @@ Describe 'SqlRS\Get-ReportingServicesData' -Tag 'Helper' { $getReportingServicesDataResult = Get-ReportingServicesData -InstanceName 'INSTANCE' - $getReportingServicesDataResult.Configuration | Should -BeOfType [Microsoft.Management.Infrastructure.CimInstance] - $getReportingServicesDataResult.Configuration.InstanceName | Should -Be 'INSTANCE' - $getReportingServicesDataResult.Configuration.DatabaseServerName | Should -Be 'MockDatabaseServer\MockDatabaseInstance' - $getReportingServicesDataResult.Configuration.IsInitialized | Should -BeFalse - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should -Be 'ReportServer' - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should -Be 'Reports' - $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should -Be 0 - $getReportingServicesDataResult.ReportsApplicationName | Should -Be 'ReportManager' - $getReportingServicesDataResult.SqlVersion | Should -Be '12' + $getReportingServicesDataResult.Configuration | Should-HaveType ([Microsoft.Management.Infrastructure.CimInstance]) + $getReportingServicesDataResult.Configuration.InstanceName | Should-Be 'INSTANCE' + $getReportingServicesDataResult.Configuration.DatabaseServerName | Should-Be 'MockDatabaseServer\MockDatabaseInstance' + $getReportingServicesDataResult.Configuration.IsInitialized | Should-BeFalse + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should-Be 'ReportServer' + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should-Be 'Reports' + $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should-Be 0 + $getReportingServicesDataResult.ReportsApplicationName | Should-Be 'ReportManager' + $getReportingServicesDataResult.SqlVersion | Should-Be '12' } - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter ` - -Exactly -Times 2 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter -Scope 'It' -Times 2 - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_Sql2014AndSql2016_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_Sql2014AndSql2016_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope 'It' -Times 1 } } @@ -1596,26 +1592,22 @@ Describe 'SqlRS\Get-ReportingServicesData' -Tag 'Helper' { $getReportingServicesDataResult = Get-ReportingServicesData -InstanceName 'INSTANCE' - $getReportingServicesDataResult.Configuration | Should -BeOfType [Microsoft.Management.Infrastructure.CimInstance] - $getReportingServicesDataResult.Configuration.InstanceName | Should -Be 'INSTANCE' - $getReportingServicesDataResult.Configuration.DatabaseServerName | Should -Be 'MockDatabaseServer\MockDatabaseInstance' - $getReportingServicesDataResult.Configuration.IsInitialized | Should -BeFalse - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should -Be 'ReportServer' - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should -Be 'Reports' - $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should -Be 0 - $getReportingServicesDataResult.ReportsApplicationName | Should -Be 'ReportServerWebApp' - $getReportingServicesDataResult.SqlVersion | Should -Be '13' + $getReportingServicesDataResult.Configuration | Should-HaveType ([Microsoft.Management.Infrastructure.CimInstance]) + $getReportingServicesDataResult.Configuration.InstanceName | Should-Be 'INSTANCE' + $getReportingServicesDataResult.Configuration.DatabaseServerName | Should-Be 'MockDatabaseServer\MockDatabaseInstance' + $getReportingServicesDataResult.Configuration.IsInitialized | Should-BeFalse + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should-Be 'ReportServer' + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should-Be 'Reports' + $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should-Be 0 + $getReportingServicesDataResult.ReportsApplicationName | Should-Be 'ReportServerWebApp' + $getReportingServicesDataResult.SqlVersion | Should-Be '13' } - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter ` - -Exactly -Times 2 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter -Scope 'It' -Times 2 - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_Sql2014AndSql2016_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_Sql2014AndSql2016_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope 'It' -Times 1 } } @@ -1636,26 +1628,22 @@ Describe 'SqlRS\Get-ReportingServicesData' -Tag 'Helper' { $getReportingServicesDataResult = Get-ReportingServicesData -InstanceName 'INSTANCE' - $getReportingServicesDataResult.Configuration | Should -BeOfType [Microsoft.Management.Infrastructure.CimInstance] - $getReportingServicesDataResult.Configuration.InstanceName | Should -Be 'INSTANCE' - $getReportingServicesDataResult.Configuration.DatabaseServerName | Should -Be 'MockDatabaseServer\MockDatabaseInstance' - $getReportingServicesDataResult.Configuration.IsInitialized | Should -BeFalse - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should -Be 'ReportServer' - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should -Be 'Reports' - $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should -Be 0 - $getReportingServicesDataResult.ReportsApplicationName | Should -Be 'ReportServerWebApp' - $getReportingServicesDataResult.SqlVersion | Should -Be '14' + $getReportingServicesDataResult.Configuration | Should-HaveType ([Microsoft.Management.Infrastructure.CimInstance]) + $getReportingServicesDataResult.Configuration.InstanceName | Should-Be 'INSTANCE' + $getReportingServicesDataResult.Configuration.DatabaseServerName | Should-Be 'MockDatabaseServer\MockDatabaseInstance' + $getReportingServicesDataResult.Configuration.IsInitialized | Should-BeFalse + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should-Be 'ReportServer' + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should-Be 'Reports' + $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should-Be 0 + $getReportingServicesDataResult.ReportsApplicationName | Should-Be 'ReportServerWebApp' + $getReportingServicesDataResult.SqlVersion | Should-Be '14' } - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter ` - -Exactly -Times 2 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter -Scope 'It' -Times 2 - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_Sql2017AndSql2019_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_Sql2017AndSql2019_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope 'It' -Times 1 } } @@ -1676,26 +1664,22 @@ Describe 'SqlRS\Get-ReportingServicesData' -Tag 'Helper' { $getReportingServicesDataResult = Get-ReportingServicesData -InstanceName 'INSTANCE' - $getReportingServicesDataResult.Configuration | Should -BeOfType [Microsoft.Management.Infrastructure.CimInstance] - $getReportingServicesDataResult.Configuration.InstanceName | Should -Be 'INSTANCE' - $getReportingServicesDataResult.Configuration.DatabaseServerName | Should -Be 'MockDatabaseServer\MockDatabaseInstance' - $getReportingServicesDataResult.Configuration.IsInitialized | Should -BeFalse - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should -Be 'ReportServer' - $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should -Be 'Reports' - $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should -Be 0 - $getReportingServicesDataResult.ReportsApplicationName | Should -Be 'ReportServerWebApp' - $getReportingServicesDataResult.SqlVersion | Should -Be '15' + $getReportingServicesDataResult.Configuration | Should-HaveType ([Microsoft.Management.Infrastructure.CimInstance]) + $getReportingServicesDataResult.Configuration.InstanceName | Should-Be 'INSTANCE' + $getReportingServicesDataResult.Configuration.DatabaseServerName | Should-Be 'MockDatabaseServer\MockDatabaseInstance' + $getReportingServicesDataResult.Configuration.IsInitialized | Should-BeFalse + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportServer | Should-Be 'ReportServer' + $getReportingServicesDataResult.Configuration.VirtualDirectoryReportManager | Should-Be 'Reports' + $getReportingServicesDataResult.Configuration.SecureConnectionLevel | Should-Be 0 + $getReportingServicesDataResult.ReportsApplicationName | Should-Be 'ReportServerWebApp' + $getReportingServicesDataResult.SqlVersion | Should-Be '15' } - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter ` - -Exactly -Times 2 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_InstanceNames_ParameterFilter -Scope 'It' -Times 2 - Should -Invoke -CommandName Get-ItemProperty ` - -ParameterFilter $mockGetItemProperty_Sql2017AndSql2019_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_Sql2017AndSql2019_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope 'It' -Times 1 } } } diff --git a/tests/Unit/DSC_SqlRSSetup.Tests.ps1 b/tests/Unit/DSC_SqlRSSetup.Tests.ps1 index 4f862b487..1fa95bf02 100644 --- a/tests/Unit/DSC_SqlRSSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlRSSetup.Tests.ps1 @@ -90,10 +90,10 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { Set-StrictMode -Version 1.0 $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -BeNullOrEmpty + $result.InstanceName | Should-BeFalsy } - Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -Scope 'It' -Times 1 } It 'Should return the same values as passed as parameters' { @@ -102,11 +102,11 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IAcceptLicenseTerms | Should -Be $mockGetTargetResourceParameters.IAcceptLicenseTerms - $result.SourcePath | Should -Be $mockGetTargetResourceParameters.SourcePath + $result.IAcceptLicenseTerms | Should-Be $mockGetTargetResourceParameters.IAcceptLicenseTerms + $result.SourcePath | Should-Be $mockGetTargetResourceParameters.SourcePath } - Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -Scope 'It' -Times 1 } It 'Should return $null or $false for the rest of the properties' { @@ -115,20 +115,20 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Action | Should -BeNullOrEmpty - $getTargetResourceResult.SourceCredential | Should -BeNullOrEmpty - $getTargetResourceResult.ProductKey | Should -BeNullOrEmpty - $getTargetResourceResult.ForceRestart | Should -BeFalse - $getTargetResourceResult.EditionUpgrade | Should -BeFalse - $getTargetResourceResult.Edition | Should -BeNullOrEmpty - $getTargetResourceResult.LogPath | Should -BeNullOrEmpty - $getTargetResourceResult.InstallFolder | Should -BeNullOrEmpty - $getTargetResourceResult.ErrorDumpDirectory | Should -BeNullOrEmpty - $getTargetResourceResult.CurrentVersion | Should -BeNullOrEmpty - $getTargetResourceResult.ServiceName | Should -BeNullOrEmpty + $getTargetResourceResult.Action | Should-BeFalsy + $getTargetResourceResult.SourceCredential | Should-BeFalsy + $getTargetResourceResult.ProductKey | Should-BeFalsy + $getTargetResourceResult.ForceRestart | Should-BeFalse + $getTargetResourceResult.EditionUpgrade | Should-BeFalse + $getTargetResourceResult.Edition | Should-BeFalsy + $getTargetResourceResult.LogPath | Should-BeFalsy + $getTargetResourceResult.InstallFolder | Should-BeFalsy + $getTargetResourceResult.ErrorDumpDirectory | Should-BeFalsy + $getTargetResourceResult.CurrentVersion | Should-BeFalsy + $getTargetResourceResult.ServiceName | Should-BeFalsy } - Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -Scope 'It' -Times 1 } } @@ -215,12 +215,10 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Get-RegistryPropertyValue ` - -ParameterFilter $mockGetRegistryPropertyValue_InstanceName_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -ParameterFilter $mockGetRegistryPropertyValue_InstanceName_ParameterFilter -Scope 'It' -Times 1 } It 'Should return the same values as passed as parameters' { @@ -229,8 +227,8 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IAcceptLicenseTerms | Should -Be $mockGetTargetResourceParameters.IAcceptLicenseTerms - $result.SourcePath | Should -Be $mockGetTargetResourceParameters.SourcePath + $result.IAcceptLicenseTerms | Should-Be $mockGetTargetResourceParameters.IAcceptLicenseTerms + $result.SourcePath | Should-Be $mockGetTargetResourceParameters.SourcePath } } @@ -240,32 +238,26 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.Action | Should -BeNullOrEmpty - $getTargetResourceResult.SourceCredential | Should -BeNullOrEmpty - $getTargetResourceResult.ProductKey | Should -BeNullOrEmpty - $getTargetResourceResult.ForceRestart | Should -BeFalse - $getTargetResourceResult.EditionUpgrade | Should -BeFalse - $getTargetResourceResult.Edition | Should -BeNullOrEmpty - $getTargetResourceResult.LogPath | Should -BeNullOrEmpty - $getTargetResourceResult.InstallFolder | Should -Be 'C:\Program Files\Microsoft SQL Server Reporting Services' - $getTargetResourceResult.ErrorDumpDirectory | Should -Be 'C:\Program Files\Microsoft SQL Server Reporting Services\SSRS\LogFiles' - $getTargetResourceResult.CurrentVersion | Should -Be '14.0.6514.11481' - $getTargetResourceResult.ServiceName | Should -Be 'SQLServerReportingServices' + $getTargetResourceResult.Action | Should-BeFalsy + $getTargetResourceResult.SourceCredential | Should-BeFalsy + $getTargetResourceResult.ProductKey | Should-BeFalsy + $getTargetResourceResult.ForceRestart | Should-BeFalse + $getTargetResourceResult.EditionUpgrade | Should-BeFalse + $getTargetResourceResult.Edition | Should-BeFalsy + $getTargetResourceResult.LogPath | Should-BeFalsy + $getTargetResourceResult.InstallFolder | Should-Be 'C:\Program Files\Microsoft SQL Server Reporting Services' + $getTargetResourceResult.ErrorDumpDirectory | Should-Be 'C:\Program Files\Microsoft SQL Server Reporting Services\SSRS\LogFiles' + $getTargetResourceResult.CurrentVersion | Should-Be '14.0.6514.11481' + $getTargetResourceResult.ServiceName | Should-Be 'SQLServerReportingServices' } - Should -Invoke -CommandName Get-RegistryPropertyValue ` - -ParameterFilter $mockGetRegistryPropertyValue_InstallRootDirectory_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -ParameterFilter $mockGetRegistryPropertyValue_InstallRootDirectory_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-RegistryPropertyValue ` - -ParameterFilter $mockGetRegistryPropertyValue_ServiceName_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -ParameterFilter $mockGetRegistryPropertyValue_ServiceName_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-RegistryPropertyValue ` - -ParameterFilter $mockGetRegistryPropertyValue_ErrorDumpDir_ParameterFilter ` - -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -ParameterFilter $mockGetRegistryPropertyValue_ErrorDumpDir_ParameterFilter -Scope 'It' -Times 1 - Should -Invoke -CommandName Get-Package -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-Package -Exactly -Scope 'It' -Times 1 } Context 'When there is an installed Reporting Services, but no installed package is found to determine version' { @@ -280,10 +272,10 @@ Describe 'DSC_SqlRSSetup\Get-TargetResource' -Tag 'Get' { $getTargetResourceResult = Get-TargetResource @mockGetTargetResourceParameters - $getTargetResourceResult.CurrentVersion | Should -BeNullOrEmpty + $getTargetResourceResult.CurrentVersion | Should-BeFalsy } - Should -Invoke -CommandName Write-Warning -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Write-Warning -Exactly -Scope 'It' -Times 1 } } } @@ -326,10 +318,10 @@ Describe 'DSC_SqlRSSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope 'It' -Times 1 } } @@ -353,11 +345,11 @@ Describe 'DSC_SqlRSSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It' - Should -Invoke -CommandName Get-FileProductVersion -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope 'It' -Times 1 + Should-Invoke -CommandName Get-FileProductVersion -Exactly -Scope 'It' -Times 1 } } @@ -382,11 +374,11 @@ Describe 'DSC_SqlRSSetup\Test-TargetResource' -Tag 'Test' { # This is called without the parameter 'VersionUpgrade'. $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It' - Should -Invoke -CommandName Get-FileProductVersion -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope 'It' -Times 1 + Should-Invoke -CommandName Get-FileProductVersion -Exactly -Scope 'It' -Times 1 } } } @@ -409,10 +401,10 @@ Describe 'DSC_SqlRSSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope 'It' -Times 1 } } @@ -435,10 +427,10 @@ Describe 'DSC_SqlRSSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters -Verbose - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope 'It' -Times 1 } } @@ -464,11 +456,11 @@ Describe 'DSC_SqlRSSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters -Verbose - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It' - Should -Invoke -CommandName Get-FileProductVersion -Exactly -Times 1 -Scope 'It' + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope 'It' -Times 1 + Should-Invoke -CommandName Get-FileProductVersion -Exactly -Scope 'It' -Times 1 } } } @@ -533,8 +525,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { } # Start by checking whether we have the same number of parameters - $actualValues.Count | Should -Be $ExpectedArgument.Count ` - -Because ('the expected arguments was: {0}' -f ($ExpectedArgument.Keys -join ',')) + $actualValues.Count | Should-Be $ExpectedArgument.Count -Because ('the expected arguments was: {0}' -f ($ExpectedArgument.Keys -join ',')) Write-Verbose -Message 'Verified actual setup argument values against expected setup argument values' -Verbose @@ -547,8 +538,8 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $argumentValue = $actualValues.$argumentKey - $argumentKeyName | Should -Be $argumentKey - $argumentValue | Should -Be $ExpectedArgument.$argumentKey + $argumentKeyName | Should-Be $argumentKey + $argumentValue | Should-Be $ExpectedArgument.$argumentKey } } @@ -590,7 +581,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $errorMessage = $script:localizedData.SourcePathNotFound -f $script:mockSetTargetResourceParameters.SourcePath { Set-TargetResource @mockSetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $errorMessage + " (Parameter 'SourcePath')") + Should-Throw -ExceptionMessage ('*' + $errorMessage + " (Parameter 'SourcePath')") } } } @@ -617,7 +608,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $errorMessage = $script:localizedData.SourcePathNotFound -f $script:mockSetTargetResourceParameters.SourcePath { Set-TargetResource @mockSetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $errorMessage + " (Parameter 'SourcePath')") + Should-Throw -ExceptionMessage ('*' + $errorMessage + " (Parameter 'SourcePath')") } } } @@ -631,7 +622,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['ProductKey'] = $script:mockProductKey { Set-TargetResource @mockSetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $script:localizedData.EditionInvalidParameter + " (Parameter 'Edition, ProductKey')") + Should-Throw -ExceptionMessage ('*' + $script:localizedData.EditionInvalidParameter + " (Parameter 'Edition, ProductKey')") } } } @@ -642,7 +633,7 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { Set-StrictMode -Version 1.0 { Set-TargetResource @mockSetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $script:localizedData.EditionMissingParameter + " (Parameter 'Edition, ProductKey')") + Should-Throw -ExceptionMessage ('*' + $script:localizedData.EditionMissingParameter + " (Parameter 'Edition, ProductKey')") } } } @@ -681,12 +672,12 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['ProductKey'] = $script:mockProductKey - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -710,12 +701,12 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Action'] = 'Uninstall' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -740,12 +731,12 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Edition'] = 'Development' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -778,12 +769,12 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['EditionUpgrade'] = $true $script:mockSetTargetResourceParameters['InstallFolder'] = 'C:\Temp' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -809,12 +800,12 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['ProductKey'] = $script:mockProductKey $script:mockSetTargetResourceParameters['SuppressRestart'] = $false - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -840,12 +831,12 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['ProductKey'] = $script:mockProductKey $script:mockSetTargetResourceParameters['EditionUpgrade'] = $false - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -882,14 +873,14 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['ProductKey'] = $script:mockProductKey $script:mockSetTargetResourceParameters['SourceCredential'] = $mockShareCredential - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Invoke-InstallationMediaCopy -Exactly -Times 1 -Scope 'It' - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Invoke-InstallationMediaCopy -Exactly -Scope 'It' -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { # Have to build the correct path (local path + executable). $FilePath -eq (Join-Path -Path $mockLocalPath -ChildPath (Split-Path -Path (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) -Leaf)) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -914,15 +905,15 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Edition'] = 'Development' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 # Should set the global DSCMachineStatus variable. - $global:DSCMachineStatus | Should -Be 1 + $global:DSCMachineStatus | Should-Be 1 } Context 'When the Reporting Services installation is successful with exit code 3010, and called with parameter SuppressRestart' { @@ -937,15 +928,15 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Edition'] = 'Development' $script:mockSetTargetResourceParameters['SuppressRestart'] = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 # Should not set the global DSCMachineStatus variable. - $global:DSCMachineStatus | Should -Be 0 + $global:DSCMachineStatus | Should-Be 0 } } } @@ -973,16 +964,16 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Edition'] = 'Development' $script:mockSetTargetResourceParameters['ForceRestart'] = $true - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } # Should set the global DSCMachineStatus variable. - $global:DSCMachineStatus | Should -Be 1 + $global:DSCMachineStatus | Should-Be 1 - Should -Invoke -CommandName Test-PendingRestart -Exactly -Times 0 -Scope 'It' - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Test-PendingRestart -Exactly -Scope 'It' -Times 0 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -1011,16 +1002,16 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Edition'] = 'Development' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } # Should set the global DSCMachineStatus variable. - $global:DSCMachineStatus | Should -Be 1 + $global:DSCMachineStatus | Should-Be 1 - Should -Invoke -CommandName Test-PendingRestart -Exactly -Times 1 -Scope 'It' - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Test-PendingRestart -Exactly -Scope 'It' -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 } } @@ -1045,15 +1036,15 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $script:mockSetTargetResourceParameters['Edition'] = 'Development' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $script:localizedData.SetupFailed) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $script:localizedData.SetupFailed) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 # Should not set the global DSCMachineStatus variable. - $global:DSCMachineStatus | Should -Be 0 + $global:DSCMachineStatus | Should-Be 0 } Context 'When the Reporting Services installation fails, and called with parameter LogPath' { @@ -1075,15 +1066,15 @@ Describe "DSC_SqlRSSetup\Set-TargetResource" -Tag 'Set' { $errorMessage = $script:localizedData.SetupFailedWithLog -f $script:mockSetTargetResourceParameters.LogPath - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $errorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $errorMessage) } - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { $FilePath -eq (InModuleScope -ScriptBlock { $script:mockSetTargetResourceParameters.SourcePath }) - } -Exactly -Times 1 -Scope 'It' + } -Scope 'It' -Times 1 # Should not set the global DSCMachineStatus variable. - $global:DSCMachineStatus | Should -Be 0 + $global:DSCMachineStatus | Should-Be 0 } } } @@ -1128,7 +1119,7 @@ Describe "DSC_SqlRSSetup\Convert-EditionName" -Tag 'Helper' { } -ScriptBlock { Set-StrictMode -Version 1.0 - Convert-EditionName -Name $InputName | Should -Be $OutputName + Convert-EditionName -Name $InputName | Should-Be $OutputName } } } @@ -1150,7 +1141,7 @@ Describe "DSC_SqlRSSetup\Get-FileProductVersion" -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - Get-FileProductVersion -Path 'TestDrive:\MockExecutable.exe' | Should -Be '14.0.0.0' + Get-FileProductVersion -Path 'TestDrive:\MockExecutable.exe' | Should-Be '14.0.0.0' } } } diff --git a/tests/Unit/DSC_SqlReplication.Tests.ps1 b/tests/Unit/DSC_SqlReplication.Tests.ps1 index 03b5117c7..26359ccc3 100644 --- a/tests/Unit/DSC_SqlReplication.Tests.ps1 +++ b/tests/Unit/DSC_SqlReplication.Tests.ps1 @@ -85,7 +85,7 @@ Describe 'Helper functions' { #> $mockComputerName = Get-ComputerName - Get-SqlLocalServerName -InstanceName MSSQLSERVER | Should -Be $mockComputerName + Get-SqlLocalServerName -InstanceName MSSQLSERVER | Should-Be $mockComputerName } } @@ -97,7 +97,7 @@ Describe 'Helper functions' { #> $mockComputerName = Get-ComputerName - Get-SqlLocalServerName -InstanceName InstanceName | Should -Be "$($mockComputerName)\InstanceName" + Get-SqlLocalServerName -InstanceName InstanceName | Should-Be "$($mockComputerName)\InstanceName" } } } @@ -150,78 +150,74 @@ Describe 'The system is not in the desired state given Local distribution mode' } It 'Get method calls Get-SqlInstanceMajorVersion with InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Absent' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } It 'Get method returns InstanceName = ''MSSQLSERVER''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode as $null' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -BeNullOrEmpty + $result.DistributorMode | Should-BeFalsy } } It 'Get method returns DistributionDBName as $null' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -BeNullOrEmpty + $result.DistributionDBName | Should-BeFalsy } } It 'Get method returns RemoteDistributor as $null' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -BeNullOrEmpty + $result.RemoteDistributor | Should-BeFalsy } } It 'Get method returns WorkingDirectory as $null' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -BeNullOrEmpty + $result.WorkingDirectory | Should-BeFalsy } } } @@ -230,7 +226,7 @@ Describe 'The system is not in the desired state given Local distribution mode' Context 'Test method' { It 'Test method returns false' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeFalse + Test-TargetResource @mockTestParameters | Should-BeFalse } } } @@ -243,46 +239,39 @@ Describe 'The system is not in the desired state given Local distribution mode' } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Set method calls New-DistributionDatabase with $DistributionDBName = distribution' { - Should -Invoke -CommandName New-DistributionDatabase -Times 1 ` - -ParameterFilter { $DistributionDBName -eq 'distribution' } + Should-Invoke -CommandName New-DistributionDatabase -ParameterFilter { $DistributionDBName -eq 'distribution' } -Times 1 } It 'Set method calls Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 1 ` - -ParameterFilter { $ReplicationServer.DistributionServer -eq 'SERVERNAME' } + Should-Invoke -CommandName Install-LocalDistributor -ParameterFilter { $ReplicationServer.DistributionServer -eq 'SERVERNAME' } -Times 1 } It 'Set method calls Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 1 ` - -ParameterFilter { $PublisherName -eq 'SERVERNAME' } + Should-Invoke -CommandName Register-DistributorPublisher -ParameterFilter { $PublisherName -eq 'SERVERNAME' } -Times 1 } It 'Set method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Set method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } } } @@ -336,78 +325,74 @@ Describe 'The system is not in the desired state given Remote distribution mode' } It 'Get method calls Get-SqlInstanceMajorVersion with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Absent' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } It 'Get method returns InstanceName = ''INSTANCENAME''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode as $null' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -BeNullOrEmpty + $result.DistributorMode | Should-BeFalsy } } It 'Get method returns DistributionDBName as $null' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -BeNullOrEmpty + $result.DistributionDBName | Should-BeFalsy } } It 'Get method returns RemoteDistributor as $null' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -BeNullOrEmpty + $result.RemoteDistributor | Should-BeFalsy } } It 'Get method returns WorkingDirectory as $null' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -BeNullOrEmpty + $result.WorkingDirectory | Should-BeFalsy } } } @@ -416,7 +401,7 @@ Describe 'The system is not in the desired state given Remote distribution mode' Context 'Test method' { It 'Test method returns false' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeFalse + Test-TargetResource @mockTestParameters | Should-BeFalse } } } @@ -429,49 +414,42 @@ Describe 'The system is not in the desired state given Remote distribution mode' } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = ''REMOTESERVER''' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'REMOTESERVER' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'REMOTESERVER' } -Times 1 } It 'Set method calls Register-DistributorPublisher with RemoteDistributor connection' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 1 ` - -ParameterFilter { + Should-Invoke -CommandName Register-DistributorPublisher -ParameterFilter { $PublisherName -eq 'SERVERNAME\INSTANCENAME' ` -and $ServerConnection.ServerInstance -eq 'REMOTESERVER' - } + } -Times 1 } It 'Set method calls Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 1 ` - -ParameterFilter { $RemoteDistributor -eq 'REMOTESERVER' } + Should-Invoke -CommandName Install-RemoteDistributor -ParameterFilter { $RemoteDistributor -eq 'REMOTESERVER' } -Times 1 } It 'Set method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Set method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } } @@ -486,7 +464,7 @@ Describe 'The system is not in the desired state given Remote distribution mode' InModuleScope -ScriptBlock { $mockErrorMessage = '{0} (Parameter ''RemoteDistributor'')' -f $script:localizedData.NoRemoteDistributor - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -539,78 +517,74 @@ Describe 'The system is in sync given Local distribution mode' { } It 'Get method calls Get-SqlInstanceMajorVersion with InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Present' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } It 'Get method returns InstanceName = ''MSSQLSERVER''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode = ''Local''' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -Be $mockTestParameters.DistributorMode + $result.DistributorMode | Should-Be $mockTestParameters.DistributorMode } } It 'Get method returns DistributionDBName = ''distribution''' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -Be 'distribution' + $result.DistributionDBName | Should-Be 'distribution' } } It 'Get method returns RemoteDistributor = ''SERVERNAME''' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -Be 'SERVERNAME' + $result.RemoteDistributor | Should-Be 'SERVERNAME' } } It 'Get method returns WorkingDirectory = ''C:\temp''' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -Be 'C:\temp' + $result.WorkingDirectory | Should-Be 'C:\temp' } } } @@ -618,7 +592,7 @@ Describe 'The system is in sync given Local distribution mode' { Context 'Test method' { It 'Test method returns true' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeTrue + Test-TargetResource @mockTestParameters | Should-BeTrue } } } @@ -631,43 +605,39 @@ Describe 'The system is in sync given Local distribution mode' { } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Set method does not call New-DistributionDatabase with $DistributionDBName = distribution' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Set method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Set method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Set method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Set method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } } } @@ -720,78 +690,74 @@ Describe 'The system is in sync given Remote distribution mode' { } It 'Get method calls Get-SqlInstanceMajorVersion with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Present' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } It 'Get method returns InstanceName = ''INSTANCENAME''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode = ''Remote''' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -Be $mockTestParameters.DistributorMode + $result.DistributorMode | Should-Be $mockTestParameters.DistributorMode } } It 'Get method returns DistributionDBName = distribution' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -Be 'distribution' + $result.DistributionDBName | Should-Be 'distribution' } } It 'Get method returns RemoteDistributor = ''REMOTESERVER''' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -Be $mockTestParameters.RemoteDistributor + $result.RemoteDistributor | Should-Be $mockTestParameters.RemoteDistributor } } It 'Get method returns WorkingDirectory = C:\temp' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -Be 'C:\temp' + $result.WorkingDirectory | Should-Be 'C:\temp' } } } @@ -799,7 +765,7 @@ Describe 'The system is in sync given Remote distribution mode' { Context 'Test method' { It 'Test method returns true' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeTrue + Test-TargetResource @mockTestParameters | Should-BeTrue } } } @@ -812,43 +778,39 @@ Describe 'The system is in sync given Remote distribution mode' { } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Set method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Set method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Set method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Set method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Set method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } } } @@ -899,78 +861,74 @@ Describe 'The system is not in desired state given Local distribution, but shoul } } It 'Get method calls Get-SqlInstanceMajorVersion with InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Present' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } It 'Get method returns InstanceName = ''MSSQLSERVER''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode = ''Local''' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -Be $mockTestParameters.DistributorMode + $result.DistributorMode | Should-Be $mockTestParameters.DistributorMode } } It 'Get method returns DistributionDBName = distribution' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -Be 'distribution' + $result.DistributionDBName | Should-Be 'distribution' } } It 'Get method returns RemoteDistributor is empty' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -Be 'SERVERNAME' + $result.RemoteDistributor | Should-Be 'SERVERNAME' } } It 'Get method returns WorkingDirectory = C:\temp' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -Be 'C:\temp' + $result.WorkingDirectory | Should-Be 'C:\temp' } } } @@ -978,7 +936,7 @@ Describe 'The system is not in desired state given Local distribution, but shoul Context 'Test method' { It 'Test method returns false' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeFalse + Test-TargetResource @mockTestParameters | Should-BeFalse } } } @@ -991,44 +949,39 @@ Describe 'The system is not in desired state given Local distribution, but shoul } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Set method calls Uninstall-Distributor with $ReplicationServer.DistributionServer = SERVERNAME' { - Should -Invoke -CommandName Uninstall-Distributor -Times 1 ` - -ParameterFilter { $ReplicationServer.DistributionServer -eq 'SERVERNAME' } + Should-Invoke -CommandName Uninstall-Distributor -ParameterFilter { $ReplicationServer.DistributionServer -eq 'SERVERNAME' } -Times 1 } It 'Set method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Set method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Set method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Set method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } } } @@ -1081,78 +1034,74 @@ Describe 'The system is not in desired state given Remote distribution, but shou } It 'Get method calls Get-SqlInstanceMajorVersion with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Present' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } It 'Get method returns InstanceName = ''INSTANCENAME''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode = ''Remote''' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -Be $mockTestParameters.DistributorMode + $result.DistributorMode | Should-Be $mockTestParameters.DistributorMode } } It 'Get method returns DistributionDBName = distribution' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -Be 'distribution' + $result.DistributionDBName | Should-Be 'distribution' } } It 'Get method returns RemoteDistributor = ''REMOTESERVER''' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -Be $mockTestParameters.RemoteDistributor + $result.RemoteDistributor | Should-Be $mockTestParameters.RemoteDistributor } } It 'Get method returns WorkingDirectory = C:\temp' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -Be 'C:\temp' + $result.WorkingDirectory | Should-Be 'C:\temp' } } } @@ -1160,7 +1109,7 @@ Describe 'The system is not in desired state given Remote distribution, but shou Context 'Test method' { It 'Test method returns false' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeFalse + Test-TargetResource @mockTestParameters | Should-BeFalse } } } @@ -1173,44 +1122,39 @@ Describe 'The system is not in desired state given Remote distribution, but shou } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = INSTANCENAME' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'INSTANCENAME' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME\INSTANCENAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME\INSTANCENAME' } -Times 1 } It 'Set method calls Uninstall-Distributor with $ReplicationServer.DistributionServer = REMOTESERVER' { - Should -Invoke -CommandName Uninstall-Distributor -Times 1 ` - -ParameterFilter { $ReplicationServer.DistributionServer -eq 'REMOTESERVER' } + Should-Invoke -CommandName Uninstall-Distributor -ParameterFilter { $ReplicationServer.DistributionServer -eq 'REMOTESERVER' } -Times 1 } It 'Set method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Set method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Set method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Set method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } } } @@ -1262,78 +1206,74 @@ Describe 'The system is in sync when Absent' { } It 'Get method calls Get-SqlInstanceMajorVersion with InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Get method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Get method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Get method does not call New-DistributionDatabase' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Get method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Get method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Ger method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Ger method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } It 'Get method returns Ensure = Absent' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } It 'Get method returns InstanceName = ''MSSQLSERVER''' { InModuleScope -ScriptBlock { - $result.InstanceName | Should -Be $mockTestParameters.InstanceName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName } } It 'Get method returns DistributorMode as $null' { InModuleScope -ScriptBlock { - $result.DistributorMode | Should -BeNullOrEmpty + $result.DistributorMode | Should-BeFalsy } } It 'Get method returns DistributionDBName as $null' { InModuleScope -ScriptBlock { - $result.DistributionDBName | Should -BeNullOrEmpty + $result.DistributionDBName | Should-BeFalsy } } It 'Get method returns RemoteDistributor as $null' { InModuleScope -ScriptBlock { - $result.RemoteDistributor | Should -BeNullOrEmpty + $result.RemoteDistributor | Should-BeFalsy } } It 'Get method returns WorkingDirectory as $null' { InModuleScope -ScriptBlock { - $result.WorkingDirectory | Should -BeNullOrEmpty + $result.WorkingDirectory | Should-BeFalsy } } } @@ -1341,7 +1281,7 @@ Describe 'The system is in sync when Absent' { Context 'Test method' { It 'Test method returns true' { InModuleScope -ScriptBlock { - Test-TargetResource @mockTestParameters | Should -BeTrue + Test-TargetResource @mockTestParameters | Should-BeTrue } } } @@ -1354,43 +1294,39 @@ Describe 'The system is in sync when Absent' { } It 'Set method calls Get-SqlInstanceMajorVersion with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlInstanceMajorVersion -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlInstanceMajorVersion -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls Get-SqlLocalServerName with $InstanceName = MSSQLSERVER' { - Should -Invoke -CommandName Get-SqlLocalServerName -Times 1 ` - -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } + Should-Invoke -CommandName Get-SqlLocalServerName -ParameterFilter { $InstanceName -eq 'MSSQLSERVER' } -Times 1 } It 'Set method calls New-ServerConnection with $SqlServerName = SERVERNAME' { - Should -Invoke -CommandName New-ServerConnection -Times 1 ` - -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ServerConnection -ParameterFilter { $SqlServerName -eq 'SERVERNAME' } -Times 1 } It 'Set method calls New-ReplicationServer with $ServerConnection.ServerInstance = SERVERNAME' { - Should -Invoke -CommandName New-ReplicationServer -Times 1 ` - -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } + Should-Invoke -CommandName New-ReplicationServer -ParameterFilter { $ServerConnection.ServerInstance -eq 'SERVERNAME' } -Times 1 } It 'Set method does not call New-DistributionDatabase with $DistributionDBName = distribution' { - Should -Invoke -CommandName New-DistributionDatabase -Times 0 + Should-Invoke -CommandName New-DistributionDatabase -Times 0 } It 'Set method does not call Install-LocalDistributor' { - Should -Invoke -CommandName Install-LocalDistributor -Times 0 + Should-Invoke -CommandName Install-LocalDistributor -Times 0 } It 'Set method does not call Install-RemoteDistributor' { - Should -Invoke -CommandName Install-RemoteDistributor -Times 0 + Should-Invoke -CommandName Install-RemoteDistributor -Times 0 } It 'Set method does not call Register-DistributorPublisher' { - Should -Invoke -CommandName Register-DistributorPublisher -Times 0 + Should-Invoke -CommandName Register-DistributorPublisher -Times 0 } It 'Set method does not call Uninstall-Distributor' { - Should -Invoke -CommandName Uninstall-Distributor -Times 0 + Should-Invoke -CommandName Uninstall-Distributor -Times 0 } } } @@ -1409,7 +1345,7 @@ Describe 'New-ServerConnection' { InModuleScope -ScriptBlock { $result = New-ServerConnection -SqlMajorVersion 16 -SqlServerName 'localhost\SqlInstance' - $result | Should -Be 'Mocked server connection object for localhost\SqlInstance' + $result | Should-Be 'Mocked server connection object for localhost\SqlInstance' } } } @@ -1443,7 +1379,7 @@ Describe 'New-ServerConnection' { New-Object call the string will be filled with the value passed as ArgumentList. #> - $result | Should -Be 'localhost\SqlInstance' + $result | Should-Be 'localhost\SqlInstance' } } } diff --git a/tests/Unit/DSC_SqlRole.Tests.ps1 b/tests/Unit/DSC_SqlRole.Tests.ps1 index 530ed4911..d7ed9896c 100644 --- a/tests/Unit/DSC_SqlRole.Tests.ps1 +++ b/tests/Unit/DSC_SqlRole.Tests.ps1 @@ -240,30 +240,30 @@ Describe "DSC_SqlRole\Get-TargetResource" -Tag 'Get' { It 'Should return the state as absent when the role does not exist' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } It 'Should return the members as null' { InModuleScope -ScriptBlock { - $result.membersInRole | Should -BeNullOrEmpty + $result.membersInRole | Should-BeFalsy } } It 'Should return the same values as passed as parameters' { InModuleScope -ScriptBlock { - $result.ServerName | Should -Be $mockTestParameters.ServerName - $result.InstanceName | Should -Be $mockTestParameters.InstanceName - $result.ServerRoleName | Should -Be $mockTestParameters.ServerRoleName + $result.ServerName | Should-Be $mockTestParameters.ServerName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName + $result.ServerRoleName | Should-Be $mockTestParameters.ServerRoleName } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When the system is not in the desired state and ensure is set to Absent' { + Context 'When the system is not in the desired state and ensure is set to default value' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -276,33 +276,33 @@ Describe "DSC_SqlRole\Get-TargetResource" -Tag 'Get' { It 'Should not return the state as absent when the role exist' { InModuleScope -ScriptBlock { - $result.Ensure | Should -Not -Be 'Absent' + $result.Ensure | Should-NotBe 'Absent' } } It 'Should return the members as not null' { InModuleScope -ScriptBlock { - $result.Members | Should -Not -BeNullOrEmpty + $result.Members | Should-BeTruthy } } # Regression test for issue #790 It 'Should return the members as string array' { InModuleScope -ScriptBlock { - ($result.Members -is [System.String[]]) | Should -BeTrue + ($result.Members -is [System.String[]]) | Should-BeTrue } } It 'Should return the same values as passed as parameters' { InModuleScope -ScriptBlock { - $result.ServerName | Should -Be $mockTestParameters.ServerName - $result.InstanceName | Should -Be $mockTestParameters.InstanceName - $result.ServerRoleName | Should -Be $mockTestParameters.ServerRoleName + $result.ServerName | Should-Be $mockTestParameters.ServerName + $result.InstanceName | Should-Be $mockTestParameters.InstanceName + $result.ServerRoleName | Should-Be $mockTestParameters.ServerRoleName } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -323,12 +323,12 @@ Describe "DSC_SqlRole\Get-TargetResource" -Tag 'Get' { 'AdminSqlForBI' ) - { Get-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Get-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } } It 'Should call the mock function Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } } @@ -368,12 +368,12 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return false when desired server role exist' { InModuleScope -ScriptBlock { - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -391,12 +391,12 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return true when desired server role does not exist' { InModuleScope -ScriptBlock { - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -414,16 +414,16 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return true when desired server role exist' { InModuleScope -ScriptBlock { - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When the system is not in the desired state and ensure is set to Present' { + Context 'When the system is not in the desired state and ensure is set to Present, single role' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -437,16 +437,16 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return false when desired server role does not exist' { InModuleScope -ScriptBlock { - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When the system is not in the desired state and ensure is set to Present' { + Context 'When the system is not in the desired state and ensure is set to Present, multiple roles' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -461,12 +461,12 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return false when desired members are not in desired server role' { InModuleScope -ScriptBlock { - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -482,16 +482,16 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { $mockErrorMessage = $script:localizedData.MembersToIncludeAndExcludeParamMustBeNull - { Test-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } It 'Should not be executed' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } } - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToInclude is assigned a member that exist, parameter Members is not assigned a value, and ensure is set to Present' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -506,16 +506,16 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return true when desired server role exist' { InModuleScope -ScriptBlock { - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToInclude is assigned a member that does not exist, parameter Members is not assigned a value, and ensure is set to Present' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -530,12 +530,12 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return false when desired server role does not exist' { InModuleScope -ScriptBlock { - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -566,12 +566,12 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return false when desired server role does not exist' { InModuleScope -ScriptBlock { - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should be executed once' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -587,16 +587,16 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { $mockErrorMessage = $script:localizedData.MembersToIncludeAndExcludeParamMustBeNull - { Test-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } It 'Should not be executed' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } } - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToExclude is assigned a member that does not exist, parameter Members is not assigned a value, and ensure is set to Present' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -611,16 +611,16 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return true when desired server role does not exist' { InModuleScope -ScriptBlock { - $result | Should -BeTrue + $result | Should-BeTrue } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToExclude is assigned a member that exist, parameter Members is not assigned a value, and ensure is set to Present' { BeforeEach { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -635,12 +635,12 @@ Describe "DSC_SqlRole\Test-TargetResource" -Tag 'Test' { It 'Should return false when desired server role exist' { InModuleScope -ScriptBlock { - $result | Should -BeFalse + $result | Should-BeFalse } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -703,7 +703,7 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { } } - Context 'When the system is not in the desired state and ensure is set to Absent' { + Context 'When the system is not in the desired state and ensure is set to Absent for Set-TargetResource' { It 'Should not throw when calling the drop method' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -714,16 +714,16 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Absent' $mockTestParameters.ServerRoleName = $mockSqlServerRole - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } } It 'Should be executed once' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 1 } } - Context 'When the system is not in the desired state and ensure is set to Absent' { + Context 'When the system is not in the desired state and ensure is set to Absent and role is missing' { It 'Should throw the correct error when calling the drop method' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -737,14 +737,14 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockErrorMessage = $script:localizedData.DropServerRoleSetError ` -f 'localhost', 'MSSQLSERVER', 'AdminSqlForBI' - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When the system is not in the desired state and ensure is set to Present' { + Context 'When the system is not in the desired state and ensure is set to Present, single role' { It 'Should not throw when calling the create method' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 @@ -755,20 +755,20 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.ServerRoleName = $mockSqlServerRoleAdd - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call the mock function New-Object with TypeName equal to Microsoft.SqlServer.Management.Smo.ServerRole' { - Should -Invoke -CommandName New-Object -Exactly -Times 1 -ParameterFilter { + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' - } -Scope Context + } -Scope Context -Times 1 } } - Context 'When the system is not in the desired state and ensure is set to Present' { + Context 'When the system is not in the desired state and ensure is set to Present and role cannot be created' { BeforeAll { $mockInvalidOperationForCreateMethod = $true } @@ -786,16 +786,16 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockErrorMessage = $script:localizedData.CreateServerRoleSetError ` -f 'localhost', 'MSSQLSERVER', $mockSqlServerRoleAdd - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should call the mock function New-Object with TypeName equal to Microsoft.SqlServer.Management.Smo.ServerRole' { - Should -Invoke -CommandName New-Object -Exactly -Times 1 -ParameterFilter { + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.ServerRole' - } -Scope Context + } -Scope Context -Times 1 } } @@ -809,12 +809,12 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Members = @('CONTOSO\John', 'CONTOSO\Kelly') $mockTestParameters.MembersToInclude = 'CONTOSO\Lucy' - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage '*(DRC0010)*' + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage '*(DRC0010)*' } } It 'Should should not call Connect-SQL' { - Should -Invoke -CommandName Connect-SQL -Exactly -Times 0 -Scope Context + Should-Invoke -CommandName Connect-SQL -Exactly -Scope Context -Times 0 } } @@ -830,10 +830,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $errorMessage = $script:localizedData.MembersToIncludeAndExcludeParamMustBeNull - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage '*(DRC0010)*' + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage '*(DRC0010)*' } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } } @@ -850,14 +850,14 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToInclude = 'CONTOSO\Lucy' - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToInclude is assigned a member that cannot be added, parameter Members is not assigned a value, and ensure is set to Present' { BeforeAll { $mockInvalidOperationForAddMemberMethod = $true $mockExpectedMemberToAdd = 'CONTOSO\Lucy' @@ -874,14 +874,14 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockErrorMessage = $script:localizedData.AddMemberServerRoleSetError ` -f 'localhost', 'MSSQLSERVER', 'AdminSqlForBI', 'CONTOSO\Lucy' - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When parameter MembersToInclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToInclude is assigned a member that is missing login, parameter Members is not assigned a value, and ensure is set to Present' { BeforeAll { $mockExpectedMemberToAdd = 'CONTOSO\Lucy' } @@ -901,10 +901,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { 'KingJulian' ) - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -923,14 +923,14 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToExclude = 'CONTOSO\Kelly' - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToExclude is assigned a member that cannot be dropped, parameter Members is not assigned a value, and ensure is set to Present' { BeforeAll { $mockInvalidOperationForDropMemberMethod = $true $mockExpectedMemberToDrop = 'CONTOSO\Kelly' @@ -947,14 +947,14 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockErrorMessage = $script:localizedData.DropMemberServerRoleSetError ` -f 'localhost', 'MSSQLSERVER', 'AdminSqlForBI', 'CONTOSO\Kelly' - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } - Context 'When parameter MembersToExclude is assigned a value, parameter Members is not assigned a value, and ensure is set to Present' { + Context 'When parameter MembersToExclude is assigned a member without a login, parameter Members is not assigned a value, and ensure is set to Present' { BeforeAll { $mockEnumMemberNames = @('KingJulian', 'CONTOSO\John', 'CONTOSO\Kelly') $mockExpectedMemberToAdd = 'CONTOSO\Lucy' @@ -975,10 +975,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { 'KingJulian' ) - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1002,10 +1002,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { 'KingJulian' ) - { Set-TargetResource @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage + '*') + { Set-TargetResource @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage + '*') } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1023,10 +1023,10 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1044,10 +1044,10 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1064,10 +1064,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToInclude = @('TestChildRole') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1084,10 +1084,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.ServerRoleName = 'AdminSqlForBI' $mockTestParameters.MembersToExclude = @('TestChildRole') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockTestParameters }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -1104,10 +1104,10 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should not attempt to add an explicit member that already exists in the role' { @@ -1120,10 +1120,10 @@ Describe "DSC_SqlRole\Set-TargetResource" -Tag 'Set' { $mockTestParameters.Ensure = 'Present' $mockTestParameters.Members = @('CONTOSO\John'.ToUpper(), 'CONTOSO\Kelly') - { Set-TargetResource @mockTestParameters } | Should -Not -Throw - - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + $null = & ({ Set-TargetResource @mockTestParameters }) } + + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -1138,10 +1138,10 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should attempt to remove a member that is to be excluded' { @@ -1154,10 +1154,10 @@ 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 }) } - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -1195,7 +1195,7 @@ Describe 'DSC_SqlRole\Test-SqlSecurityPrincipal' -Tag 'Helper' { 'localhost\MSSQLSERVER' ) - { Test-SqlSecurityPrincipal @mockTestParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Test-SqlSecurityPrincipal @mockTestParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -1210,7 +1210,7 @@ Describe 'DSC_SqlRole\Test-SqlSecurityPrincipal' -Tag 'Helper' { SecurityPrincipal = 'CONTOSO\John' } - Test-SqlSecurityPrincipal @mockTestParameters | Should -BeTrue + Test-SqlSecurityPrincipal @mockTestParameters | Should-BeTrue } } @@ -1223,7 +1223,7 @@ Describe 'DSC_SqlRole\Test-SqlSecurityPrincipal' -Tag 'Helper' { SecurityPrincipal = 'CONTOSO\John'.ToUpper() } - Test-SqlSecurityPrincipal @mockTestParameters | Should -BeTrue + Test-SqlSecurityPrincipal @mockTestParameters | Should-BeTrue } } @@ -1236,7 +1236,7 @@ Describe 'DSC_SqlRole\Test-SqlSecurityPrincipal' -Tag 'Helper' { SecurityPrincipal = 'AdminSqlForBI' } - Test-SqlSecurityPrincipal @mockTestParameters | Should -BeTrue + Test-SqlSecurityPrincipal @mockTestParameters | Should-BeTrue } } @@ -1249,7 +1249,7 @@ Describe 'DSC_SqlRole\Test-SqlSecurityPrincipal' -Tag 'Helper' { SecurityPrincipal = 'AdminSqlForBI'.ToUpper() } - Test-SqlSecurityPrincipal @mockTestParameters | Should -BeTrue + Test-SqlSecurityPrincipal @mockTestParameters | Should-BeTrue } } } @@ -1275,13 +1275,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 2 elements' { InModuleScope -ScriptBlock { - $result.Members | Should -HaveCount 2 + $result.Members | Should-BeCollection -Count 2 } } It 'Should return the same elements' { InModuleScope -ScriptBlock { - $result.Members | Should -Be @( + $result.Members | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly' ) @@ -1290,8 +1290,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.MembersToInclude | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1316,13 +1316,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 3 elements' { InModuleScope -ScriptBlock { - $result.Members | Should -HaveCount 3 + $result.Members | Should-BeCollection -Count 3 } } It 'Should return the same elements' { InModuleScope -ScriptBlock { - $result.Members | Should -Be @( + $result.Members | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly', 'SA' @@ -1332,8 +1332,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.MembersToInclude | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1357,20 +1357,20 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 3 elements' { InModuleScope -ScriptBlock { - $result.Members | Should -HaveCount 3 + $result.Members | Should-BeCollection -Count 3 } } It 'Should have SA in Members' { InModuleScope -ScriptBlock { - $result.Members | Should -Contain 'SA' + $result.Members | Should-ContainCollection 'SA' } } It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.MembersToInclude | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1395,13 +1395,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 3 elements' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -HaveCount 3 + $result.MembersToInclude | Should-BeCollection -Count 3 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -Be @( + $result.MembersToInclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly', 'SA' @@ -1411,8 +1411,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1436,13 +1436,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 2 elements' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -HaveCount 2 + $result.MembersToInclude | Should-BeCollection -Count 2 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -Be @( + $result.MembersToInclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly' ) @@ -1451,8 +1451,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1476,13 +1476,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 2 elements' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -HaveCount 2 + $result.MembersToInclude | Should-BeCollection -Count 2 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -Be @( + $result.MembersToInclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly' ) @@ -1491,8 +1491,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1517,13 +1517,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 3 elements' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -HaveCount 3 + $result.MembersToInclude | Should-BeCollection -Count 3 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToInclude | Should -Be @( + $result.MembersToInclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly', 'SA' @@ -1533,8 +1533,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToExclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToExclude | Should-BeFalsy } } } @@ -1559,13 +1559,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 3 elements' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -HaveCount 3 + $result.MembersToExclude | Should-BeCollection -Count 3 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -Be @( + $result.MembersToExclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly', 'SA' @@ -1575,8 +1575,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToInclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToInclude | Should-BeFalsy } } } @@ -1600,13 +1600,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 2 elements' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -HaveCount 2 + $result.MembersToExclude | Should-BeCollection -Count 2 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -Be @( + $result.MembersToExclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly' ) @@ -1615,8 +1615,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToInclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToInclude | Should-BeFalsy } } } @@ -1640,13 +1640,13 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 2 elements' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -HaveCount 2 + $result.MembersToExclude | Should-BeCollection -Count 2 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -Be @( + $result.MembersToExclude | Should-Be @( 'CONTOSO\John', 'CONTOSO\Kelly' ) @@ -1655,8 +1655,8 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToInclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToInclude | Should-BeFalsy } } } @@ -1681,20 +1681,20 @@ Describe 'DSC_SqlRole\Get-CorrectedMemberParameters' -Tag 'Helper' { It 'Should return an array with 2 elements' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -HaveCount 2 + $result.MembersToExclude | Should-BeCollection -Count 2 } } It 'Should return the elements from Members' { InModuleScope -ScriptBlock { - $result.MembersToExclude | Should -Not -Contain 'SA' + $result.MembersToExclude | Should-NotContainCollection 'SA' } } It 'Should not return extra values' { InModuleScope -ScriptBlock { - $result.Members | Should -BeNullOrEmpty - $result.MembersToInclude | Should -BeNullOrEmpty + $result.Members | Should-BeFalsy + $result.MembersToInclude | Should-BeFalsy } } } diff --git a/tests/Unit/DSC_SqlScript.Tests.ps1 b/tests/Unit/DSC_SqlScript.Tests.ps1 index 27bdabf1f..5ae68959b 100644 --- a/tests/Unit/DSC_SqlScript.Tests.ps1 +++ b/tests/Unit/DSC_SqlScript.Tests.ps1 @@ -108,12 +108,12 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result | Should -BeOfType [System.Collections.Hashtable] - $result.Id | Should -Be $mockGetTargetResourceParameters.Id - $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance - $result.SetFilePath | Should -Be $mockGetTargetResourceParameters.SetFilePath - $result.GetFilePath | Should -Be $mockGetTargetResourceParameters.GetFilePath - $result.TestFilePath | Should -Be $mockGetTargetResourceParameters.TestFilePath + $result | Should-HaveType ([System.Collections.Hashtable]) + $result.Id | Should-Be $mockGetTargetResourceParameters.Id + $result.ServerInstance | Should-Be $mockGetTargetResourceParameters.ServerInstance + $result.SetFilePath | Should-Be $mockGetTargetResourceParameters.SetFilePath + $result.GetFilePath | Should-Be $mockGetTargetResourceParameters.GetFilePath + $result.TestFilePath | Should-Be $mockGetTargetResourceParameters.TestFilePath } } } @@ -133,12 +133,12 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result | Should -BeOfType [System.Collections.Hashtable] - $result.Id | Should -Be $mockGetTargetResourceParameters.Id - $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance - $result.SetFilePath | Should -Be $mockGetTargetResourceParameters.SetFilePath - $result.GetFilePath | Should -Be $mockGetTargetResourceParameters.GetFilePath - $result.TestFilePath | Should -Be $mockGetTargetResourceParameters.TestFilePath + $result | Should-HaveType ([System.Collections.Hashtable]) + $result.Id | Should-Be $mockGetTargetResourceParameters.Id + $result.ServerInstance | Should-Be $mockGetTargetResourceParameters.ServerInstance + $result.SetFilePath | Should-Be $mockGetTargetResourceParameters.SetFilePath + $result.GetFilePath | Should-Be $mockGetTargetResourceParameters.GetFilePath + $result.TestFilePath | Should-Be $mockGetTargetResourceParameters.TestFilePath } } } @@ -156,7 +156,7 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = 'Failed to run SQL Script' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -195,7 +195,7 @@ Describe 'SqlScript\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 'SqlScript\Set-TargetResource' -Tag 'Set' { $mockSetTargetResourceParameters.QueryTimeout = 30 - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } } @@ -232,7 +232,7 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = 'Failed to run SQL Script' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -272,7 +272,7 @@ Describe 'SqlScript\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -290,7 +290,7 @@ Describe 'SqlScript\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -312,7 +312,7 @@ Describe 'SqlScript\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -330,7 +330,7 @@ Describe 'SqlScript\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -348,7 +348,7 @@ Describe 'SqlScript\Test-TargetResource' { $mockErrorMessage = 'Failed to run SQL Script' - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 b/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 index 641608482..60289dc3b 100644 --- a/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 +++ b/tests/Unit/DSC_SqlScriptQuery.Tests.ps1 @@ -108,12 +108,12 @@ Describe 'SqlScriptQuery\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result | Should -BeOfType [System.Collections.Hashtable] - $result.Id | Should -Be $mockGetTargetResourceParameters.Id - $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance - $result.GetQuery | Should -Be $mockGetTargetResourceParameters.GetQuery - $result.SetQuery | Should -Be $mockGetTargetResourceParameters.SetQuery - $result.TestQuery | Should -Be $mockGetTargetResourceParameters.TestQuery + $result | Should-HaveType ([System.Collections.Hashtable]) + $result.Id | Should-Be $mockGetTargetResourceParameters.Id + $result.ServerInstance | Should-Be $mockGetTargetResourceParameters.ServerInstance + $result.GetQuery | Should-Be $mockGetTargetResourceParameters.GetQuery + $result.SetQuery | Should-Be $mockGetTargetResourceParameters.SetQuery + $result.TestQuery | Should-Be $mockGetTargetResourceParameters.TestQuery } } } @@ -133,12 +133,12 @@ Describe 'SqlScriptQuery\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result | Should -BeOfType [System.Collections.Hashtable] - $result.Id | Should -Be $mockGetTargetResourceParameters.Id - $result.ServerInstance | Should -Be $mockGetTargetResourceParameters.ServerInstance - $result.GetQuery | Should -Be $mockGetTargetResourceParameters.GetQuery - $result.SetQuery | Should -Be $mockGetTargetResourceParameters.SetQuery - $result.TestQuery | Should -Be $mockGetTargetResourceParameters.TestQuery + $result | Should-HaveType ([System.Collections.Hashtable]) + $result.Id | Should-Be $mockGetTargetResourceParameters.Id + $result.ServerInstance | Should-Be $mockGetTargetResourceParameters.ServerInstance + $result.GetQuery | Should-Be $mockGetTargetResourceParameters.GetQuery + $result.SetQuery | Should-Be $mockGetTargetResourceParameters.SetQuery + $result.TestQuery | Should-Be $mockGetTargetResourceParameters.TestQuery } } } @@ -156,7 +156,7 @@ Describe 'SqlScriptQuery\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = 'Failed to run SQL Script' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -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 }) } } } @@ -232,7 +232,7 @@ Describe 'SqlScriptQuery\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = 'Failed to run SQL Script' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -272,7 +272,7 @@ Describe 'SqlScriptQuery\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -290,7 +290,7 @@ Describe 'SqlScriptQuery\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -312,7 +312,7 @@ Describe 'SqlScriptQuery\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -330,7 +330,7 @@ Describe 'SqlScriptQuery\Test-TargetResource' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -348,7 +348,7 @@ Describe 'SqlScriptQuery\Test-TargetResource' { $mockErrorMessage = 'Failed to run SQL Script' - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 b/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 index 0e24ebbc3..9e6c6619d 100644 --- a/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 +++ b/tests/Unit/DSC_SqlSecureConnection.Tests.ps1 @@ -121,16 +121,16 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -BeExactly '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeTrue - $resultGetTargetResource.Ensure | Should -Be 'Present' - $resultGetTargetResource.ServerName | Should -Be 'MyHostName' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-BeString -CaseSensitive '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeTrue + $resultGetTargetResource.Ensure | Should-Be 'Present' + $resultGetTargetResource.ServerName | Should-Be 'MyHostName' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-CertificatePermission -Exactly -Times 1 -Scope It -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-CertificatePermission -Exactly -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } -Scope It -Times 1 } } } @@ -162,15 +162,15 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -Be 'Empty' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeFalse - $resultGetTargetResource.Ensure | Should -Be 'Absent' - $resultGetTargetResource.ServerName | Should -Be 'localhost' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-Be 'Empty' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeFalse + $resultGetTargetResource.Ensure | Should-Be 'Absent' + $resultGetTargetResource.ServerName | Should-Be 'localhost' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 } } } @@ -204,14 +204,14 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeFalse - $resultGetTargetResource.Ensure | Should -Be 'Absent' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeFalse + $resultGetTargetResource.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 } } @@ -235,14 +235,14 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -Not -Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeTrue - $resultGetTargetResource.Ensure | Should -Be 'Absent' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-NotBe '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeTrue + $resultGetTargetResource.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 } } @@ -266,14 +266,14 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeTrue - $resultGetTargetResource.Ensure | Should -Be 'Absent' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeTrue + $resultGetTargetResource.Ensure | Should-Be 'Absent' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 } } } @@ -301,14 +301,14 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -Be 'Empty' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeTrue - $resultGetTargetResource.Ensure | Should -Be 'Present' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-Be 'Empty' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeTrue + $resultGetTargetResource.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 } } @@ -328,14 +328,14 @@ Describe 'SqlSecureConnection\Get-TargetResource' -Tag 'Get' { $resultGetTargetResource = Get-TargetResource @mockGetTargetResourceParameters - $resultGetTargetResource.InstanceName | Should -Be 'INSTANCE' - $resultGetTargetResource.Thumbprint | Should -Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' - $resultGetTargetResource.ServiceAccount | Should -Be 'SqlSvc' - $resultGetTargetResource.ForceEncryption | Should -BeFalse - $resultGetTargetResource.Ensure | Should -Be 'Present' + $resultGetTargetResource.InstanceName | Should-Be 'INSTANCE' + $resultGetTargetResource.Thumbprint | Should-Be '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB' + $resultGetTargetResource.ServiceAccount | Should-Be 'SqlSvc' + $resultGetTargetResource.ForceEncryption | Should-BeFalse + $resultGetTargetResource.Ensure | Should-Be 'Present' } - Should -Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-EncryptedConnectionSetting -Exactly -Scope It -Times 1 } } } @@ -384,14 +384,14 @@ 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() } - Should -Invoke -CommandName Set-CertificatePermission -Exactly -Times 1 -Scope It -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } - Should -Invoke -CommandName Restart-SqlService -ParameterFilter { + Should-Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } -Scope It -Times 1 + Should-Invoke -CommandName Set-CertificatePermission -Exactly -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -ParameterFilter { $ServerName -eq 'localhost' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -411,12 +411,12 @@ 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() } - Should -Invoke -CommandName Set-CertificatePermission -Exactly -Times 1 -Scope It -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } -Scope It -Times 1 + Should-Invoke -CommandName Set-CertificatePermission -Exactly -ParameterFilter { $Thumbprint -ceq '2A11AB1AB1A11111A1111AB111111AB11ABCDEFB'.ToLower() } -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } } @@ -441,14 +441,14 @@ 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 - Should -Invoke -CommandName Set-CertificatePermission -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Restart-SqlService -ParameterFilter { + Should-Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-CertificatePermission -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Restart-SqlService -Exactly -ParameterFilter { $ServerName -eq 'MyHostName' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -473,12 +473,12 @@ 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 - Should -Invoke -CommandName Set-CertificatePermission -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Set-CertificatePermission -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -503,12 +503,12 @@ 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 - Should -Invoke -CommandName Set-CertificatePermission -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-CertificatePermission -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -535,12 +535,12 @@ 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 - Should -Invoke -CommandName Set-CertificatePermission -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Set-EncryptedConnectionSetting -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Set-CertificatePermission -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } } @@ -587,7 +587,7 @@ Describe 'SqlSecureConnection\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @mockTestTargetResourceParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -611,7 +611,7 @@ Describe 'SqlSecureConnection\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @mockTestTargetResourceParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -639,7 +639,7 @@ Describe 'SqlSecureConnection\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @mockTestTargetResourceParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -663,7 +663,7 @@ Describe 'SqlSecureConnection\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @mockTestTargetResourceParameters - $resultTestTargetResource | Should -BeFalse + $resultTestTargetResource | Should-BeFalse } } } @@ -692,7 +692,7 @@ Describe 'SqlSecureConnection\Test-TargetResource' -Tag 'Test' { $resultTestTargetResource = Test-TargetResource @mockTestTargetResourceParameters - $resultTestTargetResource | Should -BeTrue + $resultTestTargetResource | Should-BeTrue } } } @@ -763,9 +763,9 @@ Describe 'SqlSecureConnection\Get-EncryptedConnectionSetting' -Tag 'Helper' { $result = Get-EncryptedConnectionSetting -InstanceName 'NamedInstance' - $result.Certificate | Should -Be '12345678' - $result.ForceEncryption | Should -Be 1 - $result | Should -BeOfType [Hashtable] + $result.Certificate | Should-Be '12345678' + $result.ForceEncryption | Should-Be 1 + $result | Should-HaveType ([Hashtable]) } } } @@ -783,7 +783,7 @@ Describe 'SqlSecureConnection\Get-EncryptedConnectionSetting' -Tag 'Helper' { $result = Get-EncryptedConnectionSetting -InstanceName 'NamedInstance' - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy } } } @@ -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 }) } } } @@ -851,9 +851,9 @@ Describe 'SqlSecureConnection\Set-EncryptedConnectionSetting' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-EncryptedConnectionSetting -InstanceName 'NamedInstance' -Thumbprint '12345678' -ForceEncryption $true } | Should -Throw + { Set-EncryptedConnectionSetting -InstanceName 'NamedInstance' -Thumbprint '12345678' -ForceEncryption $true } | Should-Throw - Should -Invoke -CommandName 'Set-ItemProperty' -Times 0 + Should-Invoke -CommandName 'Set-ItemProperty' -Times 0 } } } @@ -907,7 +907,7 @@ Describe 'SqlSecureConnection\Test-CertificatePermission' -Tag 'Helper' { $result = Test-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -927,7 +927,7 @@ Describe 'SqlSecureConnection\Test-CertificatePermission' -Tag 'Helper' { $result = Test-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -947,7 +947,7 @@ Describe 'SqlSecureConnection\Test-CertificatePermission' -Tag 'Helper' { $result = Test-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -965,7 +965,7 @@ Describe 'SqlSecureConnection\Test-CertificatePermission' -Tag 'Helper' { $result = Test-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -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' }) } } } @@ -1036,7 +1036,7 @@ Describe 'SqlSecureConnection\Set-CertificatePermission' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Set-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' } | Should -Throw + { Set-CertificatePermission -Thumbprint '12345678' -ServiceAccount 'Everyone' } | Should-Throw } } } @@ -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' }) } } } @@ -1166,7 +1166,7 @@ Describe 'SqlSecureConnection\Get-SqlEncryptionValue' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { Get-SqlEncryptionValue -InstanceName 'INSTANCE' } | Should -Throw -ExpectedMessage 'SQL instance ''INSTANCE'' not found on SQL Server.' + { Get-SqlEncryptionValue -InstanceName 'INSTANCE' } | Should-Throw -ExceptionMessage 'SQL instance ''INSTANCE'' not found on SQL Server.' } } } diff --git a/tests/Unit/DSC_SqlServiceAccount.Tests.ps1 b/tests/Unit/DSC_SqlServiceAccount.Tests.ps1 index a2e2f7913..8a7cdaf81 100644 --- a/tests/Unit/DSC_SqlServiceAccount.Tests.ps1 +++ b/tests/Unit/DSC_SqlServiceAccount.Tests.ps1 @@ -110,14 +110,14 @@ Describe 'SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { $testServiceInformation = Get-TargetResource @defaultGetTargetResourceParameters # Validate the hashtable returned - $testServiceInformation.ServerName | Should -Be 'TestServer' - $testServiceInformation.InstanceName | Should -Be 'MSSQLSERVER' - $testServiceInformation.ServiceType | Should -Be 'DatabaseEngine' - $testServiceInformation.ServiceAccountName | Should -Be 'NT SERVICE\MSSQLSERVER' + $testServiceInformation.ServerName | Should-Be 'TestServer' + $testServiceInformation.InstanceName | Should-Be 'MSSQLSERVER' + $testServiceInformation.ServiceType | Should-Be 'DatabaseEngine' + $testServiceInformation.ServiceAccountName | Should-Be 'NT SERVICE\MSSQLSERVER' } # Ensure mocks were properly used - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } It 'Should throw the correct exception when an invalid ServiceType and InstanceName are specified' { @@ -133,11 +133,11 @@ Describe 'SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.ServiceNotFound -f 'SQLServerAgent', 'TestServer', 'MSSQLSERVER' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } # Ensure mocks were properly used - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } } @@ -175,14 +175,14 @@ Describe 'SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { $testServiceInformation = Get-TargetResource @mockGetTargetResourceParameters # Validate the hashtable returned - $testServiceInformation.ServerName | Should -Be 'TestServer' - $testServiceInformation.InstanceName | Should -Be 'TestInstance' - $testServiceInformation.ServiceType | Should -Be 'DatabaseEngine' - $testServiceInformation.ServiceAccountName | Should -Be 'CONTOSO\sql.service' + $testServiceInformation.ServerName | Should-Be 'TestServer' + $testServiceInformation.InstanceName | Should-Be 'TestInstance' + $testServiceInformation.ServiceType | Should-Be 'DatabaseEngine' + $testServiceInformation.ServiceAccountName | Should-Be 'CONTOSO\sql.service' } # Ensure mocks were properly used - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } It 'Should throw the correct exception when an invalid ServiceType and InstanceName are specified' { @@ -198,11 +198,11 @@ Describe 'SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.ServiceNotFound -f 'SQLServerAgent', 'TestServer', 'TestInstance' - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } # Ensure mocks were properly used - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } } @@ -231,11 +231,11 @@ Describe 'SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { $currentState = Get-TargetResource @mockGetTargetResourceParameters # Validate the service account - $currentState.ServiceAccountName | Should -Be 'TestServer\SqlService' + $currentState.ServiceAccountName | Should-Be 'TestServer\SqlService' } # Ensure mocks were properly used - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } } @@ -264,11 +264,11 @@ Describe 'SqlServerServiceAccount\Get-TargetResource' -Tag 'Get' { $currentState = Get-TargetResource @mockGetTargetResourceParameters # Validate the managed service account - $currentState.ServiceAccountName | Should -Be 'CONTOSO\sqlservice$' + $currentState.ServiceAccountName | Should-Be 'CONTOSO\sqlservice$' } # Ensure the mocks were properly used - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } } } @@ -298,11 +298,11 @@ Describe 'SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { ServiceAccount = (New-Object -TypeName System.Management.Automation.PSCredential 'CONTOSO\sql.service', (New-Object -TypeName System.Security.SecureString)) } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } # Ensure mocks are properly used - Should -Invoke -CommandName Get-TargetResource -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -329,11 +329,11 @@ Describe 'SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { ServiceAccount = (New-Object -TypeName System.Management.Automation.PSCredential 'NT SERVICE\MSSQLSERVER', (New-Object -TypeName System.Security.SecureString)) } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } # Ensure mocks are properly used - Should -Invoke -CommandName Get-TargetResource -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -362,11 +362,11 @@ Describe 'SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { ServiceAccount = (New-Object -TypeName System.Management.Automation.PSCredential 'NT SERVICE\MSSQLSERVER', (New-Object -TypeName System.Security.SecureString)) } - Test-TargetResource @testTargetResourceParameters | Should -BeTrue + Test-TargetResource @testTargetResourceParameters | Should-BeTrue } # Ensure mocks are properly used - Should -Invoke -CommandName Get-TargetResource -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } Context 'When the parameter Force is specified for default instance' { @@ -393,7 +393,7 @@ Describe 'SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { Force = $true } - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } } } @@ -422,11 +422,11 @@ Describe 'SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { ServiceAccount = (New-Object -TypeName System.Management.Automation.PSCredential 'CONTOSO\sql.service', (New-Object -TypeName System.Security.SecureString)) } - Test-TargetResource @testTargetResourceParameters | Should -BeTrue + Test-TargetResource @testTargetResourceParameters | Should-BeTrue } # Ensure mocks are properly used - Should -Invoke -CommandName Get-TargetResource -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } Context 'When the parameter Force is specified for named instance' { @@ -454,7 +454,7 @@ Describe 'SqlServerServiceAccount\Test-TargetResource' -Tag 'Test' { } # Validate the return value - Test-TargetResource @testTargetResourceParameters | Should -BeFalse + Test-TargetResource @testTargetResourceParameters | Should-BeFalse } } } @@ -543,14 +543,14 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { Set-TargetResource @setTargetResourceParameters # Validate that the correct information was passed through and updated - $testServiceAccountUpdated.Processed | Should -BeTrue - $testServiceAccountUpdated.NewUserAccount | Should -Be $setTargetResourceParameters.ServiceAccount.Username - $testServiceAccountUpdated.NewPassword | Should -Be $setTargetResourceParameters.ServiceAccount.GetNetworkCredential().Password + $testServiceAccountUpdated.Processed | Should-BeTrue + $testServiceAccountUpdated.NewUserAccount | Should-Be $setTargetResourceParameters.ServiceAccount.Username + $testServiceAccountUpdated.NewPassword | Should-Be $setTargetResourceParameters.ServiceAccount.GetNetworkCredential().Password } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-SqlService -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } It 'Should throw the correct exception when an invalid service name and type is provided' { @@ -564,12 +564,12 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { $mockCorrectErrorMessage = $script:localizedData.ServiceNotFound -f $setTargetResourceParameters.ServiceType, $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName # Attempt to update the service account - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockCorrectErrorMessage) + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockCorrectErrorMessage) } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-SqlService -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } It 'Should restart the service if requested' { @@ -585,8 +585,8 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-SqlService -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -659,14 +659,14 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { Set-TargetResource @setTargetResourceParameters # Validate that the correct information was passed through and updated - $testServiceAccountUpdated.Processed | Should -BeTrue - $testServiceAccountUpdated.NewUserAccount | Should -Be $setTargetResourceParameters.ServiceAccount.Username - $testServiceAccountUpdated.NewPassword | Should -Be $setTargetResourceParameters.ServiceAccount.GetNetworkCredential().Password + $testServiceAccountUpdated.Processed | Should-BeTrue + $testServiceAccountUpdated.NewUserAccount | Should-Be $setTargetResourceParameters.ServiceAccount.Username + $testServiceAccountUpdated.NewPassword | Should-Be $setTargetResourceParameters.ServiceAccount.GetNetworkCredential().Password } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-SqlService -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } It 'Should throw the correct exception when an invalid service name and type is provided' { @@ -680,12 +680,12 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { $mockCorrectErrorMessage = $script:localizedData.ServiceNotFound -f $setTargetResourceParameters.ServiceType, $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName # Attempt to update the service account - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockCorrectErrorMessage) + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockCorrectErrorMessage) } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-SqlService -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 0 } It 'Should restart the service if requested' { @@ -701,8 +701,8 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-SqlService -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } @@ -729,11 +729,11 @@ Describe 'SqlServerServiceAccount\Set-TargetResource' -Tag 'Set' { $mockCorrectErrorMessage = $script:localizedData.SetServiceAccountFailed -f $setTargetResourceParameters.ServerName, $setTargetResourceParameters.InstanceName, '' # Attempt to update the service account - { Set-TargetResource @setTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockCorrectErrorMessage + '*Mock SetServiceAccount*') + { Set-TargetResource @setTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockCorrectErrorMessage + '*Mock SetServiceAccount*') } # Ensure mocks are used properly - Should -Invoke -CommandName Get-ServiceObject -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-ServiceObject -Exactly -Scope It -Times 1 } } } @@ -791,8 +791,8 @@ Describe 'SqlServerServiceAccount\ConvertTo-ManagedServiceType' -Tag 'Helper' { # Get the ManagedServiceType $managedServiceType = ConvertTo-ManagedServiceType -ServiceType $MockServiceType - $managedServiceType | Should -BeOfType Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType - $managedServiceType | Should -Be $MockExpectedType + $managedServiceType | Should-HaveType ([Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType]) + $managedServiceType | Should-Be $MockExpectedType } } } @@ -856,8 +856,8 @@ Describe 'SqlServerServiceAccount\ConvertTo-ResourceServiceType' -Tag 'Helper' { # Get the ManagedServiceType $managedServiceType = ConvertTo-ResourceServiceType -ServiceType $MockServiceType - $managedServiceType | Should -BeOfType [System.String] - $managedServiceType | Should -Be $MockExpectedType + $managedServiceType | Should-HaveType ([System.String]) + $managedServiceType | Should-Be $MockExpectedType } } } @@ -1017,14 +1017,14 @@ Describe 'SqlServerServiceAccount\Get-SqlServiceName' -Tag 'Helper' { Set-StrictMode -Version 1.0 # Get the service name - Get-SqlServiceName -InstanceName 'MSSQLSERVER' -ServiceType $MockServiceType | Should -Be $MockExpectedServiceName + Get-SqlServiceName -InstanceName 'MSSQLSERVER' -ServiceType $MockServiceType | Should-Be $MockExpectedServiceName } # Ensure the mock is utilized - Should -Invoke -CommandName Get-ChildItem -ParameterFilter { + Should-Invoke -CommandName Get-ChildItem -Exactly -ParameterFilter { # Registry key used to index service type mappings $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Services' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 } } @@ -1099,14 +1099,14 @@ Describe 'SqlServerServiceAccount\Get-SqlServiceName' -Tag 'Helper' { Set-StrictMode -Version 1.0 # Get the service name - Get-SqlServiceName -InstanceName 'TestInstance' -ServiceType $MockServiceType | Should -Be $MockExpectedServiceName + Get-SqlServiceName -InstanceName 'TestInstance' -ServiceType $MockServiceType | Should-Be $MockExpectedServiceName } # Ensure the mock is utilized - Should -Invoke -CommandName Get-ChildItem -ParameterFilter { + Should-Invoke -CommandName Get-ChildItem -Exactly -ParameterFilter { # Registry key used to index service type mappings $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Services' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 } It 'Should throw an error for which is not instance-aware' -ForEach $notInstanceAwareTestCases { @@ -1117,7 +1117,7 @@ Describe 'SqlServerServiceAccount\Get-SqlServiceName' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.NotInstanceAware -f $MockServiceType # An exception should be raised - { Get-SqlServiceName -InstanceName 'TestInstance' -ServiceType $MockServiceType } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-SqlServiceName -InstanceName 'TestInstance' -ServiceType $MockServiceType } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -1138,11 +1138,11 @@ Describe 'SqlServerServiceAccount\Get-SqlServiceName' -Tag 'Helper' { $mockErrorMessage = '{0} (Parameter ''ServiceType'')' -f ($script:localizedData.UnknownServiceType -f 'DatabaseEngine') - { Get-SqlServiceName -InstanceName 'TestInstance' -ServiceType DatabaseEngine } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-SqlServiceName -InstanceName 'TestInstance' -ServiceType DatabaseEngine } | Should-Throw -ExceptionMessage $mockErrorMessage } # Ensure the mock was called - Should -Invoke -CommandName Get-ChildItem -Times 1 -Exactly -Scope It + Should-Invoke -CommandName Get-ChildItem -Exactly -Scope It -Times 1 } } } @@ -1191,12 +1191,12 @@ Describe 'SqlServerServiceAccount\Get-ServiceObject' -Tag 'Helper' { $serviceObject = Get-ServiceObject @mockGetServiceObjectParameters - $serviceObject.Type | Should -Be 'SqlServer' + $serviceObject.Type | Should-Be 'SqlServer' } # Ensure mocks are properly used - Should -Invoke -CommandName Import-SqlDscPreferredModule -Scope It -Exactly -Times 1 - Should -Invoke -CommandName New-Object -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 } } @@ -1237,12 +1237,12 @@ Describe 'SqlServerServiceAccount\Get-ServiceObject' -Tag 'Helper' { $serviceObject = Get-ServiceObject @mockGetServiceObjectParameters - $serviceObject.Type | Should -Be 'SqlServer' + $serviceObject.Type | Should-Be 'SqlServer' } # Ensure mocks are properly used - Should -Invoke -CommandName Import-SqlDscPreferredModule -Scope It -Exactly -Times 1 - Should -Invoke -CommandName New-Object -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 } } @@ -1292,7 +1292,7 @@ Describe 'SqlServerServiceAccount\Get-ServiceObject' -Tag 'Helper' { $testErrorMessage = '{0} (Parameter ''VersionNumber'')' -f ($script:localizedData.MissingParameter -f 'IntegrationServices') - { Get-ServiceObject @mockGetServiceObjectParameters } | Should -Throw $testErrorMessage + { Get-ServiceObject @mockGetServiceObjectParameters } | Should-Throw $testErrorMessage } } @@ -1307,10 +1307,10 @@ Describe 'SqlServerServiceAccount\Get-ServiceObject' -Tag 'Helper' { $mockGetServiceObject = Get-ServiceObject @mockGetServiceObjectParameters - $mockGetServiceObject | Should -HaveCount 1 - $mockGetServiceObject.Type | Should -Be 'IntegrationServices' - $mockGetServiceObject.ServiceAccount | Should -Be 'NT SERVICE\MSSQLSERVER' - $mockGetServiceObject.Name | Should -Be 'MsDtsServer130' + $mockGetServiceObject | Should-BeCollection -Count 1 + $mockGetServiceObject.Type | Should-Be 'IntegrationServices' + $mockGetServiceObject.ServiceAccount | Should-Be 'NT SERVICE\MSSQLSERVER' + $mockGetServiceObject.Name | Should-Be 'MsDtsServer130' } } } diff --git a/tests/Unit/DSC_SqlSetup.Tests.ps1 b/tests/Unit/DSC_SqlSetup.Tests.ps1 index 272ba8e41..6a36a24c8 100644 --- a/tests/Unit/DSC_SqlSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlSetup.Tests.ps1 @@ -302,7 +302,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { SqlVersion = '14.0' } - { Get-TargetResource @mockGetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-TargetResource @mockGetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -350,17 +350,17 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 0 - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should not return any names of installed features' { @@ -369,7 +369,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be '' + $result.Features | Should-Be '' } } @@ -379,34 +379,34 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $TestDrive - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.InstanceID | Should -BeNullOrEmpty - $result.InstallSharedDir | Should -BeNullOrEmpty - $result.InstallSharedWOWDir | Should -BeNullOrEmpty - $result.SQLSvcAccountUsername | Should -BeNullOrEmpty - $result.AgtSvcAccountUsername | Should -BeNullOrEmpty - $result.SqlCollation | Should -BeNullOrEmpty - $result.SQLSysAdminAccounts | Should -BeNullOrEmpty - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -BeNullOrEmpty - $result.SQLUserDBDir | Should -BeNullOrEmpty - $result.SQLUserDBLogDir | Should -BeNullOrEmpty - $result.SQLBackupDir | Should -BeNullOrEmpty - $result.FTSvcAccountUsername | Should -BeNullOrEmpty - $result.RSSvcAccountUsername | Should -BeNullOrEmpty - $result.ASSvcAccountUsername | Should -BeNullOrEmpty - $result.ASCollation | Should -BeNullOrEmpty - $result.ProductCoveredBySA | Should -BeFalse - $result.ASSysAdminAccounts | Should -BeNullOrEmpty - $result.ASDataDir | Should -BeNullOrEmpty - $result.ASLogDir | Should -BeNullOrEmpty - $result.ASBackupDir | Should -BeNullOrEmpty - $result.ASTempDir | Should -BeNullOrEmpty - $result.ASConfigDir | Should -BeNullOrEmpty - $result.ASServerMode | Should -BeNullOrEmpty - $result.ISSvcAccountUsername | Should -BeNullOrEmpty - $result.ServerName | Should -Be 'host.company.local' + $result.SourcePath | Should-Be $TestDrive + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.InstanceID | Should-BeFalsy + $result.InstallSharedDir | Should-BeFalsy + $result.InstallSharedWOWDir | Should-BeFalsy + $result.SQLSvcAccountUsername | Should-BeFalsy + $result.AgtSvcAccountUsername | Should-BeFalsy + $result.SqlCollation | Should-BeFalsy + $result.SQLSysAdminAccounts | Should-BeFalsy + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-BeFalsy + $result.SQLUserDBDir | Should-BeFalsy + $result.SQLUserDBLogDir | Should-BeFalsy + $result.SQLBackupDir | Should-BeFalsy + $result.FTSvcAccountUsername | Should-BeFalsy + $result.RSSvcAccountUsername | Should-BeFalsy + $result.ASSvcAccountUsername | Should-BeFalsy + $result.ASCollation | Should-BeFalsy + $result.ProductCoveredBySA | Should-BeFalse + $result.ASSysAdminAccounts | Should-BeFalsy + $result.ASDataDir | Should-BeFalsy + $result.ASLogDir | Should-BeFalsy + $result.ASBackupDir | Should-BeFalsy + $result.ASTempDir | Should-BeFalsy + $result.ASConfigDir | Should-BeFalsy + $result.ASServerMode | Should-BeFalsy + $result.ISSvcAccountUsername | Should-BeFalsy + $result.ServerName | Should-Be 'host.company.local' } } } @@ -513,17 +513,17 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should return correct names of installed features' { @@ -532,7 +532,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'SQLENGINE,REPLICATION,DQ,FULLTEXT,RS,AS,IS,DQC,BOL,CONN,BC,SDK,MDS' + $result.Features | Should-Be 'SQLENGINE,REPLICATION,DQ,FULLTEXT,RS,AS,IS,DQC,BOL,CONN,BC,SDK,MDS' } } @@ -542,38 +542,38 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $TestDrive - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.InstanceID | Should -Be 'MSSQLSERVER' - $result.InstallSharedDir | Should -Be 'C:\Program Files\Microsoft SQL Server' - $result.InstallSharedWOWDir | Should -Be 'C:\Program Files (x86)\Microsoft SQL Server' - $result.SQLSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.AgtSvcAccountUsername | Should -Be 'COMPANY\AgentAccount' - $result.SqlCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.SQLSysAdminAccounts | Should -Be 'COMPANY\Stacy' - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL" - $result.SQLUserDBDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" - $result.SQLUserDBLogDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" - $result.SQLBackupDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\Backup" - $result.FTSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.RSSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.ASSysAdminAccounts | Should -Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') - $result.ASDataDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' - $result.ASLogDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' - $result.ASBackupDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' - $result.ASTempDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' - $result.ASConfigDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' - $result.ASServerMode | Should -Be 'MULTIDIMENSIONAL' - $result.ISSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.SQLTempDBDir | Should -Be 'M:\MSSQL\TempDb\Data' - $result.SqlTempdbFileCount | Should -Be 1 - $result.SqlTempdbFileSize | Should -Be 200 - $result.SqlTempdbFileGrowth | Should -Be 10 - $result.SqlTempdbLogFileSize | Should -Be 20 - $result.SqlTempdbLogFileGrowth | Should -Be 10 + $result.SourcePath | Should-Be $TestDrive + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.InstanceID | Should-Be 'MSSQLSERVER' + $result.InstallSharedDir | Should-Be 'C:\Program Files\Microsoft SQL Server' + $result.InstallSharedWOWDir | Should-Be 'C:\Program Files (x86)\Microsoft SQL Server' + $result.SQLSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.AgtSvcAccountUsername | Should-Be 'COMPANY\AgentAccount' + $result.SqlCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.SQLSysAdminAccounts | Should-Be 'COMPANY\Stacy' + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL" + $result.SQLUserDBDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" + $result.SQLUserDBLogDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" + $result.SQLBackupDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\Backup" + $result.FTSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.RSSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.ASSysAdminAccounts | Should-Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') + $result.ASDataDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' + $result.ASLogDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' + $result.ASBackupDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' + $result.ASTempDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' + $result.ASConfigDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' + $result.ASServerMode | Should-Be 'MULTIDIMENSIONAL' + $result.ISSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.SQLTempDBDir | Should-Be 'M:\MSSQL\TempDb\Data' + $result.SqlTempdbFileCount | Should-Be 1 + $result.SqlTempdbFileSize | Should-Be 200 + $result.SqlTempdbFileGrowth | Should-Be 10 + $result.SqlTempdbLogFileSize | Should-Be 20 + $result.SqlTempdbLogFileGrowth | Should-Be 10 } } @@ -585,7 +585,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ASServerMode | Should -Be 'POWERPIVOT' + $result.ASServerMode | Should-Be 'POWERPIVOT' } } @@ -597,7 +597,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ASServerMode | Should -Be 'TABULAR' + $result.ASServerMode | Should-Be 'TABULAR' } # Return the state to the default for all other tests. @@ -616,8 +616,8 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - Write-Output -InputObject $result.ASSysAdminAccounts -NoEnumerate | Should -BeOfType [System.String[]] - $result.ASSysAdminAccounts | Should -Be 'COMPANY\AnalysisAdmin' + Write-Output -InputObject $result.ASSysAdminAccounts -NoEnumerate | Should-HaveType ([System.String[]]) + $result.ASSysAdminAccounts | Should-Be 'COMPANY\AnalysisAdmin' } # Setting back the default administrators for mock Connect-SQLAnalysis. @@ -676,16 +676,16 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should not return any names of installed features' { @@ -694,7 +694,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be '' + $result.Features | Should-Be '' } } @@ -704,32 +704,32 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $mockSourcePathUNC - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.InstanceID | Should -BeNullOrEmpty - $result.InstallSharedDir | Should -BeNullOrEmpty - $result.InstallSharedWOWDir | Should -BeNullOrEmpty - $result.SQLSvcAccountUsername | Should -BeNullOrEmpty - $result.AgtSvcAccountUsername | Should -BeNullOrEmpty - $result.SqlCollation | Should -BeNullOrEmpty - $result.SQLSysAdminAccounts | Should -BeNullOrEmpty - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -BeNullOrEmpty - $result.SQLUserDBDir | Should -BeNullOrEmpty - $result.SQLUserDBLogDir | Should -BeNullOrEmpty - $result.SQLBackupDir | Should -BeNullOrEmpty - $result.FTSvcAccountUsername | Should -BeNullOrEmpty - $result.RSSvcAccountUsername | Should -BeNullOrEmpty - $result.ASSvcAccountUsername | Should -BeNullOrEmpty - $result.ASCollation | Should -BeNullOrEmpty - $result.ASSysAdminAccounts | Should -BeNullOrEmpty - $result.ASDataDir | Should -BeNullOrEmpty - $result.ASLogDir | Should -BeNullOrEmpty - $result.ASBackupDir | Should -BeNullOrEmpty - $result.ASTempDir | Should -BeNullOrEmpty - $result.ASConfigDir | Should -BeNullOrEmpty - $result.ISSvcAccountUsername | Should -BeNullOrEmpty - $result.SqlVersion | Should -Be $MockSqlMajorVersion + $result.SourcePath | Should-Be $mockSourcePathUNC + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.InstanceID | Should-BeFalsy + $result.InstallSharedDir | Should-BeFalsy + $result.InstallSharedWOWDir | Should-BeFalsy + $result.SQLSvcAccountUsername | Should-BeFalsy + $result.AgtSvcAccountUsername | Should-BeFalsy + $result.SqlCollation | Should-BeFalsy + $result.SQLSysAdminAccounts | Should-BeFalsy + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-BeFalsy + $result.SQLUserDBDir | Should-BeFalsy + $result.SQLUserDBLogDir | Should-BeFalsy + $result.SQLBackupDir | Should-BeFalsy + $result.FTSvcAccountUsername | Should-BeFalsy + $result.RSSvcAccountUsername | Should-BeFalsy + $result.ASSvcAccountUsername | Should-BeFalsy + $result.ASCollation | Should-BeFalsy + $result.ASSysAdminAccounts | Should-BeFalsy + $result.ASDataDir | Should-BeFalsy + $result.ASLogDir | Should-BeFalsy + $result.ASBackupDir | Should-BeFalsy + $result.ASTempDir | Should-BeFalsy + $result.ASConfigDir | Should-BeFalsy + $result.ISSvcAccountUsername | Should-BeFalsy + $result.SqlVersion | Should-Be $MockSqlMajorVersion } } } @@ -821,43 +821,43 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { if ($MockSqlMajorVersion -in ('13', '14', '15')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' } elseif ($MockSqlMajorVersion -in ('16')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' } else { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'SSMS\b' - $result.Features | Should -Match 'ADV_SSMS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'SSMS\b' + $result.Features | Should-MatchString 'ADV_SSMS\b' } } } @@ -953,17 +953,17 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should return correct names of installed features' { @@ -974,49 +974,49 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { if ($MockSqlMajorVersion -in ('13', '14', '15')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'CONN\b' - $result.Features | Should -Match 'BC\b' - $result.Features | Should -Match 'SDK\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'CONN\b' + $result.Features | Should-MatchString 'BC\b' + $result.Features | Should-MatchString 'SDK\b' } elseif ($MockSqlMajorVersion -in ('16')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' } else { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'CONN\b' - $result.Features | Should -Match 'BC\b' - $result.Features | Should -Match 'SDK\b' - $result.Features | Should -Match 'SSMS\b' - $result.Features | Should -Match 'ADV_SSMS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'CONN\b' + $result.Features | Should-MatchString 'BC\b' + $result.Features | Should-MatchString 'SDK\b' + $result.Features | Should-MatchString 'SSMS\b' + $result.Features | Should-MatchString 'ADV_SSMS\b' } } } @@ -1027,32 +1027,32 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $TestDrive - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.InstanceID | Should -Be 'MSSQLSERVER' - $result.InstallSharedDir | Should -Be 'C:\Program Files\Microsoft SQL Server' - $result.InstallSharedWOWDir | Should -Be 'C:\Program Files (x86)\Microsoft SQL Server' - $result.SQLSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.AgtSvcAccountUsername | Should -Be 'COMPANY\AgentAccount' - $result.SqlCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.SQLSysAdminAccounts | Should -Be 'COMPANY\Stacy' - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL" - $result.SQLUserDBDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" - $result.SQLUserDBLogDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" - $result.SQLBackupDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\Backup" - $result.FTSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.RSSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.ASSysAdminAccounts | Should -Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') - $result.ASDataDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' - $result.ASLogDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' - $result.ASBackupDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' - $result.ASTempDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' - $result.ASConfigDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' - $result.ASServerMode | Should -Be 'MULTIDIMENSIONAL' - $result.ISSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' + $result.SourcePath | Should-Be $TestDrive + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.InstanceID | Should-Be 'MSSQLSERVER' + $result.InstallSharedDir | Should-Be 'C:\Program Files\Microsoft SQL Server' + $result.InstallSharedWOWDir | Should-Be 'C:\Program Files (x86)\Microsoft SQL Server' + $result.SQLSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.AgtSvcAccountUsername | Should-Be 'COMPANY\AgentAccount' + $result.SqlCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.SQLSysAdminAccounts | Should-Be 'COMPANY\Stacy' + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL" + $result.SQLUserDBDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" + $result.SQLUserDBLogDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" + $result.SQLBackupDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\Backup" + $result.FTSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.RSSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.ASSysAdminAccounts | Should-Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') + $result.ASDataDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' + $result.ASLogDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' + $result.ASBackupDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' + $result.ASTempDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' + $result.ASConfigDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' + $result.ASServerMode | Should-Be 'MULTIDIMENSIONAL' + $result.ISSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' } } @@ -1064,7 +1064,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ASServerMode | Should -Be 'POWERPIVOT' + $result.ASServerMode | Should-Be 'POWERPIVOT' } } @@ -1076,7 +1076,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ASServerMode | Should -Be 'TABULAR' + $result.ASServerMode | Should-Be 'TABULAR' } # Return the state to the default for all other tests. @@ -1096,8 +1096,8 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - Write-Output -NoEnumerate $result.ASSysAdminAccounts | Should -BeOfType [System.String[]] - $result.ASSysAdminAccounts | Should -Be 'COMPANY\AnalysisAdmin' + Write-Output -NoEnumerate $result.ASSysAdminAccounts | Should-HaveType ([System.String[]]) + $result.ASSysAdminAccounts | Should-Be 'COMPANY\AnalysisAdmin' } # Setting back the default administrators for mock Connect-SQLAnalysis. @@ -1198,17 +1198,17 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should return correct names of installed features' { @@ -1219,49 +1219,49 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { if ($MockSqlMajorVersion -in ('13', '14', '15')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'CONN\b' - $result.Features | Should -Match 'BC\b' - $result.Features | Should -Match 'SDK\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'CONN\b' + $result.Features | Should-MatchString 'BC\b' + $result.Features | Should-MatchString 'SDK\b' } elseif ($MockSqlMajorVersion -in ('16')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' } else { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'CONN\b' - $result.Features | Should -Match 'BC\b' - $result.Features | Should -Match 'SDK\b' - $result.Features | Should -Match 'SSMS\b' - $result.Features | Should -Match 'ADV_SSMS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'CONN\b' + $result.Features | Should-MatchString 'BC\b' + $result.Features | Should-MatchString 'SDK\b' + $result.Features | Should-MatchString 'SSMS\b' + $result.Features | Should-MatchString 'ADV_SSMS\b' } } } @@ -1272,31 +1272,31 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $mockSourcePathUNC - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.InstanceID | Should -Be 'MSSQLSERVER' - $result.InstallSharedDir | Should -Be 'C:\Program Files\Microsoft SQL Server' - $result.InstallSharedWOWDir | Should -Be 'C:\Program Files (x86)\Microsoft SQL Server' - $result.SQLSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.AgtSvcAccountUsername | Should -Be 'COMPANY\AgentAccount' - $result.SqlCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.SQLSysAdminAccounts | Should -Be 'COMPANY\Stacy' - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL" - $result.SQLUserDBDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" - $result.SQLUserDBLogDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" - $result.SQLBackupDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\Backup" - $result.FTSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.RSSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.ASSysAdminAccounts | Should -Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') - $result.ASDataDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' - $result.ASLogDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' - $result.ASBackupDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' - $result.ASTempDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' - $result.ASConfigDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' - $result.ISSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' + $result.SourcePath | Should-Be $mockSourcePathUNC + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.InstanceID | Should-Be 'MSSQLSERVER' + $result.InstallSharedDir | Should-Be 'C:\Program Files\Microsoft SQL Server' + $result.InstallSharedWOWDir | Should-Be 'C:\Program Files (x86)\Microsoft SQL Server' + $result.SQLSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.AgtSvcAccountUsername | Should-Be 'COMPANY\AgentAccount' + $result.SqlCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.SQLSysAdminAccounts | Should-Be 'COMPANY\Stacy' + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL" + $result.SQLUserDBDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" + $result.SQLUserDBLogDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\DATA\" + $result.SQLBackupDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).MSSQLSERVER\MSSQL\Backup" + $result.FTSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.RSSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.ASSysAdminAccounts | Should-Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') + $result.ASDataDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' + $result.ASLogDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' + $result.ASBackupDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' + $result.ASTempDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' + $result.ASConfigDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' + $result.ISSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' } } } @@ -1339,14 +1339,14 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should not return any names of installed features' { @@ -1355,7 +1355,7 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be '' + $result.Features | Should-Be '' } } @@ -1365,31 +1365,31 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $TestDrive - $result.InstanceName | Should -Be 'TEST' - $result.InstanceID | Should -BeNullOrEmpty - $result.InstallSharedDir | Should -BeNullOrEmpty - $result.InstallSharedWOWDir | Should -BeNullOrEmpty - $result.SQLSvcAccountUsername | Should -BeNullOrEmpty - $result.AgtSvcAccountUsername | Should -BeNullOrEmpty - $result.SqlCollation | Should -BeNullOrEmpty - $result.SQLSysAdminAccounts | Should -BeNullOrEmpty - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -BeNullOrEmpty - $result.SQLUserDBDir | Should -BeNullOrEmpty - $result.SQLUserDBLogDir | Should -BeNullOrEmpty - $result.SQLBackupDir | Should -BeNullOrEmpty - $result.FTSvcAccountUsername | Should -BeNullOrEmpty - $result.RSSvcAccountUsername | Should -BeNullOrEmpty - $result.ASSvcAccountUsername | Should -BeNullOrEmpty - $result.ASCollation | Should -BeNullOrEmpty - $result.ASSysAdminAccounts | Should -BeNullOrEmpty - $result.ASDataDir | Should -BeNullOrEmpty - $result.ASLogDir | Should -BeNullOrEmpty - $result.ASBackupDir | Should -BeNullOrEmpty - $result.ASTempDir | Should -BeNullOrEmpty - $result.ASConfigDir | Should -BeNullOrEmpty - $result.ISSvcAccountUsername | Should -BeNullOrEmpty + $result.SourcePath | Should-Be $TestDrive + $result.InstanceName | Should-Be 'TEST' + $result.InstanceID | Should-BeFalsy + $result.InstallSharedDir | Should-BeFalsy + $result.InstallSharedWOWDir | Should-BeFalsy + $result.SQLSvcAccountUsername | Should-BeFalsy + $result.AgtSvcAccountUsername | Should-BeFalsy + $result.SqlCollation | Should-BeFalsy + $result.SQLSysAdminAccounts | Should-BeFalsy + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-BeFalsy + $result.SQLUserDBDir | Should-BeFalsy + $result.SQLUserDBLogDir | Should-BeFalsy + $result.SQLBackupDir | Should-BeFalsy + $result.FTSvcAccountUsername | Should-BeFalsy + $result.RSSvcAccountUsername | Should-BeFalsy + $result.ASSvcAccountUsername | Should-BeFalsy + $result.ASCollation | Should-BeFalsy + $result.ASSysAdminAccounts | Should-BeFalsy + $result.ASDataDir | Should-BeFalsy + $result.ASLogDir | Should-BeFalsy + $result.ASBackupDir | Should-BeFalsy + $result.ASTempDir | Should-BeFalsy + $result.ASConfigDir | Should-BeFalsy + $result.ISSvcAccountUsername | Should-BeFalsy } } } @@ -1521,15 +1521,15 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } - Should -Invoke -CommandName Get-PSDrive -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Service -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-InstanceProgramPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsInstalled -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsReplicationFeatureInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-InstanceProgramPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsInstalled -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-IsSsmsAdvancedInstalled -Exactly -Scope It -Times 1 } It 'Should return correct names of installed features' { @@ -1540,49 +1540,49 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { if ($MockSqlMajorVersion -in ('13', '14', '15')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'CONN\b' - $result.Features | Should -Match 'BC\b' - $result.Features | Should -Match 'SDK\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'CONN\b' + $result.Features | Should-MatchString 'BC\b' + $result.Features | Should-MatchString 'SDK\b' } elseif ($MockSqlMajorVersion -in ('16')) { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' } else { - $result.Features | Should -Match 'SQLENGINE\b' - $result.Features | Should -Match 'REPLICATION\b' - $result.Features | Should -Match 'DQ\b' - $result.Features | Should -Match 'DQC\b' - $result.Features | Should -Match 'FULLTEXT\b' - $result.Features | Should -Match 'RS\b' - $result.Features | Should -Match 'AS\b' - $result.Features | Should -Match 'IS\b' - $result.Features | Should -Match 'BOL\b' - $result.Features | Should -Match 'MDS\b' - $result.Features | Should -Match 'CONN\b' - $result.Features | Should -Match 'BC\b' - $result.Features | Should -Match 'SDK\b' - $result.Features | Should -Match 'SSMS\b' - $result.Features | Should -Match 'ADV_SSMS\b' + $result.Features | Should-MatchString 'SQLENGINE\b' + $result.Features | Should-MatchString 'REPLICATION\b' + $result.Features | Should-MatchString 'DQ\b' + $result.Features | Should-MatchString 'DQC\b' + $result.Features | Should-MatchString 'FULLTEXT\b' + $result.Features | Should-MatchString 'RS\b' + $result.Features | Should-MatchString 'AS\b' + $result.Features | Should-MatchString 'IS\b' + $result.Features | Should-MatchString 'BOL\b' + $result.Features | Should-MatchString 'MDS\b' + $result.Features | Should-MatchString 'CONN\b' + $result.Features | Should-MatchString 'BC\b' + $result.Features | Should-MatchString 'SDK\b' + $result.Features | Should-MatchString 'SSMS\b' + $result.Features | Should-MatchString 'ADV_SSMS\b' } } } @@ -1593,31 +1593,31 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.SourcePath | Should -Be $TestDrive - $result.InstanceName | Should -Be 'TEST' - $result.InstanceID | Should -Be 'TEST' - $result.InstallSharedDir | Should -Be 'C:\Program Files\Microsoft SQL Server' - $result.InstallSharedWOWDir | Should -Be 'C:\Program Files (x86)\Microsoft SQL Server' - $result.SQLSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.AgtSvcAccountUsername | Should -Be 'COMPANY\AgentAccount' - $result.SqlCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.SQLSysAdminAccounts | Should -Be 'COMPANY\Stacy' - $result.SecurityMode | Should -BeNullOrEmpty - $result.InstallSQLDataDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL" - $result.SQLUserDBDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL\DATA\" - $result.SQLUserDBLogDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL\DATA\" - $result.SQLBackupDir | Should -Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL\Backup" - $result.FTSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.RSSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.ASCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.ASSysAdminAccounts | Should -Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') - $result.ASDataDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' - $result.ASLogDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' - $result.ASBackupDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' - $result.ASTempDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' - $result.ASConfigDir | Should -Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' - $result.ISSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' + $result.SourcePath | Should-Be $TestDrive + $result.InstanceName | Should-Be 'TEST' + $result.InstanceID | Should-Be 'TEST' + $result.InstallSharedDir | Should-Be 'C:\Program Files\Microsoft SQL Server' + $result.InstallSharedWOWDir | Should-Be 'C:\Program Files (x86)\Microsoft SQL Server' + $result.SQLSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.AgtSvcAccountUsername | Should-Be 'COMPANY\AgentAccount' + $result.SqlCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.SQLSysAdminAccounts | Should-Be 'COMPANY\Stacy' + $result.SecurityMode | Should-BeFalsy + $result.InstallSQLDataDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL" + $result.SQLUserDBDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL\DATA\" + $result.SQLUserDBLogDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL\DATA\" + $result.SQLBackupDir | Should-Be "C:\Program Files\Microsoft SQL Server\MSSQL$($MockSqlMajorVersion).TEST\MSSQL\Backup" + $result.FTSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.RSSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.ASCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.ASSysAdminAccounts | Should-Be @('COMPANY\Stacy', 'COMPANY\SSAS Administrators') + $result.ASDataDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Data' + $result.ASLogDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Log' + $result.ASBackupDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Backup' + $result.ASTempDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Temp' + $result.ASConfigDir | Should-Be 'C:\Program Files\Microsoft SQL Server\OLAP\Config' + $result.ISSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' } } } @@ -1673,9 +1673,9 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $currentState = Get-TargetResource @mockGetTargetResourceParameters - $currentState.FailoverClusterGroupName | Should -BeNullOrEmpty - $currentState.FailoverClusterNetworkName | Should -BeNullOrEmpty - $currentState.FailoverClusterIPAddress | Should -BeNullOrEmpty + $currentState.FailoverClusterGroupName | Should-BeFalsy + $currentState.FailoverClusterNetworkName | Should-BeFalsy + $currentState.FailoverClusterIPAddress | Should-BeFalsy } } } @@ -1769,10 +1769,10 @@ Describe 'SqlSetup\Get-TargetResource' -Tag 'Get' { $currentState = Get-TargetResource @mockGetTargetResourceParameters - $currentState.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName - $currentState.FailoverClusterGroupName | Should -Be 'SQL Server (MSSQLSERVER)' - $currentState.FailoverClusterIPAddress | Should -Be '10.0.0.10' - $currentSTate.FailoverClusterNetworkName | Should -Be 'TestDefaultCluster' + $currentState.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName + $currentState.FailoverClusterGroupName | Should-Be 'SQL Server (MSSQLSERVER)' + $currentState.FailoverClusterIPAddress | Should-Be '10.0.0.10' + $currentSTate.FailoverClusterNetworkName | Should-Be 'TestDefaultCluster' } } } @@ -1814,7 +1814,7 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $script:localizedData.ParameterSqlVersionNotAllowedForSetupActionUpgrade ) - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -1841,10 +1841,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } Context 'When using parameter SqlVersion' { @@ -1860,10 +1860,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1893,10 +1893,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1927,10 +1927,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -1962,10 +1962,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -1990,10 +1990,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -2026,10 +2026,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } # Regression test when the variables were detected differently. @@ -2053,10 +2053,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -2087,10 +2087,10 @@ Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -2311,7 +2311,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SqlVersion = '14.0' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -2429,13 +2429,13 @@ 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 - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 } } @@ -2474,10 +2474,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -2515,10 +2515,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -2557,13 +2557,13 @@ 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 - Should -Invoke -CommandName Invoke-InstallationMediaCopy -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-InstallationMediaCopy -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 } } @@ -2601,13 +2601,13 @@ 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 - Should -Invoke -CommandName Invoke-InstallationMediaCopy -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-InstallationMediaCopy -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 } } } @@ -2725,13 +2725,13 @@ 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 - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 0 } } } @@ -2774,10 +2774,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -2820,10 +2820,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -2865,10 +2865,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -2910,10 +2910,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -2955,10 +2955,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } @@ -3004,10 +3004,10 @@ 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 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 } } } @@ -3048,9 +3048,9 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) - $global:DSCMachineStatus | Should -Be 1 + $global:DSCMachineStatus | Should-Be 1 } } } @@ -3074,11 +3074,11 @@ 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 - Should -Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Write-Warning -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 0 } } } @@ -3118,7 +3118,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw "*'SSMS' is not a valid value for setting 'FEATURES'. Refer to SQL Help for more information." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw "*'SSMS' is not a valid value for setting 'FEATURES'. Refer to SQL Help for more information." } } @@ -3135,7 +3135,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SourcePath = $TestDrive } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage "*'ADV_SSMS' is not a valid value for setting 'FEATURES'. Refer to SQL Help for more information." + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage "*'ADV_SSMS' is not a valid value for setting 'FEATURES'. Refer to SQL Help for more information." } } } @@ -3178,12 +3178,12 @@ 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 - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 } It 'Should set the system in the desired state when feature is ADV_SSMS' { @@ -3205,12 +3205,12 @@ 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 - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 } } @@ -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 }) } } @@ -3499,7 +3499,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLUserDBDir = 'C:\MSSQL\' # Pass in a bad path } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*Unable to map the specified paths to valid cluster storage. Drives mapped: Backup; SysData; TempDbData; TempDbLogs; UserLogs.' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*Unable to map the specified paths to valid cluster storage. Drives mapped: Backup; SysData; TempDbData; TempDbLogs; UserLogs.' } } @@ -3547,7 +3547,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } @@ -3591,7 +3591,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' } } } @@ -3639,7 +3639,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' } } } @@ -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,32 +3975,32 @@ 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 - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Test-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-PSDrive -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Test-TargetResource -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { ($Namespace -eq 'root/MSCluster') -and ($ClassName -eq 'MSCluster_ResourceGroup') -and ($Filter -eq "Name = 'Available Storage'") - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Get-CimAssociatedInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -ParameterFilter { ($Association -eq 'MSCluster_ResourceGroupToResource') -and ($ResultClassName -eq 'MSCluster_Resource') - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Get-CimAssociatedInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -ParameterFilter { $Association -eq 'MSCluster_ResourceToPossibleOwner' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Get-CimAssociatedInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -ParameterFilter { $ResultClass -eq 'MSCluster_DiskPartition' - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 - Should -Invoke -CommandName Get-CimInstance -ParameterFilter { + Should-Invoke -CommandName Get-CimInstance -Exactly -ParameterFilter { ($Namespace -eq 'root/MSCluster') -and ($ClassName -eq 'MSCluster_Network') -and ($Filter -eq 'Role >= 2') - } -Exactly -Times 0 -Scope It + } -Scope It -Times 0 } } @@ -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 }) } } @@ -4222,7 +4222,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLUserDBDir = 'C:\MSSQL\' # Pass in a bad path } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*Unable to map the specified paths to valid cluster storage. Drives mapped: Backup; SysData; TempDbData; TempDbLogs; UserLogs.' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*Unable to map the specified paths to valid cluster storage. Drives mapped: Backup; SysData; TempDbData; TempDbLogs; UserLogs.' } } @@ -4270,7 +4270,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw + $null = & ({ Set-TargetResource @mockSetTargetResourceParameters }) } } @@ -4314,7 +4314,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' } } } @@ -4362,7 +4362,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { SQLBackupDir = 'O:\MSSQL\Backup' } - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*Unable to map the specified IP Address(es) to valid cluster networks.' } } } @@ -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. @@ -4522,8 +4522,8 @@ Describe 'Get-ServiceAccountParameters' -Tag 'Helper' { $result = Get-ServiceAccountParameters -ServiceAccount $mockSystemServiceAccount -ServiceType $MockServiceType - $result.$mockAccountArgumentName | Should -BeExactly $mockSystemServiceAccount.UserName - $result.ContainsKey($mockPasswordArgumentName) | Should -BeFalse + $result.$mockAccountArgumentName | Should-BeString -CaseSensitive $mockSystemServiceAccount.UserName + $result.ContainsKey($mockPasswordArgumentName) | Should-BeFalse } } @@ -4533,8 +4533,8 @@ Describe 'Get-ServiceAccountParameters' -Tag 'Helper' { $result = Get-ServiceAccountParameters -ServiceAccount $mockVirtualServiceAccount -ServiceType $MockServiceType - $result.$mockAccountArgumentName | Should -BeExactly $mockVirtualServiceAccount.UserName - $result.ContainsKey($mockPasswordArgumentName) | Should -BeFalse + $result.$mockAccountArgumentName | Should-BeString -CaseSensitive $mockVirtualServiceAccount.UserName + $result.ContainsKey($mockPasswordArgumentName) | Should-BeFalse } } @@ -4544,8 +4544,8 @@ Describe 'Get-ServiceAccountParameters' -Tag 'Helper' { $result = Get-ServiceAccountParameters -ServiceAccount $mockManagedServiceAccount -ServiceType $MockServiceType - $result.$mockAccountArgumentName | Should -BeExactly $mockManagedServiceAccount.UserName - $result.ContainsKey($mockPasswordArgumentName) | Should -BeFalse + $result.$mockAccountArgumentName | Should-BeString -CaseSensitive $mockManagedServiceAccount.UserName + $result.ContainsKey($mockPasswordArgumentName) | Should-BeFalse } } @@ -4555,8 +4555,8 @@ Describe 'Get-ServiceAccountParameters' -Tag 'Helper' { $result = Get-ServiceAccountParameters -ServiceAccount $mockDomainServiceAccount -ServiceType $MockServiceType - $result.$mockAccountArgumentName | Should -BeExactly $mockDomainServiceAccount.UserName - $result.$mockPasswordArgumentName | Should -BeExactly $mockDomainServiceAccount.GetNetworkCredential().Password + $result.$mockAccountArgumentName | Should-BeString -CaseSensitive $mockDomainServiceAccount.UserName + $result.$mockPasswordArgumentName | Should-BeString -CaseSensitive $mockDomainServiceAccount.GetNetworkCredential().Password } } @@ -4567,8 +4567,8 @@ Describe 'Get-ServiceAccountParameters' -Tag 'Helper' { $result = Get-ServiceAccountParameters -ServiceAccount $mockDomainServiceAccountContainingDollarSign -ServiceType $MockServiceType - $result.$mockAccountArgumentName | Should -BeExactly $mockDomainServiceAccountContainingDollarSign.UserName - $result.$mockPasswordArgumentName | Should -BeExactly $mockDomainServiceAccountContainingDollarSign.GetNetworkCredential().Password + $result.$mockAccountArgumentName | Should-BeString -CaseSensitive $mockDomainServiceAccountContainingDollarSign.UserName + $result.$mockPasswordArgumentName | Should-BeString -CaseSensitive $mockDomainServiceAccountContainingDollarSign.GetNetworkCredential().Password } } } @@ -4595,7 +4595,7 @@ Describe 'Get-InstalledSharedFeatures' -Tag 'Helper' { $getInstalledSharedFeaturesResult = Get-InstalledSharedFeatures -SqlServerMajorVersion 14 - $getInstalledSharedFeaturesResult | Should -HaveCount 0 + $getInstalledSharedFeaturesResult | Should-BeCollection -Count 0 } } } @@ -4625,13 +4625,13 @@ Describe 'Get-InstalledSharedFeatures' -Tag 'Helper' { $getInstalledSharedFeaturesResult = Get-InstalledSharedFeatures -SqlServerMajorVersion 14 - $getInstalledSharedFeaturesResult | Should -HaveCount 6 - $getInstalledSharedFeaturesResult | Should -Contain 'DQC' - $getInstalledSharedFeaturesResult | Should -Contain 'BOL' - $getInstalledSharedFeaturesResult | Should -Contain 'CONN' - $getInstalledSharedFeaturesResult | Should -Contain 'BC' - $getInstalledSharedFeaturesResult | Should -Contain 'SDK' - $getInstalledSharedFeaturesResult | Should -Contain 'MDS' + $getInstalledSharedFeaturesResult | Should-BeCollection -Count 6 + $getInstalledSharedFeaturesResult | Should-ContainCollection 'DQC' + $getInstalledSharedFeaturesResult | Should-ContainCollection 'BOL' + $getInstalledSharedFeaturesResult | Should-ContainCollection 'CONN' + $getInstalledSharedFeaturesResult | Should-ContainCollection 'BC' + $getInstalledSharedFeaturesResult | Should-ContainCollection 'SDK' + $getInstalledSharedFeaturesResult | Should-ContainCollection 'MDS' } } } @@ -4643,7 +4643,7 @@ Describe 'Test-FeatureFlag' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - Test-FeatureFlag -FeatureFlag $null -TestFlag 'MyFlag' | Should -BeFalse + Test-FeatureFlag -FeatureFlag $null -TestFlag 'MyFlag' | Should-BeFalse } } } @@ -4653,7 +4653,7 @@ Describe 'Test-FeatureFlag' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - Test-FeatureFlag -FeatureFlag @('FirstFlag', 'SecondFlag') -TestFlag 'SecondFlag' | Should -BeTrue + Test-FeatureFlag -FeatureFlag @('FirstFlag', 'SecondFlag') -TestFlag 'SecondFlag' | Should-BeTrue } } } @@ -4663,7 +4663,7 @@ Describe 'Test-FeatureFlag' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - Test-FeatureFlag -FeatureFlag @('MyFlag2') -TestFlag 'MyFlag' | Should -BeFalse + Test-FeatureFlag -FeatureFlag @('MyFlag2') -TestFlag 'MyFlag' | Should-BeFalse } } } @@ -4683,13 +4683,13 @@ Describe 'Get-FullInstanceId' -Tag 'Helper' { $result = Get-FullInstanceId -InstanceName 'MSSQLSERVER' - $result | Should -Be 'MSSQL14.MSSQLSERVER' + $result | Should-Be 'MSSQL14.MSSQLSERVER' } - Should -Invoke -CommandName Get-RegistryPropertyValue -ParameterFilter { + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -ParameterFilter { $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL' ` -and $Name -eq 'MSSQLSERVER' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -4706,13 +4706,13 @@ Describe 'Get-FullInstanceId' -Tag 'Helper' { $result = Get-FullInstanceId -InstanceName 'NAMED' - $result | Should -Be 'MSSQL14.NAMED' + $result | Should-Be 'MSSQL14.NAMED' } - Should -Invoke -CommandName Get-RegistryPropertyValue -ParameterFilter { + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -ParameterFilter { $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL' ` -and $Name -eq 'NAMED' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -4759,17 +4759,17 @@ Describe 'Get-SqlEngineProperties' -Tag 'Helper' { $result = Get-SqlEngineProperties -ServerName 'localhost' -InstanceName 'MSSQLSERVER' - $result.SQLSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.AgtSvcAccountUsername | Should -Be 'COMPANY\AgentAccount' - $result.SqlSvcStartupType | Should -Be 'Automatic' - $result.AgtSvcStartupType | Should -Be 'Automatic' - $result.SQLCollation | Should -Be 'Finnish_Swedish_CI_AS' - $result.IsClustered | Should -BeTrue - $result.InstallSQLDataDir | Should -Be 'E:\MSSQL\Data' - $result.SQLUserDBDir | Should -Be 'K:\MSSQL\Data' - $result.SQLUserDBLogDir | Should -Be 'L:\MSSQL\Logs' - $result.SQLBackupDir | Should -Be 'O:\MSSQL\Backup' - $result.SecurityMode | Should -BeNullOrEmpty + $result.SQLSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.AgtSvcAccountUsername | Should-Be 'COMPANY\AgentAccount' + $result.SqlSvcStartupType | Should-Be 'Automatic' + $result.AgtSvcStartupType | Should-Be 'Automatic' + $result.SQLCollation | Should-Be 'Finnish_Swedish_CI_AS' + $result.IsClustered | Should-BeTrue + $result.InstallSQLDataDir | Should-Be 'E:\MSSQL\Data' + $result.SQLUserDBDir | Should-Be 'K:\MSSQL\Data' + $result.SQLUserDBLogDir | Should-Be 'L:\MSSQL\Logs' + $result.SQLBackupDir | Should-Be 'O:\MSSQL\Backup' + $result.SecurityMode | Should-BeFalsy } } @@ -4784,7 +4784,7 @@ Describe 'Get-SqlEngineProperties' -Tag 'Helper' { $result = Get-SqlEngineProperties -ServerName 'localhost' -InstanceName 'MSSQLSERVER' - $result.SecurityMode | Should -BeNullOrEmpty + $result.SecurityMode | Should-BeFalsy } } } @@ -4800,7 +4800,7 @@ Describe 'Get-SqlEngineProperties' -Tag 'Helper' { $result = Get-SqlEngineProperties -ServerName 'localhost' -InstanceName 'MSSQLSERVER' - $result.SecurityMode | Should -BeExactly 'SQL' + $result.SecurityMode | Should-BeString -CaseSensitive 'SQL' } } } @@ -4839,10 +4839,10 @@ Describe 'Get-SqlEngineProperties' -Tag 'Helper' { $result = Get-SqlEngineProperties -ServerName 'localhost' -InstanceName 'TEST' - $result.SQLSvcAccountUsername | Should -Be 'COMPANY\SqlAccount' - $result.AgtSvcAccountUsername | Should -Be 'COMPANY\AgentAccount' - $result.SqlSvcStartupType | Should -Be 'Automatic' - $result.AgtSvcStartupType | Should -Be 'Automatic' + $result.SQLSvcAccountUsername | Should-Be 'COMPANY\SqlAccount' + $result.AgtSvcAccountUsername | Should-Be 'COMPANY\AgentAccount' + $result.SqlSvcStartupType | Should-Be 'Automatic' + $result.AgtSvcStartupType | Should-Be 'Automatic' } } } @@ -4861,7 +4861,7 @@ Describe 'Test-IsReplicationFeatureInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 Test-IsReplicationFeatureInstalled -InstanceName 'MSSQLSERVER' | - Should -BeTrue + Should-BeTrue } } } @@ -4878,7 +4878,7 @@ Describe 'Test-IsReplicationFeatureInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 Test-IsReplicationFeatureInstalled -InstanceName 'MSSQLSERVER' | - Should -BeFalse + Should-BeFalse } } } @@ -4904,7 +4904,7 @@ Describe 'Test-IsDQComponentInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 Test-IsDQComponentInstalled -InstanceName 'MSSQLSERVER' -SqlServerMajorVersion '14' | - Should -BeTrue + Should-BeTrue } } } @@ -4919,7 +4919,7 @@ Describe 'Test-IsDQComponentInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 Test-IsDQComponentInstalled -InstanceName 'MSSQLSERVER' -SqlServerMajorVersion '14' | - Should -BeFalse + Should-BeFalse } } } @@ -4937,7 +4937,7 @@ Describe 'Get-InstanceProgramPath' -Tag 'Helper' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - Get-InstanceProgramPath -InstanceName 'MSSQLSERVER' | Should -Be 'C:\Program Files\Microsoft SQL Server' + Get-InstanceProgramPath -InstanceName 'MSSQLSERVER' | Should-Be 'C:\Program Files\Microsoft SQL Server' } } } @@ -4950,12 +4950,12 @@ Describe 'Get-ServiceNamesForInstance' -Tag 'Helper' { $result = Get-ServiceNamesForInstance -InstanceName 'MSSQLSERVER' -SqlServerMajorVersion 14 - $result.DatabaseService | Should -Be 'MSSQLSERVER' - $result.AgentService | Should -Be 'SQLSERVERAGENT' - $result.FullTextService | Should -Be 'MSSQLFDLauncher' - $result.ReportService | Should -Be 'ReportServer' - $result.AnalysisService | Should -Be 'MSSQLServerOLAPService' - $result.IntegrationService | Should -Be 'MsDtsServer140' + $result.DatabaseService | Should-Be 'MSSQLSERVER' + $result.AgentService | Should-Be 'SQLSERVERAGENT' + $result.FullTextService | Should-Be 'MSSQLFDLauncher' + $result.ReportService | Should-Be 'ReportServer' + $result.AnalysisService | Should-Be 'MSSQLServerOLAPService' + $result.IntegrationService | Should-Be 'MsDtsServer140' } } } @@ -4967,11 +4967,11 @@ Describe 'Get-ServiceNamesForInstance' -Tag 'Helper' { $result = Get-ServiceNamesForInstance -InstanceName 'TEST' - $result.DatabaseService | Should -Be 'MSSQL$TEST' - $result.AgentService | Should -Be 'SQLAgent$TEST' - $result.FullTextService | Should -Be 'MSSQLFDLauncher$TEST' - $result.ReportService | Should -Be 'ReportServer$TEST' - $result.AnalysisService | Should -Be 'MSOLAP$TEST' + $result.DatabaseService | Should-Be 'MSSQL$TEST' + $result.AgentService | Should-Be 'SQLAgent$TEST' + $result.FullTextService | Should-Be 'MSSQLFDLauncher$TEST' + $result.ReportService | Should-Be 'ReportServer$TEST' + $result.AnalysisService | Should-Be 'MSOLAP$TEST' } } } @@ -4983,7 +4983,7 @@ Describe 'Get-ServiceNamesForInstance' -Tag 'Helper' { $result = Get-ServiceNamesForInstance -InstanceName 'MSSQLSERVER' - $result.IntegrationService | Should -BeNullOrEmpty + $result.IntegrationService | Should-BeFalsy } } } @@ -5050,12 +5050,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 1 - $result.SqlTempdbFileSize | Should -Be 8 - $result.SqlTempdbFileGrowth | Should -Be 10 - $result.SqlTempdbLogFileSize | Should -Be 8 - $result.SqlTempdbLogFileGrowth | Should -Be 10 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 1 + $result.SqlTempdbFileSize | Should-Be 8 + $result.SqlTempdbFileGrowth | Should-Be 10 + $result.SqlTempdbLogFileSize | Should-Be 8 + $result.SqlTempdbLogFileGrowth | Should-Be 10 } } } @@ -5083,12 +5083,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 1 - $result.SqlTempdbFileSize | Should -Be 8 - $result.SqlTempdbFileGrowth | Should -Be 100 - $result.SqlTempdbLogFileSize | Should -Be 0.75 - $result.SqlTempdbLogFileGrowth | Should -Be 100 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 1 + $result.SqlTempdbFileSize | Should-Be 8 + $result.SqlTempdbFileGrowth | Should-Be 100 + $result.SqlTempdbLogFileSize | Should-Be 0.75 + $result.SqlTempdbLogFileGrowth | Should-Be 100 } } } @@ -5126,12 +5126,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 2 - $result.SqlTempdbFileSize | Should -Be 8 - $result.SqlTempdbFileGrowth | Should -Be 10 - $result.SqlTempdbLogFileSize | Should -Be 0.75 - $result.SqlTempdbLogFileGrowth | Should -Be 10 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 2 + $result.SqlTempdbFileSize | Should-Be 8 + $result.SqlTempdbFileGrowth | Should-Be 10 + $result.SqlTempdbLogFileSize | Should-Be 0.75 + $result.SqlTempdbLogFileGrowth | Should-Be 10 } } } @@ -5169,12 +5169,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 2 - $result.SqlTempdbFileSize | Should -Be 8 - $result.SqlTempdbFileGrowth | Should -Be 100 - $result.SqlTempdbLogFileSize | Should -Be 0.75 - $result.SqlTempdbLogFileGrowth | Should -Be 100 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 2 + $result.SqlTempdbFileSize | Should-Be 8 + $result.SqlTempdbFileGrowth | Should-Be 100 + $result.SqlTempdbLogFileSize | Should-Be 0.75 + $result.SqlTempdbLogFileGrowth | Should-Be 100 } } } @@ -5212,12 +5212,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 2 - $result.SqlTempdbFileSize | Should -Be 20 - $result.SqlTempdbFileGrowth | Should -Be 17.5 - $result.SqlTempdbLogFileSize | Should -Be 0.875 - $result.SqlTempdbLogFileGrowth | Should -Be 17.5 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 2 + $result.SqlTempdbFileSize | Should-Be 20 + $result.SqlTempdbFileGrowth | Should-Be 17.5 + $result.SqlTempdbLogFileSize | Should-Be 0.875 + $result.SqlTempdbLogFileGrowth | Should-Be 17.5 } } } @@ -5255,12 +5255,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 2 - $result.SqlTempdbFileSize | Should -Be 20 - $result.SqlTempdbFileGrowth | Should -Be 1.5 - $result.SqlTempdbLogFileSize | Should -Be 0.875 - $result.SqlTempdbLogFileGrowth | Should -Be 1.5 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 2 + $result.SqlTempdbFileSize | Should-Be 20 + $result.SqlTempdbFileGrowth | Should-Be 1.5 + $result.SqlTempdbLogFileSize | Should-Be 0.875 + $result.SqlTempdbLogFileGrowth | Should-Be 1.5 } } } @@ -5298,12 +5298,12 @@ Describe 'Get-TempDbProperties' -Tag 'Helper' { $result = Get-TempDbProperties -ServerName 'localhost' -InstanceName 'INSTANCE' - $result.SQLTempDBDir | Should -Be 'H:\MSSQL\Temp' - $result.SqlTempdbFileCount | Should -Be 2 - $result.SqlTempdbFileSize | Should -Be 20 - $result.SqlTempdbFileGrowth | Should -Be 110 - $result.SqlTempdbLogFileSize | Should -Be 0.875 - $result.SqlTempdbLogFileGrowth | Should -Be 12 + $result.SQLTempDBDir | Should-Be 'H:\MSSQL\Temp' + $result.SqlTempdbFileCount | Should-Be 2 + $result.SqlTempdbFileSize | Should-Be 20 + $result.SqlTempdbFileGrowth | Should-Be 110 + $result.SqlTempdbLogFileSize | Should-Be 0.875 + $result.SqlTempdbLogFileGrowth | Should-Be 12 } } } @@ -5347,9 +5347,9 @@ Describe 'Get-SqlRoleMembers' -Tag 'Helper' { $result = Get-SqlRoleMembers @getTempDbPropertiesParameters - $result -is [System.Object[]] | Should -BeTrue - $result | Should -HaveCount 1 - $result[0] | Should -Be 'sa' + $result -is [System.Object[]] | Should-BeTrue + $result | Should-BeCollection -Count 1 + $result[0] | Should-Be 'sa' } } } @@ -5374,10 +5374,10 @@ Describe 'Get-SqlRoleMembers' -Tag 'Helper' { $result = Get-SqlRoleMembers @getTempDbPropertiesParameters - $result -is [System.Object[]] | Should -BeTrue - $result | Should -HaveCount 2 - $result[0] | Should -Be 'sa' - $result[1] | Should -Be 'COMPUTER\SqlInstall' + $result -is [System.Object[]] | Should-BeTrue + $result | Should-BeCollection -Count 2 + $result[0] | Should-Be 'sa' + $result[1] | Should-Be 'COMPUTER\SqlInstall' } } } @@ -5440,9 +5440,9 @@ Describe 'Get-SqlClusterProperties' -Tag 'Helper' { $result = Get-SqlClusterProperties -InstanceName 'TEST' - $result.FailoverClusterNetworkName | Should -Be 'TESTCLU01A' - $result.FailoverClusterGroupName | Should -Be 'TESTCLU01A' - $result.FailoverClusterIPAddress | Should -Be '10.0.0.10' + $result.FailoverClusterNetworkName | Should-Be 'TESTCLU01A' + $result.FailoverClusterGroupName | Should-Be 'TESTCLU01A' + $result.FailoverClusterIPAddress | Should-Be '10.0.0.10' } } @@ -5452,7 +5452,7 @@ Describe 'Get-SqlClusterProperties' -Tag 'Helper' { $mockErrorMessage = $script:localizedData.FailoverClusterResourceNotFound -f 'MSSQLSERVER' - { Get-SqlClusterProperties -InstanceName 'MSSQLSERVER' } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Get-SqlClusterProperties -InstanceName 'MSSQLSERVER' } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -5479,8 +5479,8 @@ Describe 'Get-ServiceProperties' -Tag 'Helper' { $result = Get-ServiceProperties -ServiceName 'MSSQL$SQL2014' - $result.UserName | Should -Be 'COMPANY\SqlAccount' - $result.StartupType | Should -Be 'Automatic' + $result.UserName | Should-Be 'COMPANY\SqlAccount' + $result.StartupType | Should-Be 'Automatic' } } } @@ -5495,10 +5495,10 @@ Describe 'Test-IsSsmsInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsInstalled -SqlServerMajorVersion 99 | Should -BeFalse + Test-IsSsmsInstalled -SqlServerMajorVersion 99 | Should-BeFalse } - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-ItemProperty -Exactly -Scope It -Times 0 } } @@ -5511,10 +5511,10 @@ Describe 'Test-IsSsmsInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsInstalled -SqlServerMajorVersion 10 | Should -BeFalse + Test-IsSsmsInstalled -SqlServerMajorVersion 10 | Should-BeFalse } - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ItemProperty -Exactly -Scope It -Times 1 } } @@ -5541,12 +5541,12 @@ Describe 'Test-IsSsmsInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsInstalled -SqlServerMajorVersion 10 | Should -BeTrue + Test-IsSsmsInstalled -SqlServerMajorVersion 10 | Should-BeTrue } - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq (Join-Path -Path $mockRegistryUninstallProductsPath -ChildPath $mockSqlServerManagementStudio2008R2_ProductIdentifyingNumber) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -5564,12 +5564,12 @@ Describe 'Test-IsSsmsInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsInstalled -SqlServerMajorVersion 11 | Should -BeTrue + Test-IsSsmsInstalled -SqlServerMajorVersion 11 | Should-BeTrue } - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq (Join-Path -Path $mockRegistryUninstallProductsPath -ChildPath $mockSqlServerManagementStudio2012_ProductIdentifyingNumber) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -5587,12 +5587,12 @@ Describe 'Test-IsSsmsInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsInstalled -SqlServerMajorVersion 12 | Should -BeTrue + Test-IsSsmsInstalled -SqlServerMajorVersion 12 | Should-BeTrue } - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq (Join-Path -Path $mockRegistryUninstallProductsPath -ChildPath $mockSqlServerManagementStudio2014_ProductIdentifyingNumber) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -5608,10 +5608,10 @@ Describe 'Test-IsSsmsAdvancedInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 99 | Should -BeFalse + Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 99 | Should-BeFalse } - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-ItemProperty -Exactly -Scope It -Times 0 } } @@ -5624,10 +5624,10 @@ Describe 'Test-IsSsmsAdvancedInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 10 | Should -BeFalse + Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 10 | Should-BeFalse } - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ItemProperty -Exactly -Scope It -Times 1 } } @@ -5654,12 +5654,12 @@ Describe 'Test-IsSsmsAdvancedInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 10 | Should -BeTrue + Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 10 | Should-BeTrue } - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq (Join-Path -Path $mockRegistryUninstallProductsPath -ChildPath $mockSqlServerManagementStudioAdvanced2008R2_ProductIdentifyingNumber) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -5677,12 +5677,12 @@ Describe 'Test-IsSsmsAdvancedInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 11 | Should -BeTrue + Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 11 | Should-BeTrue } - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq (Join-Path -Path $mockRegistryUninstallProductsPath -ChildPath $mockSqlServerManagementStudioAdvanced2012_ProductIdentifyingNumber) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -5700,12 +5700,12 @@ Describe 'Test-IsSsmsAdvancedInstalled' -Tag 'Helper' { Set-StrictMode -Version 1.0 InModuleScope -ScriptBlock { - Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 12 | Should -BeTrue + Test-IsSsmsAdvancedInstalled -SqlServerMajorVersion 12 | Should-BeTrue } - Should -Invoke -CommandName Get-ItemProperty -ParameterFilter { + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter { $Path -eq (Join-Path -Path $mockRegistryUninstallProductsPath -ChildPath $mockSqlServerManagementStudioAdvanced2014_ProductIdentifyingNumber) - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -5755,8 +5755,8 @@ Describe 'Get-SqlSharedPaths' -Tag 'Helper' { $result = Get-SqlSharedPaths -SqlServerMajorVersion $MockSqlServerMajorVersion - $result.InstallSharedDir | Should -Be 'C:\Program Files\Microsoft SQL Server' - $result.InstallSharedWOWDir | Should -Be 'C:\Program Files (x86)\Microsoft SQL Server' + $result.InstallSharedDir | Should-Be 'C:\Program Files\Microsoft SQL Server' + $result.InstallSharedWOWDir | Should-Be 'C:\Program Files (x86)\Microsoft SQL Server' } } } @@ -5792,7 +5792,7 @@ Describe 'Get-FirstPathValueFromRegistryPath' -Tag 'Helper' { $result = Get-FirstPathValueFromRegistryPath -Path $mockRegistryPath - $result | Should -Be 'C:\Program Files\Microsoft SQL Server' + $result | Should-Be 'C:\Program Files\Microsoft SQL Server' } } } @@ -5804,8 +5804,8 @@ Describe 'ConvertTo-Decimal' -Tag 'Helper' { $result = ConvertTo-Decimal '192.168.10.0' - $result | Should -BeOfType [System.UInt32] - $result | Should -Be 3232238080 + $result | Should-HaveType ([System.UInt32]) + $result | Should-Be 3232238080 } } } @@ -5818,7 +5818,7 @@ Describe 'Test-IPAddress' -Tag 'Helper' { $result = Test-IPAddress -IPaddress '192.168.10.4' -NetworkID '192.168.10.0' -SubnetMask '255.255.255.0' - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -5830,7 +5830,7 @@ Describe 'Test-IPAddress' -Tag 'Helper' { $result = Test-IPAddress -IPaddress '192.168.10.240' -NetworkID '192.168.10.0' -SubnetMask '255.255.255.128' - $result | Should -BeFalse + $result | Should-BeFalse } } } diff --git a/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 b/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 index 281690506..9ca32b74f 100644 --- a/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 +++ b/tests/Unit/DSC_SqlTraceFlag.Tests.ps1 @@ -178,10 +178,10 @@ Describe 'DSC_SqlTraceFlag\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be 'TestServer' -Because 'ServerName must be correct' - $result.InstanceName | Should -Be 'MSSQLSERVER' -Because 'InstanceName must be correct' - $result.TraceFlags | Should -Be @('3226', '1802') -Because 'TraceFlags must be correct' - $result.TraceFlags.Count | Should -Be 2 -Because 'number of TraceFlags must be correct' + $result.ServerName | Should-Be 'TestServer' -Because 'ServerName must be correct' + $result.InstanceName | Should-Be 'MSSQLSERVER' -Because 'InstanceName must be correct' + $result.TraceFlags | Should-Be @('3226', '1802') -Because 'TraceFlags must be correct' + $result.TraceFlags.Count | Should-Be 2 -Because 'number of TraceFlags must be correct' } } @@ -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 }) } } } @@ -203,10 +203,10 @@ Describe 'DSC_SqlTraceFlag\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be 'TestServer' -Because 'ServerName must be correct' - $result.InstanceName | Should -Be 'INST00' -Because 'InstanceName must be correct' - $result.TraceFlags | Should -BeNullOrEmpty -Because 'TraceFlags must be correct' - $result.TraceFlags.Count | Should -Be 0 -Because 'number of TraceFlags must be correct' + $result.ServerName | Should-Be 'TestServer' -Because 'ServerName must be correct' + $result.InstanceName | Should-Be 'INST00' -Because 'InstanceName must be correct' + $result.TraceFlags | Should-BeFalsy -Because 'TraceFlags must be correct' + $result.TraceFlags.Count | Should-Be 0 -Because 'number of TraceFlags must be correct' } } @@ -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 }) } } } @@ -229,7 +229,7 @@ Describe 'DSC_SqlTraceFlag\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.NotConnectedToWMI -f 'INST01', 'TestServer' { Get-TargetResource @mockGetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -253,7 +253,7 @@ Describe 'DSC_SqlTraceFlag\Get-TargetResource' -Tag 'Get' { $mockErrorMessage = $script:localizedData.NotConnectedToComputerManagement -f 'FakeServer' { Get-TargetResource @mockGetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) } + Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } } @@ -295,12 +295,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'it should return that the trace flags are in the desired state' + $result | Should-BeTrue -Because 'it should return that the trace flags are in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -327,12 +327,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'it should return that the trace flags are in the desired state' + $result | Should-BeTrue -Because 'it should return that the trace flags are in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -355,12 +355,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'it should return that the trace flags are in the desired state' + $result | Should-BeTrue -Because 'it should return that the trace flags are in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -383,12 +383,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'it should return that the trace flags are in the desired state' + $result | Should-BeTrue -Because 'it should return that the trace flags are in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -411,12 +411,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'it should return that the trace flags are in the desired state' + $result | Should-BeTrue -Because 'it should return that the trace flags are in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -440,12 +440,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue -Because 'it should return that the trace flags are in the desired state' + $result | Should-BeTrue -Because 'it should return that the trace flags are in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } } @@ -470,12 +470,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -498,12 +498,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -526,12 +526,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -554,12 +554,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -582,12 +582,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -610,12 +610,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -638,12 +638,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -666,12 +666,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } @@ -695,12 +695,12 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse -Because 'it should return that the trace flags are not in the desired state' + $result | Should-BeFalse -Because 'it should return that the trace flags are not in the desired state' } } It 'Should call the correct mock' { - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope Context + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope Context -Times 1 } } } @@ -713,7 +713,7 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $mockTestTargetResourceParameters.TraceFlags = '3226' $mockTestTargetResourceParameters.TraceFlagsToInclude = '3226' - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage '*(DRC0010)*' + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage '*(DRC0010)*' } } } @@ -726,7 +726,7 @@ Describe 'DSC_SqlTraceFlag\Test-TargetResource' -Tag 'Test' { $mockTestTargetResourceParameters.TraceFlags = '3226' $mockTestTargetResourceParameters.TraceFlagsToExclude = '3226' - { Test-TargetResource @mockTestTargetResourceParameters } | Should -Throw -ExpectedMessage '*(DRC0010)*' + { Test-TargetResource @mockTestTargetResourceParameters } | Should-Throw -ExceptionMessage '*(DRC0010)*' } } } @@ -846,12 +846,12 @@ 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' + $script:mockMethodAlterRan | Should-BeFalse -Because 'no TraceFlag parameter was set' } - Should -Invoke -CommandName New-Object -Exactly -Times 0 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 0 } } @@ -862,18 +862,18 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf "@ -Because 'Alter must change the value correct' } - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 } } @@ -884,18 +884,18 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3228 "@ -Because 'Alter must change the value correct' } - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 } } @@ -907,11 +907,11 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3228 @@ -919,7 +919,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3228 } # New-Object is also called in Get-TargetResource since there is no mock for Get-TargetResource. - Should -Invoke -CommandName New-Object -Exactly -Times 2 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 2 } } @@ -930,11 +930,11 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3226;-T1802;-T3228 @@ -942,7 +942,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3226;-T1802;-T3228 } # New-Object is also called in Get-TargetResource since there is no mock for Get-TargetResource. - Should -Invoke -CommandName New-Object -Exactly -Times 2 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 2 } } @@ -953,11 +953,11 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3226 @@ -965,7 +965,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T3226 } # New-Object is also called in Get-TargetResource since there is no mock for Get-TargetResource. - Should -Invoke -CommandName New-Object -Exactly -Times 2 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 2 } } @@ -976,11 +976,11 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf @@ -988,7 +988,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf } # New-Object is also called in Get-TargetResource since there is no mock for Get-TargetResource. - Should -Invoke -CommandName New-Object -Exactly -Times 2 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 2 } } @@ -1000,11 +1000,11 @@ 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' + $script:mockMethodAlterRan | Should-BeTrue -Because 'method Alter() should run' - $script:mockMethodAlterValue | Should -Be @" + $script:mockMethodAlterValue | Should-Be @" -dC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\Log\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T4199 @@ -1012,8 +1012,8 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T4199 } # New-Object is also called in Get-TargetResource since there is no mock for Get-TargetResource. - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Restart-SqlService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-SqlService -Exactly -Scope It -Times 1 } } } @@ -1026,12 +1026,12 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T4199 $mockSetTargetResourceParameters.TraceFlags = '4199' $mockSetTargetResourceParameters.TraceFlagsToInclude = '4037' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*(DRC0010)*' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*(DRC0010)*' } } It 'Should not call mock New-Object' { - Should -Invoke -CommandName New-Object -Exactly -Times 0 -Scope Context + Should-Invoke -CommandName New-Object -Exactly -Scope Context -Times 0 } } @@ -1043,12 +1043,12 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T4199 $mockSetTargetResourceParameters.TraceFlags = '4199' $mockSetTargetResourceParameters.TraceFlagsToExclude = '4037' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage '*(DRC0010)*' + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage '*(DRC0010)*' } } It 'Should not call mock New-Object' { - Should -Invoke -CommandName New-Object -Exactly -Times 0 -Scope Context + Should-Invoke -CommandName New-Object -Exactly -Scope Context -Times 0 } } @@ -1062,7 +1062,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T4199 $mockErrorMessage = $script:localizedData.NotConnectedToWMI -f 'INST01', 'TestServer' { Test-TargetResource @mockSetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -1086,7 +1086,7 @@ Server\MSSQL15.INST00\MSSQL\DATA\mastlog.ldf;-T4199 $mockErrorMessage = $script:localizedData.NotConnectedToComputerManagement -f 'FakeServer' { Test-TargetResource @mockSetTargetResourceParameters } | - Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) } + Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } } diff --git a/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 b/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 index 248bc695a..124db00ff 100644 --- a/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 +++ b/tests/Unit/DSC_SqlWaitForAG.Tests.ps1 @@ -146,15 +146,15 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be 'localhost' - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.Name | Should -Be 'AGTest' - $result.RetryIntervalSec | Should -Be 1 - $result.RetryCount | Should -Be 2 + $result.ServerName | Should-Be 'localhost' + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.Name | Should-Be 'AGTest' + $result.RetryIntervalSec | Should-Be 1 + $result.RetryCount | Should-Be 2 } - Should -Invoke -CommandName Get-ClusterGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ClusterGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } It 'Should return that the group exist' { @@ -163,11 +163,11 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.GroupExist | Should -BeTrue + $result.GroupExist | Should-BeTrue } - Should -Invoke -CommandName Get-ClusterGroup -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Connect-SQL -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ClusterGroup -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } @@ -185,14 +185,14 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be 'localhost' - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.Name | Should -Be 'AGTest' - $result.RetryIntervalSec | Should -Be 1 - $result.RetryCount | Should -Be 2 + $result.ServerName | Should-Be 'localhost' + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.Name | Should-Be 'AGTest' + $result.RetryIntervalSec | Should-Be 1 + $result.RetryCount | Should-Be 2 } - Should -Invoke -CommandName Get-ClusterGroup -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ClusterGroup -Exactly -Scope It -Times 1 } It 'Should return that the group does not exist' { @@ -201,9 +201,9 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.GroupExist | Should -BeFalse + $result.GroupExist | Should-BeFalse - Should -Invoke -CommandName Get-ClusterGroup -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ClusterGroup -Exactly -Scope It -Times 1 } } } @@ -239,14 +239,14 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be 'localhost' - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.Name | Should -Be 'AGTest' - $result.RetryIntervalSec | Should -Be 1 - $result.RetryCount | Should -Be 2 + $result.ServerName | Should-Be 'localhost' + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.Name | Should-Be 'AGTest' + $result.RetryIntervalSec | Should-Be 1 + $result.RetryCount | Should-Be 2 } - Should -Invoke -CommandName Get-ClusterGroup -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ClusterGroup -Exactly -Scope It -Times 1 } It 'Should return that the group does not exist' { @@ -255,7 +255,7 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.GroupExist | Should -BeFalse + $result.GroupExist | Should-BeFalse } } } @@ -291,14 +291,14 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ServerName | Should -Be 'localhost' - $result.InstanceName | Should -Be 'MSSQLSERVER' - $result.Name | Should -Be 'AGTest' - $result.RetryIntervalSec | Should -Be 1 - $result.RetryCount | Should -Be 2 + $result.ServerName | Should-Be 'localhost' + $result.InstanceName | Should-Be 'MSSQLSERVER' + $result.Name | Should-Be 'AGTest' + $result.RetryIntervalSec | Should-Be 1 + $result.RetryCount | Should-Be 2 } - Should -Invoke -CommandName Get-ClusterGroup -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ClusterGroup -Exactly -Scope It -Times 1 } It 'Should return that the group does not exist' { @@ -307,7 +307,7 @@ Describe 'SqlWaitForAG\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.GroupExist | Should -BeFalse + $result.GroupExist | Should-BeFalse } } } @@ -349,10 +349,10 @@ Describe 'SqlWaitForAG\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } @@ -371,10 +371,10 @@ Describe 'SqlWaitForAG\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 } } } @@ -414,11 +414,11 @@ 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 - Should -Invoke -CommandName Start-Sleep -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Sleep -Exactly -Scope It -Times 1 } } @@ -452,12 +452,12 @@ 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. - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 2 -Scope It - Should -Invoke -CommandName Start-Sleep -Exactly -Times 2 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 2 + Should-Invoke -CommandName Start-Sleep -Exactly -Scope It -Times 2 } } @@ -477,12 +477,12 @@ Describe 'SqlWaitForAG\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.FailedMessage -f 'AGTest' - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } # Looping twice so these mocks are called twice. - Should -Invoke -CommandName Get-TargetResource -Exactly -Times 2 -Scope It - Should -Invoke -CommandName Start-Sleep -Exactly -Times 2 -Scope It + Should-Invoke -CommandName Get-TargetResource -Exactly -Scope It -Times 2 + Should-Invoke -CommandName Start-Sleep -Exactly -Scope It -Times 2 } } } diff --git a/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 b/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 index 14dd84ffd..0e5232e05 100644 --- a/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 +++ b/tests/Unit/DSC_SqlWindowsFirewall.Tests.ps1 @@ -152,7 +152,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -162,11 +162,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -176,7 +176,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -BeNullOrEmpty + $result.Features | Should-BeFalsy } } @@ -186,7 +186,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -247,7 +247,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -257,11 +257,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeTrue - $result.BrowserFirewall | Should -BeTrue - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeTrue + $result.BrowserFirewall | Should-BeTrue + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -271,7 +271,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'SQLENGINE' + $result.Features | Should-Be 'SQLENGINE' } } @@ -281,7 +281,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } } @@ -307,7 +307,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -317,11 +317,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeFalse - $result.BrowserFirewall | Should -BeTrue - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalse + $result.BrowserFirewall | Should-BeTrue + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -331,7 +331,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'SQLENGINE' + $result.Features | Should-Be 'SQLENGINE' } } @@ -341,7 +341,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -367,7 +367,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -377,11 +377,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeTrue - $result.BrowserFirewall | Should -BeFalse - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeTrue + $result.BrowserFirewall | Should-BeFalse + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -391,7 +391,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'SQLENGINE' + $result.Features | Should-Be 'SQLENGINE' } } @@ -401,7 +401,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -427,7 +427,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -437,11 +437,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeFalse - $result.BrowserFirewall | Should -BeFalse - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalse + $result.BrowserFirewall | Should-BeFalse + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -451,7 +451,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'SQLENGINE' + $result.Features | Should-Be 'SQLENGINE' } } @@ -461,7 +461,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -507,7 +507,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -517,11 +517,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -531,7 +531,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -BeNullOrEmpty + $result.Features | Should-BeFalsy } } @@ -541,7 +541,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -602,7 +602,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -612,11 +612,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.AnalysisServicesFirewall | Should -BeTrue - $result.BrowserFirewall | Should -BeTrue - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.AnalysisServicesFirewall | Should-BeTrue + $result.BrowserFirewall | Should-BeTrue + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -626,7 +626,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'AS' + $result.Features | Should-Be 'AS' } } @@ -636,7 +636,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } } @@ -662,7 +662,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -672,11 +672,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.AnalysisServicesFirewall | Should -BeFalse - $result.BrowserFirewall | Should -BeTrue - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.AnalysisServicesFirewall | Should-BeFalse + $result.BrowserFirewall | Should-BeTrue + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -686,7 +686,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'AS' + $result.Features | Should-Be 'AS' } } @@ -696,7 +696,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -722,7 +722,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -732,11 +732,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.AnalysisServicesFirewall | Should -BeTrue - $result.BrowserFirewall | Should -BeFalse - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.AnalysisServicesFirewall | Should-BeTrue + $result.BrowserFirewall | Should-BeFalse + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -746,7 +746,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'AS' + $result.Features | Should-Be 'AS' } } @@ -756,7 +756,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -782,7 +782,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -792,11 +792,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.AnalysisServicesFirewall | Should -BeFalse - $result.BrowserFirewall | Should -BeFalse - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.AnalysisServicesFirewall | Should-BeFalse + $result.BrowserFirewall | Should-BeFalse + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -806,7 +806,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'AS' + $result.Features | Should-Be 'AS' } } @@ -816,7 +816,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -862,7 +862,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -872,11 +872,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -886,7 +886,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -BeNullOrEmpty + $result.Features | Should-BeFalsy } } @@ -896,7 +896,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -957,7 +957,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -967,11 +967,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ReportingServicesFirewall | Should -BeTrue - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.ReportingServicesFirewall | Should-BeTrue + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -981,7 +981,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'RS' + $result.Features | Should-Be 'RS' } } @@ -991,7 +991,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } } @@ -1017,7 +1017,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1027,11 +1027,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ReportingServicesFirewall | Should -BeFalse - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.ReportingServicesFirewall | Should-BeFalse + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -1041,7 +1041,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'RS' + $result.Features | Should-Be 'RS' } } @@ -1051,7 +1051,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1077,7 +1077,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1087,11 +1087,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ReportingServicesFirewall | Should -BeFalse - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.ReportingServicesFirewall | Should-BeFalse + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -1101,7 +1101,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'RS' + $result.Features | Should-Be 'RS' } } @@ -1111,7 +1111,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1137,7 +1137,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1147,11 +1147,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.ReportingServicesFirewall | Should -BeFalse - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.ReportingServicesFirewall | Should-BeFalse + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -1161,7 +1161,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'RS' + $result.Features | Should-Be 'RS' } } @@ -1171,7 +1171,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1217,7 +1217,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1227,11 +1227,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -1241,7 +1241,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -BeNullOrEmpty + $result.Features | Should-BeFalsy } } @@ -1251,7 +1251,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1305,7 +1305,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1315,11 +1315,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IntegrationServicesFirewall | Should -BeTrue - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty + $result.IntegrationServicesFirewall | Should-BeTrue + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy } } @@ -1329,7 +1329,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'IS' + $result.Features | Should-Be 'IS' } } @@ -1339,7 +1339,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } } @@ -1365,7 +1365,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1375,11 +1375,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IntegrationServicesFirewall | Should -BeFalse - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty + $result.IntegrationServicesFirewall | Should-BeFalse + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy } } @@ -1389,7 +1389,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'IS' + $result.Features | Should-Be 'IS' } } @@ -1399,7 +1399,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1425,7 +1425,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1435,11 +1435,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IntegrationServicesFirewall | Should -BeFalse - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty + $result.IntegrationServicesFirewall | Should-BeFalse + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy } } @@ -1449,7 +1449,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'IS' + $result.Features | Should-Be 'IS' } } @@ -1459,7 +1459,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1484,7 +1484,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1494,11 +1494,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IntegrationServicesFirewall | Should -BeFalse - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty + $result.IntegrationServicesFirewall | Should-BeFalse + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.DatabaseEngineFirewall | Should-BeFalsy } } @@ -1508,7 +1508,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'IS' + $result.Features | Should-Be 'IS' } } @@ -1518,7 +1518,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1564,7 +1564,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1574,11 +1574,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.DatabaseEngineFirewall | Should -BeNullOrEmpty - $result.BrowserFirewall | Should -BeNullOrEmpty - $result.ReportingServicesFirewall | Should -BeNullOrEmpty - $result.AnalysisServicesFirewall | Should -BeNullOrEmpty - $result.IntegrationServicesFirewall | Should -BeNullOrEmpty + $result.DatabaseEngineFirewall | Should-BeFalsy + $result.BrowserFirewall | Should-BeFalsy + $result.ReportingServicesFirewall | Should-BeFalsy + $result.AnalysisServicesFirewall | Should-BeFalsy + $result.IntegrationServicesFirewall | Should-BeFalsy } } @@ -1588,7 +1588,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -BeNullOrEmpty + $result.Features | Should-BeFalsy } } @@ -1598,7 +1598,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Absent' + $result.Ensure | Should-Be 'Absent' } } } @@ -1669,7 +1669,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.InstanceName | Should -Be $mockGetTargetResourceParameters.InstanceName + $result.InstanceName | Should-Be $mockGetTargetResourceParameters.InstanceName } } @@ -1679,11 +1679,11 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.IntegrationServicesFirewall | Should -BeTrue - $result.ReportingServicesFirewall | Should -BeTrue - $result.AnalysisServicesFirewall | Should -BeTrue - $result.BrowserFirewall | Should -BeTrue - $result.DatabaseEngineFirewall | Should -BeTrue + $result.IntegrationServicesFirewall | Should-BeTrue + $result.ReportingServicesFirewall | Should-BeTrue + $result.AnalysisServicesFirewall | Should-BeTrue + $result.BrowserFirewall | Should-BeTrue + $result.DatabaseEngineFirewall | Should-BeTrue } } @@ -1693,7 +1693,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Features | Should -Be 'SQLENGINE,RS,AS,IS' + $result.Features | Should-Be 'SQLENGINE,RS,AS,IS' } } @@ -1703,7 +1703,7 @@ Describe 'SqlWindowsFirewall\Get-TargetResource' -Tag 'Get' { $result = Get-TargetResource @mockGetTargetResourceParameters - $result.Ensure | Should -Be 'Present' + $result.Ensure | Should-Be 'Present' } } } @@ -1740,11 +1740,11 @@ 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 - Should -Invoke Remove-SmbMapping -Exactly -Times 1 -Scope It + Should-Invoke New-SmbMapping -Exactly -Scope It -Times 1 + Should-Invoke Remove-SmbMapping -Exactly -Scope It -Times 1 } } } @@ -1783,7 +1783,7 @@ Describe 'SqlWindowsFirewall\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -1805,7 +1805,7 @@ Describe 'SqlWindowsFirewall\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -1827,7 +1827,7 @@ Describe 'SqlWindowsFirewall\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -1847,7 +1847,7 @@ Describe 'SqlWindowsFirewall\Test-TargetResource' -Tag 'Test' { $result = Test-TargetResource @mockTestTargetResourceParameters - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -1940,10 +1940,10 @@ 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 + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -1976,10 +1976,10 @@ 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 + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2012,10 +2012,10 @@ 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 + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2029,10 +2029,10 @@ 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 + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 1 } } } @@ -2054,10 +2054,10 @@ 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 + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 0 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 1 } } } @@ -2091,10 +2091,10 @@ 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' + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 1 #-Because 'the rule already exist for the Database Engine' + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 1 #-Because 'no rule exist for the SQL Browser' } } } @@ -2108,10 +2108,10 @@ 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' + Should-Invoke -CommandName Set-NetFirewallRule -Exactly -Scope It -Times 0 #-Because 'no rules exist to change' + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 2 #-Because 'no rule exist for either the Database Engine or SQL Browser' } } } @@ -2158,9 +2158,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2193,9 +2193,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2215,9 +2215,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 1 } } } @@ -2238,9 +2238,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 1 } } } @@ -2261,9 +2261,9 @@ 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' + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 2 #-Because 'no rule exist for either Analysis Services or SQL Browser' } } } @@ -2309,9 +2309,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2343,9 +2343,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2364,9 +2364,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 2 } } } @@ -2413,9 +2413,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2447,9 +2447,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 0 } } } @@ -2472,9 +2472,9 @@ 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 + Should-Invoke -CommandName New-NetFirewallRule -Exactly -Scope It -Times 2 } } } @@ -2513,11 +2513,11 @@ 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 - Should -Invoke Remove-SmbMapping -Exactly -Times 1 -Scope It + Should-Invoke New-SmbMapping -Exactly -Scope It -Times 1 + Should-Invoke Remove-SmbMapping -Exactly -Scope It -Times 1 } } @@ -2552,7 +2552,7 @@ Describe 'SqlWindowsFirewall\Set-TargetResource' -Tag 'Set' { $mockErrorMessage = $script:localizedData.TestFailedAfterSet - { Set-TargetResource @mockSetTargetResourceParameters } | Should -Throw -ExpectedMessage ('*' + $mockErrorMessage) + { Set-TargetResource @mockSetTargetResourceParameters } | Should-Throw -ExceptionMessage ('*' + $mockErrorMessage) } } } @@ -2618,7 +2618,7 @@ Describe 'SqlWindowsFirewall/Get-SqlRootPath' -Tag 'Helper' { InModuleScope -Parameters $_ -ScriptBlock { $result = Get-SQLPath -Feature $MockFeature -InstanceName 'MSSQLSERVER' -SQLVersion $MockSqlMajorVersion - $result | Should -Be 'C:\Mocked\Path' + $result | Should-Be 'C:\Mocked\Path' } } } @@ -2636,7 +2636,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled $true -Profile 'Any' -Direction 'Inbound' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2660,7 +2660,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'False' -Profile 'Any' -Direction 'Inbound' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2670,7 +2670,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Domain' -Direction 'Inbound' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2680,7 +2680,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Outbound' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2690,7 +2690,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2724,7 +2724,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Program 'WrongProgramName' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2734,7 +2734,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Program 'ProgramName' - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -2769,7 +2769,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Service 'WrongServiceName' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2779,7 +2779,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Service 'ServiceName' - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -2790,7 +2790,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Protocol 'TCP' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2825,7 +2825,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Protocol 'TCP' -LocalPort '1434' - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -2835,7 +2835,7 @@ Describe 'SqlWindowsFirewall/Test-IsFirewallRuleInDesiredState' -Tag 'Helper' { InModuleScope -ScriptBlock { $result = Test-IsFirewallRuleInDesiredState -DisplayName 'RuleName' -Enabled 'True' -Profile 'Any' -Direction 'Inbound' -Protocol 'TCP' -LocalPort '1433' - $result | Should -BeTrue + $result | Should-BeTrue } } } diff --git a/tests/Unit/Private/Assert-Feature.Tests.ps1 b/tests/Unit/Private/Assert-Feature.Tests.ps1 index 8c481a67d..7fe273a96 100644 --- a/tests/Unit/Private/Assert-Feature.Tests.ps1 +++ b/tests/Unit/Private/Assert-Feature.Tests.ps1 @@ -58,9 +58,9 @@ Describe 'Assert-Feature' -Tag 'Private' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { + $null = & ({ Assert-Feature -Feature 'RS' -ProductVersion '14' - } | Should -Not -Throw + }) } } @@ -68,9 +68,9 @@ Describe 'Assert-Feature' -Tag 'Private' { InModuleScope -ScriptBlock { Set-StrictMode -Version 1.0 - { + $null = & ({ Assert-Feature -Feature 'RS', 'SQLENGINE' -ProductVersion '14' - } | Should -Not -Throw + }) } } } @@ -90,7 +90,7 @@ Describe 'Assert-Feature' -Tag 'Private' { { Assert-Feature -Feature 'RS' -ProductVersion 14 - } | Should -Throw -ExpectedMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) + } | Should-Throw -ExceptionMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) } } } @@ -102,7 +102,7 @@ Describe 'Assert-Feature' -Tag 'Private' { { 'RS' | Assert-Feature -ProductVersion 14 - } | Should -Throw -ExpectedMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) + } | Should-Throw -ExceptionMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) } } } @@ -116,7 +116,7 @@ Describe 'Assert-Feature' -Tag 'Private' { { Assert-Feature -Feature @('RS', 'SQLENGINE') -ProductVersion 14 - } | Should -Throw -ExpectedMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) + } | Should-Throw -ExceptionMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) } } } @@ -128,7 +128,7 @@ Describe 'Assert-Feature' -Tag 'Private' { { 'RS', 'SQLENGINE' | Assert-Feature -ProductVersion 14 - } | Should -Throw -ExpectedMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) + } | Should-Throw -ExceptionMessage ($script:localizedData.Feature_Assert_NotSupportedFeature -f 'RS', 14) } } } diff --git a/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 b/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 index f42fba71a..6210a764e 100644 --- a/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 +++ b/tests/Unit/Private/Assert-ManagedServiceType.Tests.ps1 @@ -67,10 +67,10 @@ Describe 'Assert-ManagedServiceType' -Tag 'Private' { InModuleScope -Parameters $_ -ScriptBlock { Set-StrictMode -Version 1.0 - { + $null = & ({ $MockServiceObject | Assert-ManagedServiceType -ServiceType 'DatabaseEngine' -ErrorAction 'Stop' - } | Should -Not -Throw + }) } } } @@ -97,7 +97,7 @@ Describe 'Assert-ManagedServiceType' -Tag 'Private' { { $MockServiceObject | Assert-ManagedServiceType -ServiceType 'SqlServerAgent' -ErrorAction 'Stop' - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -114,7 +114,7 @@ Describe 'Assert-ManagedServiceType' -Tag 'Private' { { $MockServiceObject | Assert-ManagedServiceType -ServiceType 'SqlServerAgent' -ErrorAction 'SilentlyContinue' - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 b/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 index 5beec1af6..361019bba 100644 --- a/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 +++ b/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 @@ -99,11 +99,11 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { ) { It 'Should not throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { - { + $null = & ({ Assert-SetupActionProperties -Property @{ ValidProperty = 'Value' } -SetupAction $MockSetupAction - } | Should -Not -Throw + }) } } } @@ -122,7 +122,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { Assert-SetupActionProperties -Property @{ $MockParameterName = 'Value' } -SetupAction 'NotUsed' - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -167,7 +167,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { $MockParameters.Role = 'SPI_AS_NewFarm' Assert-SetupActionProperties -Property $MockParameters -SetupAction 'NotUsed' - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -179,7 +179,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { Assert-SetupActionProperties -Property @{ SecurityMode = 'SQL' } -SetupAction 'NotUsed' - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -189,11 +189,11 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { InModuleScope -Parameters @{ MockFileStreamLevel = $_ } -ScriptBlock { - { + $null = & ({ Assert-SetupActionProperties -Property @{ FileStreamLevel = $MockFileStreamLevel } -SetupAction 'NotUsed' - } | Should -Not -Throw + }) } } } @@ -207,7 +207,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { Assert-SetupActionProperties -Property @{ FileStreamLevel = $MockFileStreamLevel } -SetupAction 'NotUsed' - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -244,7 +244,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { Assert-SetupActionProperties -Property @{ $MockParameterName = 'AccountName' } -SetupAction 'NotUsed' - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -277,12 +277,12 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { ) { It 'Should not throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { - { + $null = & ({ Assert-SetupActionProperties -Property @{ $MockParameterName = 'AccountName' ($MockParameterName -replace 'Account', 'Password') = 'Password' } -SetupAction 'NotUsed' - } | Should -Not -Throw + }) } } } @@ -321,11 +321,11 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { It 'Should not throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { - { + $null = & ({ Assert-SetupActionProperties -Property @{ $MockParameterName = 'myMSA$' } -SetupAction 'NotUsed' - } | Should -Not -Throw + }) } } } @@ -414,7 +414,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { ) Assert-SetupActionProperties -Property $MockParameters -SetupAction 'NotUsed' - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -529,7 +529,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { MediaPath = $TestDrive Features = $MockFeature } -SetupAction $MockSetupAction - } | Should -Throw -ErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ARCP0001,Assert-RequiredCommandParameter' # cSpell: disable-line } } } @@ -548,7 +548,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { Assert-SetupActionProperties -Property @{ ASServerMode = 'PowerPivot' } -SetupAction $MockSetupAction - } | Should -Throw -ErrorId 'ASAP0001,Assert-SetupActionProperties' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ASAP0001,Assert-SetupActionProperties' # cSpell: disable-line } } } @@ -564,7 +564,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { Assert-SetupActionProperties -Property @{ RsInstallMode = 'DefaultNativeMode' } -SetupAction $MockSetupAction - } | Should -Throw -ErrorId 'ASAP0002,Assert-SetupActionProperties' # cSpell: disable-line + } | Should-Throw -FullyQualifiedErrorId 'ASAP0002,Assert-SetupActionProperties' # cSpell: disable-line } } } diff --git a/tests/Unit/Private/ConvertFrom-ManagedServiceType.Tests.ps1 b/tests/Unit/Private/ConvertFrom-ManagedServiceType.Tests.ps1 index 79b6fbf98..5c83151cc 100644 --- a/tests/Unit/Private/ConvertFrom-ManagedServiceType.Tests.ps1 +++ b/tests/Unit/Private/ConvertFrom-ManagedServiceType.Tests.ps1 @@ -103,8 +103,8 @@ Describe 'ConvertFrom-ManagedServiceType' -Tag 'Private' { # Get the ManagedServiceType $managedServiceType = ConvertFrom-ManagedServiceType -ServiceType $MockServiceType - $managedServiceType | Should -BeOfType [System.String] - $managedServiceType | Should -Be $MockExpectedType + $managedServiceType | Should-HaveType ([System.String]) + $managedServiceType | Should-Be $MockExpectedType } } } @@ -116,7 +116,7 @@ Describe 'ConvertFrom-ManagedServiceType' -Tag 'Private' { $mockErrorMessage = '*Unable to match the identifier name UnknownType to a valid enumerator name*' - { ConvertFrom-ManagedServiceType -ServiceType 'UnknownType' -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage $mockErrorMessage + { ConvertFrom-ManagedServiceType -ServiceType 'UnknownType' -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/Private/ConvertTo-ManagedServiceType.Tests.ps1 b/tests/Unit/Private/ConvertTo-ManagedServiceType.Tests.ps1 index 626928ef0..e5b965282 100644 --- a/tests/Unit/Private/ConvertTo-ManagedServiceType.Tests.ps1 +++ b/tests/Unit/Private/ConvertTo-ManagedServiceType.Tests.ps1 @@ -103,8 +103,8 @@ Describe 'ConvertTo-ManagedServiceType' -Tag 'Private' { # Get the ManagedServiceType $managedServiceType = ConvertTo-ManagedServiceType -ServiceType $MockServiceType - $managedServiceType | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType' - $managedServiceType | Should -Be $MockExpectedType + $managedServiceType | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Wmi.ManagedServiceType' + $managedServiceType | Should-Be $MockExpectedType } } } @@ -116,7 +116,7 @@ Describe 'ConvertTo-ManagedServiceType' -Tag 'Private' { $mockErrorMessage = 'Cannot validate argument on parameter ''ServiceType''. The argument "UnknownType" does not belong to the set "DatabaseEngine,SQLServerAgent,Search,IntegrationServices,AnalysisServices,ReportingServices,SQLServerBrowser,NotificationServices" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.' - { ConvertTo-ManagedServiceType -ServiceType 'UnknownType' -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage $mockErrorMessage + { ConvertTo-ManagedServiceType -ServiceType 'UnknownType' -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage $mockErrorMessage } } } diff --git a/tests/Unit/Private/ConvertTo-RedactedText.Tests.ps1 b/tests/Unit/Private/ConvertTo-RedactedText.Tests.ps1 index 977d8686b..603473ab0 100644 --- a/tests/Unit/Private/ConvertTo-RedactedText.Tests.ps1 +++ b/tests/Unit/Private/ConvertTo-RedactedText.Tests.ps1 @@ -57,7 +57,7 @@ Describe 'ConvertTo-RedactedText' -Tag 'Private' { $result = ConvertTo-RedactedText -Text 'My secret phrase: secret123 secret456' -RedactPhrase 'secret123' - $result | Should -Be 'My secret phrase: ******* secret456' + $result | Should-Be 'My secret phrase: ******* secret456' } } @@ -67,7 +67,7 @@ Describe 'ConvertTo-RedactedText' -Tag 'Private' { $result = ConvertTo-RedactedText -Text 'My secret phrase: secret123 secret456' -RedactPhrase 'secret123', 'secret456' - $result | Should -Be 'My secret phrase: ******* *******' + $result | Should-Be 'My secret phrase: ******* *******' } } @@ -81,7 +81,7 @@ secret123 secret456 '@ -RedactPhrase 'secret123', 'secret456' - $result | Should -Be @' + $result | Should-Be @' My secret phrase: ******* ******* @@ -95,7 +95,7 @@ My secret phrase: $result = ConvertTo-RedactedText -RedactWith '----' -Text 'My secret phrase: secret123' -RedactPhrase 'secret123' - $result | Should -Be 'My secret phrase: ----' + $result | Should-Be 'My secret phrase: ----' } } @@ -106,7 +106,7 @@ My secret phrase: # CSpell: disable-next $result = ConvertTo-RedactedText -Text 'My secret phrase: ^s/d(ecret)123' -RedactPhrase '^s/d(ecret)123' - $result | Should -Be 'My secret phrase: *******' + $result | Should-Be 'My secret phrase: *******' } } } diff --git a/tests/Unit/Private/Get-FileVersionInformation.Tests.ps1 b/tests/Unit/Private/Get-FileVersionInformation.Tests.ps1 index ff75effe6..d67f4655b 100644 --- a/tests/Unit/Private/Get-FileVersionInformation.Tests.ps1 +++ b/tests/Unit/Private/Get-FileVersionInformation.Tests.ps1 @@ -69,7 +69,7 @@ Describe 'Get-FileVersionInformation' -Tag 'Private' { $result = Get-FileVersionInformation -FilePath $mockFilePath - $result.ProductVersion | Should -Be '16.0.1000.6' + $result.ProductVersion | Should-Be '16.0.1000.6' } } } @@ -81,7 +81,7 @@ Describe 'Get-FileVersionInformation' -Tag 'Private' { $result = $mockFilePath | Get-FileVersionInformation - $result.ProductVersion | Should -Be '16.0.1000.6' + $result.ProductVersion | Should-Be '16.0.1000.6' } } } @@ -109,7 +109,7 @@ Describe 'Get-FileVersionInformation' -Tag 'Private' { $result = Get-FileVersionInformation -FilePath $mockFilePath - $result.ProductVersion | Should -Be '16.0.1000.6' + $result.ProductVersion | Should-Be '16.0.1000.6' } } } @@ -121,7 +121,7 @@ Describe 'Get-FileVersionInformation' -Tag 'Private' { $result = $mockFilePath | Get-FileVersionInformation - $result.ProductVersion | Should -Be '16.0.1000.6' + $result.ProductVersion | Should-Be '16.0.1000.6' } } } @@ -133,7 +133,7 @@ Describe 'Get-FileVersionInformation' -Tag 'Private' { Set-StrictMode -Version 1.0 { [System.IO.FileInfo] $TestDrive | Get-FileVersionInformation } | - Should -Throw -ExpectedMessage $script:localizedData.FileVersionInformation_Get_FilePathIsNotFile + Should-Throw -ExceptionMessage $script:localizedData.FileVersionInformation_Get_FilePathIsNotFile } } } @@ -144,7 +144,7 @@ Describe 'Get-FileVersionInformation' -Tag 'Private' { Set-StrictMode -Version 1.0 { Get-Item -Path $TestDrive | Get-FileVersionInformation -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage 'The input object cannot be bound to any parameters for the command*' + Should-Throw -ExceptionMessage 'The input object cannot be bound to any parameters for the command*' } } } diff --git a/tests/Unit/Private/Get-SMOModuleCalculatedVersion.Tests.ps1 b/tests/Unit/Private/Get-SMOModuleCalculatedVersion.Tests.ps1 index 5a0dbabfd..92907a3c4 100644 --- a/tests/Unit/Private/Get-SMOModuleCalculatedVersion.Tests.ps1 +++ b/tests/Unit/Private/Get-SMOModuleCalculatedVersion.Tests.ps1 @@ -60,7 +60,7 @@ Describe 'Get-SMOModuleCalculatedVersion' -Tag 'Private' { Version = [Version]::new(21, 1, 18068) } - $sqlServerModule | Get-SMOModuleCalculatedVersion | Should -Be '21.1.18068' + $sqlServerModule | Get-SMOModuleCalculatedVersion | Should-Be '21.1.18068' } } @@ -79,7 +79,7 @@ Describe 'Get-SMOModuleCalculatedVersion' -Tag 'Private' { } } - $sqlServerModule | Get-SMOModuleCalculatedVersion | Should -Be '22.0.49-preview1' + $sqlServerModule | Get-SMOModuleCalculatedVersion | Should-Be '22.0.49-preview1' } } } @@ -95,7 +95,7 @@ Describe 'Get-SMOModuleCalculatedVersion' -Tag 'Private' { Path = 'C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\SQLPS\Sqlps.ps1' } - $sqlServerModule | Get-SMOModuleCalculatedVersion | Should -Be '13.0' + $sqlServerModule | Get-SMOModuleCalculatedVersion | Should-Be '13.0' } } } @@ -110,7 +110,7 @@ Describe 'Get-SMOModuleCalculatedVersion' -Tag 'Private' { Version = [Version]::new(1, 0, 0) } - $sqlServerModule | Get-SMOModuleCalculatedVersion | Should -Be '1.0.0' + $sqlServerModule | Get-SMOModuleCalculatedVersion | Should-Be '1.0.0' } } @@ -129,7 +129,7 @@ Describe 'Get-SMOModuleCalculatedVersion' -Tag 'Private' { } } - $sqlServerModule | Get-SMOModuleCalculatedVersion | Should -Be '1.0.0-preview1' + $sqlServerModule | Get-SMOModuleCalculatedVersion | Should-Be '1.0.0-preview1' } } } diff --git a/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 b/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 index d2b329660..2ea579fef 100644 --- a/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 +++ b/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 @@ -146,8 +146,8 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } } @@ -175,7 +175,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { MediaPath = '\SqlMedia' InstanceName = 'INSTANCE' # Intentionally using both upper- and lower-case. - Features = 'SqlEngine', 'AZUREEXTENSION' + Features = 'SqlEngine', 'AZUREEXTENSION' # cSpell: disable-line SqlSysAdminAccounts = 'DOMAIN\User', 'COMPANY\SQL Administrators' } } @@ -186,16 +186,14 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE,AZUREEXTENSION' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/QUIET' -and + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cSpell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cSpell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE,AZUREEXTENSION' -and # cSpell: disable-line + $ArgumentList -match '/SQLSYSADMINACCOUNTS="DOMAIN\\User"\ "COMPANY\\SQL\ Administrators"' # cSpell: disable-line + } -Scope It -Times 1 } } } @@ -205,16 +203,13 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE,AZUREEXTENSION' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE,AZUREEXTENSION' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -224,7 +219,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -256,12 +251,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -695,12 +687,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -770,6 +759,10 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Force = $true } } + + $mockVerboseMessage = InModuleScope -ScriptBlock { + $script:localizedData.Server_SetupArguments + } } BeforeEach { @@ -785,21 +778,10 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { # Redirect all verbose stream to $null to ge no output from ShouldProcess. Invoke-SetupAction @installSqlDscServerParameters -Verbose 4> $null - $mockVerboseMessage = $script:localizedData.Server_SetupArguments - - Should -Invoke -CommandName Write-Verbose -ParameterFilter { - # Only test the command that output the string that should be tested. - $correctMessage = $Message -match $mockVerboseMessage - - # Only test string if it is the correct verbose command - if ($correctMessage) - { - $Message | Should -MatchExactly $MockExpectedRegEx - } - - # Return wether the correct command was called or not. - $correctMessage - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Write-Verbose -Exactly -ParameterFilter { + # Only test the verbose message that output the string that should be tested. + $Message -match $mockVerboseMessage -and $Message -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -837,14 +819,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Upgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Upgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -854,14 +833,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Upgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Upgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -871,7 +847,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -973,12 +949,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1027,19 +1000,16 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=InstallFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=InstallFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1049,19 +1019,16 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=InstallFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=InstallFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1071,7 +1038,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -1106,12 +1073,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1438,12 +1402,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1483,14 +1444,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1500,14 +1458,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1517,7 +1472,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -1548,12 +1503,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1725,12 +1677,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1776,17 +1725,14 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteFailoverCluster' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteFailoverCluster' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1796,17 +1742,14 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteFailoverCluster' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteFailoverCluster' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } } @@ -1816,7 +1759,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2021,12 +1964,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2070,14 +2010,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=AddNode' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=AddNode' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2087,14 +2024,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=AddNode' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=AddNode' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2104,7 +2038,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2139,12 +2073,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2275,12 +2206,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2317,13 +2245,10 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RemoveNode' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RemoveNode' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2333,13 +2258,10 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RemoveNode' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RemoveNode' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2349,7 +2271,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2389,12 +2311,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2437,13 +2356,10 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { # cspell: disable-next - $ArgumentList | Should -MatchExactly '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + $ArgumentList -match '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' + } -Scope It -Times 1 } } } @@ -2453,13 +2369,10 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { # cspell: disable-next - $ArgumentList | Should -MatchExactly '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + $ArgumentList -match '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' + } -Scope It -Times 1 } } } @@ -2469,7 +2382,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2528,12 +2441,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2571,14 +2481,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RebuildDatabase' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RebuildDatabase' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2588,14 +2495,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RebuildDatabase' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RebuildDatabase' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2605,7 +2509,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2686,12 +2590,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2730,15 +2631,12 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=EditionUpgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/PID="22222-00000-00000-00000-00000"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=EditionUpgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/PID="22222-00000-00000-00000-00000"' + } -Scope It -Times 1 } } } @@ -2748,15 +2646,12 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=EditionUpgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/PID="22222-00000-00000-00000-00000"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=EditionUpgrade' + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + $ArgumentList -match '\/PID="22222-00000-00000-00000-00000"' + } -Scope It -Times 1 } } } @@ -2766,7 +2661,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2808,12 +2703,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2852,14 +2744,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Repair' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Repair' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2869,14 +2758,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Repair' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Repair' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2886,7 +2772,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2916,12 +2802,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -2982,12 +2865,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -3027,15 +2907,12 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareImage' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCEID="Instance"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareImage' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCEID="Instance"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3045,15 +2922,12 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareImage' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCEID="Instance"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareImage' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCEID="Instance"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3063,7 +2937,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -3151,12 +3025,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -3193,12 +3064,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteImage' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteImage' + } -Scope It -Times 1 } } } @@ -3208,12 +3076,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteImage' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteImage' + } -Scope It -Times 1 } } } @@ -3223,7 +3088,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -3251,12 +3116,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3480,12 +3342,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -3524,14 +3383,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Uninstall' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Uninstall' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3541,14 +3397,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Uninstall' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Uninstall' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3558,7 +3411,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -3602,20 +3455,17 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURERESOURCEGROUP="MyResourceGroup"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZUREREGION="West-US"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=AZUREEXTENSION' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' -and # cspell: disable-line + $ArgumentList -match '\/AZURERESOURCEGROUP="MyResourceGroup"' -and # cspell: disable-line + $ArgumentList -match '\/AZUREREGION="West-US"' -and # cspell: disable-line + $ArgumentList -match '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=AZUREEXTENSION' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3625,20 +3475,17 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURERESOURCEGROUP="MyResourceGroup"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZUREREGION="West-US"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=AZUREEXTENSION' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' -and # cspell: disable-line + $ArgumentList -match '\/AZURERESOURCEGROUP="MyResourceGroup"' -and # cspell: disable-line + $ArgumentList -match '\/AZUREREGION="West-US"' -and # cspell: disable-line + $ArgumentList -match '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=AZUREEXTENSION' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3648,7 +3495,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -3694,12 +3541,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -3738,14 +3582,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3755,14 +3596,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3772,7 +3610,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -3828,12 +3666,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -3882,7 +3717,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { $mockVerboseMessage = $script:localizedData.Server_SetupArguments - Should -Invoke -CommandName Write-Verbose -ParameterFilter { + Should-Invoke -CommandName Write-Verbose -Exactly -ParameterFilter { # Only test the command that output the string that should be tested. $correctMessage = $Message -match $mockVerboseMessage @@ -3894,7 +3729,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { # Return wether the correct command was called or not. $correctMessage - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1s 1 -Scope It } } } @@ -3922,14 +3757,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3939,14 +3771,11 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line + } -Scope It -Times 1 } } } @@ -3956,7 +3785,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { InModuleScope -ScriptBlock { Invoke-SetupAction -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -4002,12 +3831,9 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { Invoke-SetupAction @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Add-SqlDscNode.Tests.ps1 b/tests/Unit/Public/Add-SqlDscNode.Tests.ps1 index 8353c8d9e..a08998ce4 100644 --- a/tests/Unit/Public/Add-SqlDscNode.Tests.ps1 +++ b/tests/Unit/Public/Add-SqlDscNode.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Add-SqlDscNode' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''AddNode''' { @@ -109,14 +109,11 @@ Describe 'Add-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Add-SqlDscNode -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=AddNode' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=AddNode' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -124,14 +121,11 @@ Describe 'Add-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Add-SqlDscNode -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=AddNode' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=AddNode' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -139,7 +133,7 @@ Describe 'Add-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Add-SqlDscNode -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -169,12 +163,9 @@ Describe 'Add-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Add-SqlDscNode @addSqlDscNodeParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } @@ -299,12 +290,9 @@ Describe 'Add-SqlDscNode' -Tag 'Public' { Add-SqlDscNode @addSqlDscNodeParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 index c642e259c..875df89ba 100644 --- a/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Add-SqlDscTraceFlag.Tests.ps1 @@ -75,15 +75,15 @@ Describe 'Add-SqlDscTraceFlag' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When passing $null as ServiceObject' { It 'Should throw the correct error' { $mockErrorMessage = 'Cannot bind argument to parameter ''ServiceObject'' because it is null.' - { Add-SqlDscTraceFlag -ServiceObject $null } | Should -Throw -ExpectedMessage $mockErrorMessage + { Add-SqlDscTraceFlag -ServiceObject $null } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -103,39 +103,39 @@ 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Scope It -Times 0 } } 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -143,29 +143,29 @@ 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Scope It -Times 0 } } } @@ -183,22 +183,22 @@ 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 2 -and $TraceFlag -contains 4199 -and $TraceFlag -contains 3226 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } 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 }) - Should -Invoke -CommandName Set-SqlDscTraceFlag -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 1 -and $TraceFlag -contains 3226 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Complete-SqlDscFailoverCluster.Tests.ps1 b/tests/Unit/Public/Complete-SqlDscFailoverCluster.Tests.ps1 index ad020898c..8b97bd3c2 100644 --- a/tests/Unit/Public/Complete-SqlDscFailoverCluster.Tests.ps1 +++ b/tests/Unit/Public/Complete-SqlDscFailoverCluster.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Complete-SqlDscFailoverCluster' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''CompleteFailoverCluster''' { @@ -111,17 +111,14 @@ Describe 'Complete-SqlDscFailoverCluster' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscFailoverCluster -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteFailoverCluster' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteFailoverCluster' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } @@ -129,17 +126,14 @@ Describe 'Complete-SqlDscFailoverCluster' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscFailoverCluster -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteFailoverCluster' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteFailoverCluster' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } @@ -147,7 +141,7 @@ Describe 'Complete-SqlDscFailoverCluster' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscFailoverCluster -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -288,11 +282,6 @@ Describe 'Complete-SqlDscFailoverCluster' -Tag 'Public' { MockParameterValue = 'TESTCLU01A' # cspell: disable-line MockExpectedRegEx = '\/FAILOVERCLUSTERGROUP="TESTCLU01A"' # cspell: disable-line } - @{ - MockParameterName = 'FailoverClusterGroup' - MockParameterValue = 'TESTCLU01A' # cspell: disable-line - MockExpectedRegEx = '\/FAILOVERCLUSTERGROUP="TESTCLU01A"' # cspell: disable-line - } @{ MockParameterName = 'FailoverClusterDisks' # This is the failover cluster resource name. @@ -351,12 +340,9 @@ Describe 'Complete-SqlDscFailoverCluster' -Tag 'Public' { Complete-SqlDscFailoverCluster @completeSqlDscFailoverClusterParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Complete-SqlDscImage.Tests.ps1 b/tests/Unit/Public/Complete-SqlDscImage.Tests.ps1 index 8e7fa4b4b..1faa7bb1c 100644 --- a/tests/Unit/Public/Complete-SqlDscImage.Tests.ps1 +++ b/tests/Unit/Public/Complete-SqlDscImage.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Complete-SqlDscImage' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''CompleteImage''' { @@ -102,12 +102,9 @@ Describe 'Complete-SqlDscImage' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscImage -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteImage' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteImage' + } -Scope It -Times 1 } } @@ -115,12 +112,9 @@ Describe 'Complete-SqlDscImage' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscImage -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=CompleteImage' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=CompleteImage' + } -Scope It -Times 1 } } @@ -128,7 +122,7 @@ Describe 'Complete-SqlDscImage' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscImage -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -151,12 +145,9 @@ Describe 'Complete-SqlDscImage' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Complete-SqlDscImage @completeSqlDscImageParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } @@ -374,12 +365,9 @@ Describe 'Complete-SqlDscImage' -Tag 'Public' { Complete-SqlDscImage @completeSqlDscImageParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Connect-SqlDscDatabaseEngine.Tests.ps1 b/tests/Unit/Public/Connect-SqlDscDatabaseEngine.Tests.ps1 index 2d3a991fd..eeae25559 100644 --- a/tests/Unit/Public/Connect-SqlDscDatabaseEngine.Tests.ps1 +++ b/tests/Unit/Public/Connect-SqlDscDatabaseEngine.Tests.ps1 @@ -78,8 +78,8 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When connecting to an instance' { @@ -103,7 +103,7 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag 'Public' { Connect-SqlDscDatabaseEngine @mockConnectSqlDscDatabaseEngineParameters - Should -Invoke -CommandName Connect-Sql -ParameterFilter { + Should-Invoke -CommandName Connect-Sql -ParameterFilter { $ServerName -eq 'MyServer' -and $InstanceName -eq 'MyInstance' -and $Credential -eq $mockCredentials -and diff --git a/tests/Unit/Public/ConvertFrom-SqlDscDatabasePermission.Tests.ps1 b/tests/Unit/Public/ConvertFrom-SqlDscDatabasePermission.Tests.ps1 index 2957bcb31..9a22dd89c 100644 --- a/tests/Unit/Public/ConvertFrom-SqlDscDatabasePermission.Tests.ps1 +++ b/tests/Unit/Public/ConvertFrom-SqlDscDatabasePermission.Tests.ps1 @@ -65,18 +65,18 @@ Describe 'ConvertFrom-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertFrom-SqlDscDatabasePermission -Permission $mockPermission - $mockResult.Connect | Should -BeTrue - $mockResult.Alter | Should -BeTrue - $mockResult.Update | Should -BeFalse + $mockResult.Connect | Should-BeTrue + $mockResult.Alter | Should-BeTrue + $mockResult.Update | Should-BeFalse } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockPermission | ConvertFrom-SqlDscDatabasePermission - $mockResult.Connect | Should -BeTrue - $mockResult.Alter | Should -BeTrue - $mockResult.Update | Should -BeFalse + $mockResult.Connect | Should-BeTrue + $mockResult.Alter | Should-BeTrue + $mockResult.Update | Should-BeFalse } } } diff --git a/tests/Unit/Public/ConvertFrom-SqlDscServerPermission.Tests.ps1 b/tests/Unit/Public/ConvertFrom-SqlDscServerPermission.Tests.ps1 index 75229edd8..d6412526c 100644 --- a/tests/Unit/Public/ConvertFrom-SqlDscServerPermission.Tests.ps1 +++ b/tests/Unit/Public/ConvertFrom-SqlDscServerPermission.Tests.ps1 @@ -65,18 +65,18 @@ Describe 'ConvertFrom-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertFrom-SqlDscServerPermission -Permission $mockPermission - $mockResult.ConnectSql | Should -BeTrue - $mockResult.AlterAnyAvailabilityGroup | Should -BeTrue - $mockResult.AlterAnyLogin | Should -BeFalse + $mockResult.ConnectSql | Should-BeTrue + $mockResult.AlterAnyAvailabilityGroup | Should-BeTrue + $mockResult.AlterAnyLogin | Should-BeFalse } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockPermission | ConvertFrom-SqlDscServerPermission - $mockResult.ConnectSql | Should -BeTrue - $mockResult.AlterAnyAvailabilityGroup | Should -BeTrue - $mockResult.AlterAnyLogin | Should -BeFalse + $mockResult.ConnectSql | Should-BeTrue + $mockResult.AlterAnyAvailabilityGroup | Should-BeTrue + $mockResult.AlterAnyLogin | Should-BeFalse } } } diff --git a/tests/Unit/Public/ConvertTo-SqlDscDatabasePermission.Tests.ps1 b/tests/Unit/Public/ConvertTo-SqlDscDatabasePermission.Tests.ps1 index 4d773e611..7b9fb25a3 100644 --- a/tests/Unit/Public/ConvertTo-SqlDscDatabasePermission.Tests.ps1 +++ b/tests/Unit/Public/ConvertTo-SqlDscDatabasePermission.Tests.ps1 @@ -58,14 +58,14 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 0 + $mockResult | Should-BeCollection -Count 0 } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 0 + $mockResult | Should-BeCollection -Count 0 } } } @@ -88,20 +88,20 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'Connect' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'Connect' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' } } } @@ -132,22 +132,22 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' } } } @@ -180,26 +180,26 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' - $mockResult[0].Permission | Should -Contain 'Select' - $mockResult[0].Permission | Should -Contain 'Delete' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' + $mockResult[0].Permission | Should-ContainCollection 'Select' + $mockResult[0].Permission | Should-ContainCollection 'Delete' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' - $mockResult[0].Permission | Should -Contain 'Select' - $mockResult[0].Permission | Should -Contain 'Delete' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' + $mockResult[0].Permission | Should-ContainCollection 'Select' + $mockResult[0].Permission | Should-ContainCollection 'Delete' } } } @@ -223,20 +223,20 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'Connect' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'Connect' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'Connect' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'Connect' } } } @@ -267,22 +267,22 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' } } } @@ -315,26 +315,26 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' - $mockResult[0].Permission | Should -Contain 'Select' - $mockResult[0].Permission | Should -Contain 'Delete' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' + $mockResult[0].Permission | Should-ContainCollection 'Select' + $mockResult[0].Permission | Should-ContainCollection 'Delete' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' - $mockResult[0].Permission | Should -Contain 'Select' - $mockResult[0].Permission | Should -Contain 'Delete' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' + $mockResult[0].Permission | Should-ContainCollection 'Select' + $mockResult[0].Permission | Should-ContainCollection 'Delete' } } } @@ -358,20 +358,20 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'Connect' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'Connect' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' } } } @@ -402,22 +402,22 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' } } } @@ -450,26 +450,26 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' - $mockResult[0].Permission | Should -Contain 'Select' - $mockResult[0].Permission | Should -Contain 'Delete' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' + $mockResult[0].Permission | Should-ContainCollection 'Select' + $mockResult[0].Permission | Should-ContainCollection 'Delete' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'Connect' - $mockResult[0].Permission | Should -Contain 'Alter' - $mockResult[0].Permission | Should -Contain 'Select' - $mockResult[0].Permission | Should -Contain 'Delete' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'Connect' + $mockResult[0].Permission | Should-ContainCollection 'Alter' + $mockResult[0].Permission | Should-ContainCollection 'Select' + $mockResult[0].Permission | Should-ContainCollection 'Delete' } } } @@ -514,52 +514,52 @@ Describe 'ConvertTo-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscDatabasePermission -DatabasePermissionInfo $mockDatabasePermissionInfoCollection - $mockResult | Should -HaveCount 3 + $mockResult | Should-BeCollection -Count 3 $grantPermission = $mockResult.Where({ $_.State -eq 'Grant' }) - $grantPermission.State | Should -Be 'Grant' - $grantPermission.Permission | Should -Contain 'Alter' - $grantPermission.Permission | Should -Contain 'Delete' + $grantPermission.State | Should-Be 'Grant' + $grantPermission.Permission | Should-ContainCollection 'Alter' + $grantPermission.Permission | Should-ContainCollection 'Delete' $grantWithGrantPermission = $mockResult.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantPermission.State | Should -Be 'GrantWithGrant' - $grantWithGrantPermission.Permission | Should -Contain 'Connect' - $grantWithGrantPermission.Permission | Should -Contain 'Select' + $grantWithGrantPermission.State | Should-Be 'GrantWithGrant' + $grantWithGrantPermission.Permission | Should-ContainCollection 'Connect' + $grantWithGrantPermission.Permission | Should-ContainCollection 'Select' $denyPermission = $mockResult.Where({ $_.State -eq 'Deny' }) - $denyPermission.State | Should -Be 'Deny' - $denyPermission.Permission | Should -Contain 'Update' - $denyPermission.Permission | Should -Contain 'Insert' + $denyPermission.State | Should-Be 'Deny' + $denyPermission.Permission | Should-ContainCollection 'Update' + $denyPermission.Permission | Should-ContainCollection 'Insert' } Context 'When passing DatabasePermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockDatabasePermissionInfoCollection | ConvertTo-SqlDscDatabasePermission - $mockResult | Should -HaveCount 3 + $mockResult | Should-BeCollection -Count 3 $grantPermission = $mockResult.Where({ $_.State -eq 'Grant' }) - $grantPermission.State | Should -Be 'Grant' - $grantPermission.Permission | Should -Contain 'Alter' - $grantPermission.Permission | Should -Contain 'Delete' + $grantPermission.State | Should-Be 'Grant' + $grantPermission.Permission | Should-ContainCollection 'Alter' + $grantPermission.Permission | Should-ContainCollection 'Delete' $grantWithGrantPermission = $mockResult.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantPermission.State | Should -Be 'GrantWithGrant' - $grantWithGrantPermission.Permission | Should -Contain 'Connect' - $grantWithGrantPermission.Permission | Should -Contain 'Select' + $grantWithGrantPermission.State | Should-Be 'GrantWithGrant' + $grantWithGrantPermission.Permission | Should-ContainCollection 'Connect' + $grantWithGrantPermission.Permission | Should-ContainCollection 'Select' $denyPermission = $mockResult.Where({ $_.State -eq 'Deny' }) - $denyPermission.State | Should -Be 'Deny' - $denyPermission.Permission | Should -Contain 'Update' - $denyPermission.Permission | Should -Contain 'Insert' + $denyPermission.State | Should-Be 'Deny' + $denyPermission.Permission | Should-ContainCollection 'Update' + $denyPermission.Permission | Should-ContainCollection 'Insert' } } } diff --git a/tests/Unit/Public/ConvertTo-SqlDscServerPermission.Tests.ps1 b/tests/Unit/Public/ConvertTo-SqlDscServerPermission.Tests.ps1 index eebfe6136..f7cf680e6 100644 --- a/tests/Unit/Public/ConvertTo-SqlDscServerPermission.Tests.ps1 +++ b/tests/Unit/Public/ConvertTo-SqlDscServerPermission.Tests.ps1 @@ -58,14 +58,14 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 0 + $mockResult | Should-BeCollection -Count 0 } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 0 + $mockResult | Should-BeCollection -Count 0 } } } @@ -88,20 +88,20 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' } } } @@ -132,22 +132,22 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' } } } @@ -180,26 +180,26 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $mockResult[0].Permission | Should -Contain 'ViewServerState' - $mockResult[0].Permission | Should -Contain 'ControlServer' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $mockResult[0].Permission | Should-ContainCollection 'ViewServerState' + $mockResult[0].Permission | Should-ContainCollection 'ControlServer' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Grant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $mockResult[0].Permission | Should -Contain 'ViewServerState' - $mockResult[0].Permission | Should -Contain 'ControlServer' + $mockResult[0].State | Should-Be 'Grant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $mockResult[0].Permission | Should-ContainCollection 'ViewServerState' + $mockResult[0].Permission | Should-ContainCollection 'ControlServer' } } } @@ -223,20 +223,20 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'ConnectSql' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'ConnectSql' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' } } } @@ -267,22 +267,22 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' } } } @@ -315,26 +315,26 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $mockResult[0].Permission | Should -Contain 'ViewServerState' - $mockResult[0].Permission | Should -Contain 'ControlServer' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $mockResult[0].Permission | Should-ContainCollection 'ViewServerState' + $mockResult[0].Permission | Should-ContainCollection 'ControlServer' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'Deny' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $mockResult[0].Permission | Should -Contain 'ViewServerState' - $mockResult[0].Permission | Should -Contain 'ControlServer' + $mockResult[0].State | Should-Be 'Deny' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $mockResult[0].Permission | Should-ContainCollection 'ViewServerState' + $mockResult[0].Permission | Should-ContainCollection 'ControlServer' } } } @@ -358,20 +358,20 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' } } } @@ -402,22 +402,22 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' } } } @@ -450,26 +450,26 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $mockResult[0].Permission | Should -Contain 'ViewServerState' - $mockResult[0].Permission | Should -Contain 'ControlServer' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $mockResult[0].Permission | Should-ContainCollection 'ViewServerState' + $mockResult[0].Permission | Should-ContainCollection 'ControlServer' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 1 + $mockResult | Should-BeCollection -Count 1 - $mockResult[0].State | Should -Be 'GrantWithGrant' - $mockResult[0].Permission | Should -Contain 'ConnectSql' - $mockResult[0].Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $mockResult[0].Permission | Should -Contain 'ViewServerState' - $mockResult[0].Permission | Should -Contain 'ControlServer' + $mockResult[0].State | Should-Be 'GrantWithGrant' + $mockResult[0].Permission | Should-ContainCollection 'ConnectSql' + $mockResult[0].Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $mockResult[0].Permission | Should-ContainCollection 'ViewServerState' + $mockResult[0].Permission | Should-ContainCollection 'ControlServer' } } } @@ -514,52 +514,52 @@ Describe 'ConvertTo-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = ConvertTo-SqlDscServerPermission -ServerPermissionInfo $mockServerPermissionInfoCollection - $mockResult | Should -HaveCount 3 + $mockResult | Should-BeCollection -Count 3 $grantPermission = $mockResult.Where({ $_.State -eq 'Grant' }) - $grantPermission.State | Should -Be 'Grant' - $grantPermission.Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $grantPermission.Permission | Should -Contain 'ControlServer' + $grantPermission.State | Should-Be 'Grant' + $grantPermission.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $grantPermission.Permission | Should-ContainCollection 'ControlServer' $grantWithGrantPermission = $mockResult.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantPermission.State | Should -Be 'GrantWithGrant' - $grantWithGrantPermission.Permission | Should -Contain 'ConnectSql' - $grantWithGrantPermission.Permission | Should -Contain 'ViewServerState' + $grantWithGrantPermission.State | Should-Be 'GrantWithGrant' + $grantWithGrantPermission.Permission | Should-ContainCollection 'ConnectSql' + $grantWithGrantPermission.Permission | Should-ContainCollection 'ViewServerState' $denyPermission = $mockResult.Where({ $_.State -eq 'Deny' }) - $denyPermission.State | Should -Be 'Deny' - $denyPermission.Permission | Should -Contain 'AlterAnyEndpoint' - $denyPermission.Permission | Should -Contain 'CreateEndpoint' + $denyPermission.State | Should-Be 'Deny' + $denyPermission.Permission | Should-ContainCollection 'AlterAnyEndpoint' + $denyPermission.Permission | Should-ContainCollection 'CreateEndpoint' } Context 'When passing ServerPermissionInfo over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerPermissionInfoCollection | ConvertTo-SqlDscServerPermission - $mockResult | Should -HaveCount 3 + $mockResult | Should-BeCollection -Count 3 $grantPermission = $mockResult.Where({ $_.State -eq 'Grant' }) - $grantPermission.State | Should -Be 'Grant' - $grantPermission.Permission | Should -Contain 'AlterAnyAvailabilityGroup' - $grantPermission.Permission | Should -Contain 'ControlServer' + $grantPermission.State | Should-Be 'Grant' + $grantPermission.Permission | Should-ContainCollection 'AlterAnyAvailabilityGroup' + $grantPermission.Permission | Should-ContainCollection 'ControlServer' $grantWithGrantPermission = $mockResult.Where({ $_.State -eq 'GrantWithGrant' }) - $grantWithGrantPermission.State | Should -Be 'GrantWithGrant' - $grantWithGrantPermission.Permission | Should -Contain 'ConnectSql' - $grantWithGrantPermission.Permission | Should -Contain 'ViewServerState' + $grantWithGrantPermission.State | Should-Be 'GrantWithGrant' + $grantWithGrantPermission.Permission | Should-ContainCollection 'ConnectSql' + $grantWithGrantPermission.Permission | Should-ContainCollection 'ViewServerState' $denyPermission = $mockResult.Where({ $_.State -eq 'Deny' }) - $denyPermission.State | Should -Be 'Deny' - $denyPermission.Permission | Should -Contain 'AlterAnyEndpoint' - $denyPermission.Permission | Should -Contain 'CreateEndpoint' + $denyPermission.State | Should-Be 'Deny' + $denyPermission.Permission | Should-ContainCollection 'AlterAnyEndpoint' + $denyPermission.Permission | Should-ContainCollection 'CreateEndpoint' } } } diff --git a/tests/Unit/Public/Disable-SqlDscAudit.Tests.ps1 b/tests/Unit/Public/Disable-SqlDscAudit.Tests.ps1 index 3318bf5ad..54d2329fb 100644 --- a/tests/Unit/Public/Disable-SqlDscAudit.Tests.ps1 +++ b/tests/Unit/Public/Disable-SqlDscAudit.Tests.ps1 @@ -75,8 +75,8 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When enabling an audit by ServerObject' { @@ -108,7 +108,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Disable-SqlDscAudit -Confirm:$false @mockDefaultParameters - $mockMethodDisableCallCount | Should -Be 1 + $mockMethodDisableCallCount | Should-Be 1 } } @@ -116,7 +116,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Disable-SqlDscAudit -Force @mockDefaultParameters - $mockMethodDisableCallCount | Should -Be 1 + $mockMethodDisableCallCount | Should-Be 1 } } @@ -124,7 +124,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Disable-SqlDscAudit -WhatIf @mockDefaultParameters - $mockMethodDisableCallCount | Should -Be 0 + $mockMethodDisableCallCount | Should-Be 0 } } @@ -132,7 +132,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $mockServerObject | Disable-SqlDscAudit -Name 'Log1' -Force - $mockMethodDisableCallCount | Should -Be 1 + $mockMethodDisableCallCount | Should-Be 1 } } } @@ -163,7 +163,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Disable-SqlDscAudit -Confirm:$false @mockDefaultParameters - $mockMethodDisableCallCount | Should -Be 1 + $mockMethodDisableCallCount | Should-Be 1 } } @@ -171,7 +171,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Disable-SqlDscAudit -Force @mockDefaultParameters - $mockMethodDisableCallCount | Should -Be 1 + $mockMethodDisableCallCount | Should-Be 1 } } @@ -179,7 +179,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Disable-SqlDscAudit -WhatIf @mockDefaultParameters - $mockMethodDisableCallCount | Should -Be 0 + $mockMethodDisableCallCount | Should-Be 0 } } @@ -187,7 +187,7 @@ Describe 'Disable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $mockAuditObject | Disable-SqlDscAudit -Force - $mockMethodDisableCallCount | Should -Be 1 + $mockMethodDisableCallCount | Should-Be 1 } } } diff --git a/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 b/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 index bdaf26542..8cf67a09b 100644 --- a/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 +++ b/tests/Unit/Public/Disconnect-SqlDscDatabaseEngine.Tests.ps1 @@ -73,8 +73,8 @@ Describe 'Disconnect-SqlDscDatabaseEngine' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When disconnecting using a server object' { @@ -96,33 +96,33 @@ 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 + $mockMethodDisconnectCallCount | Should-Be 1 } } 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 + $mockMethodDisconnectCallCount | Should-Be 1 } } 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 + $mockMethodDisconnectCallCount | Should-Be 0 } } 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 + $mockMethodDisconnectCallCount | Should-Be 1 } } } diff --git a/tests/Unit/Public/Enable-SqlDscAudit.Tests.ps1 b/tests/Unit/Public/Enable-SqlDscAudit.Tests.ps1 index 68f38d191..4185c9668 100644 --- a/tests/Unit/Public/Enable-SqlDscAudit.Tests.ps1 +++ b/tests/Unit/Public/Enable-SqlDscAudit.Tests.ps1 @@ -75,8 +75,8 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When enabling an audit by ServerObject' { @@ -108,7 +108,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Enable-SqlDscAudit -Confirm:$false @mockDefaultParameters - $mockMethodEnableCallCount | Should -Be 1 + $mockMethodEnableCallCount | Should-Be 1 } } @@ -116,7 +116,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Enable-SqlDscAudit -Force @mockDefaultParameters - $mockMethodEnableCallCount | Should -Be 1 + $mockMethodEnableCallCount | Should-Be 1 } } @@ -124,7 +124,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Enable-SqlDscAudit -WhatIf @mockDefaultParameters - $mockMethodEnableCallCount | Should -Be 0 + $mockMethodEnableCallCount | Should-Be 0 } } @@ -132,7 +132,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $mockServerObject | Enable-SqlDscAudit -Name 'Log1' -Force - $mockMethodEnableCallCount | Should -Be 1 + $mockMethodEnableCallCount | Should-Be 1 } } } @@ -163,7 +163,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Enable-SqlDscAudit -Confirm:$false @mockDefaultParameters - $mockMethodEnableCallCount | Should -Be 1 + $mockMethodEnableCallCount | Should-Be 1 } } @@ -171,7 +171,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Enable-SqlDscAudit -Force @mockDefaultParameters - $mockMethodEnableCallCount | Should -Be 1 + $mockMethodEnableCallCount | Should-Be 1 } } @@ -179,7 +179,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Enable-SqlDscAudit -WhatIf @mockDefaultParameters - $mockMethodEnableCallCount | Should -Be 0 + $mockMethodEnableCallCount | Should-Be 0 } } @@ -187,7 +187,7 @@ Describe 'Enable-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $mockAuditObject | Enable-SqlDscAudit -Force - $mockMethodEnableCallCount | Should -Be 1 + $mockMethodEnableCallCount | Should-Be 1 } } } diff --git a/tests/Unit/Public/Get-SqlDscAudit.Tests.ps1 b/tests/Unit/Public/Get-SqlDscAudit.Tests.ps1 index de5d5cab6..9b6f1fef0 100644 --- a/tests/Unit/Public/Get-SqlDscAudit.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscAudit.Tests.ps1 @@ -71,8 +71,8 @@ Describe 'Get-SqlDscAudit' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When no audit exist' { @@ -97,14 +97,14 @@ Describe 'Get-SqlDscAudit' -Tag 'Public' { It 'Should throw the correct error' { { Get-SqlDscAudit @mockDefaultParameters -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'Log1') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'Log1') } } Context 'When ignoring the error' { It 'Should not throw an exception and return $null' { Get-SqlDscAudit @mockDefaultParameters -ErrorAction 'SilentlyContinue' | - Should -BeNullOrEmpty + Should-BeFalsy } } } @@ -133,16 +133,16 @@ Describe 'Get-SqlDscAudit' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscAudit @mockDefaultParameters - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' - $result.Name | Should -Be 'Log1' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Audit' + $result.Name | Should-Be 'Log1' } Context 'When passing parameter ServerObject over the pipeline' { It 'Should return the correct values' { $result = $mockServerObject | Get-SqlDscAudit -Name 'Log1' - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' - $result.Name | Should -Be 'Log1' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Audit' + $result.Name | Should-Be 'Log1' } } } @@ -178,10 +178,10 @@ Describe 'Get-SqlDscAudit' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscAudit @mockDefaultParameters - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.Audit' - $result | Should -HaveCount 2 - $result.Name | Should -Contain 'Log1' - $result.Name | Should -Contain 'Log2' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.Audit' + $result | Should-BeCollection -Count 2 + $result.Name | Should-ContainCollection 'Log1' + $result.Name | Should-ContainCollection 'Log2' } } } diff --git a/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 b/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 index c8f278a09..8476e9652 100644 --- a/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1 @@ -71,8 +71,8 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When the specified configuration option exist' { @@ -99,14 +99,14 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { It 'Should throw the correct error' { { Get-SqlDscConfigurationOption @mockDefaultParameters -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'Unknown Option Name') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'Unknown Option Name') } } Context 'When ignoring the error' { It 'Should not throw an exception and return $null' { Get-SqlDscConfigurationOption @mockDefaultParameters -ErrorAction 'SilentlyContinue' | - Should -BeNullOrEmpty + Should-BeFalsy } } } @@ -132,18 +132,18 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { $result = Get-SqlDscConfigurationOption @mockDefaultParameters - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' - $result.DisplayName | Should -Be 'blocked process threshold (s)' + $result.DisplayName | Should-Be 'blocked process threshold (s)' } Context 'When passing parameter ServerObject over the pipeline' { It 'Should return the correct values' { $result = $mockServerObject | Get-SqlDscConfigurationOption -Name 'blocked process threshold (s)' - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' - $result.DisplayName | Should -Be 'blocked process threshold (s)' + $result.DisplayName | Should-Be 'blocked process threshold (s)' } } } @@ -167,20 +167,20 @@ Describe 'Get-SqlDscConfigurationOption' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscConfigurationOption -ServerObject $mockServerObject - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' - $result.DisplayName | Should -Contain 'show advanced options' - $result.DisplayName | Should -Contain 'blocked process threshold (s)' + $result.DisplayName | Should-ContainCollection 'show advanced options' + $result.DisplayName | Should-ContainCollection 'blocked process threshold (s)' } Context 'When passing parameter ServerObject over the pipeline' { It 'Should return the correct values' { $result = $mockServerObject | Get-SqlDscConfigurationOption - $result | Should -BeOfType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' + $result | Should-HaveType 'Microsoft.SqlServer.Management.Smo.ConfigProperty' - $result.DisplayName | Should -Contain 'show advanced options' - $result.DisplayName | Should -Contain 'blocked process threshold (s)' + $result.DisplayName | Should-ContainCollection 'show advanced options' + $result.DisplayName | Should-ContainCollection 'blocked process threshold (s)' } } } diff --git a/tests/Unit/Public/Get-SqlDscDatabasePermission.Tests.ps1 b/tests/Unit/Public/Get-SqlDscDatabasePermission.Tests.ps1 index ec26efd86..54999ab88 100644 --- a/tests/Unit/Public/Get-SqlDscDatabasePermission.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscDatabasePermission.Tests.ps1 @@ -67,14 +67,14 @@ Describe 'Get-SqlDscDatabasePermission' -Tag 'Public' { It 'Should throw the correct error' { { Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'MissingDatabase' -Name 'KnownUser' -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'MissingDatabase') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'MissingDatabase') } } Context 'When ignoring the error' { It 'Should not throw an exception and return $null' { Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'MissingDatabase' -Name 'KnownUser' -ErrorAction 'SilentlyContinue' | - Should -BeNullOrEmpty + Should-BeFalsy } } } @@ -99,14 +99,14 @@ Describe 'Get-SqlDscDatabasePermission' -Tag 'Public' { It 'Should throw the correct error' { { Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'MissingDatabase' -Name 'KnownUser' -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'MissingDatabase') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'MissingDatabase') } } Context 'When ignoring the error' { It 'Should not throw an exception and return $null' { Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'MissingDatabase' -Name 'KnownUser' -ErrorAction 'SilentlyContinue' | - Should -BeNullOrEmpty + Should-BeFalsy } } } @@ -135,14 +135,14 @@ Describe 'Get-SqlDscDatabasePermission' -Tag 'Public' { It 'Should throw the correct error' { { Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'UnknownUser' -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'UnknownUser', 'AdventureWorks') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'UnknownUser', 'AdventureWorks') } } Context 'When ignoring the error' { It 'Should not throw an exception and return $null' { Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'UnknownUser' -ErrorAction 'SilentlyContinue' | - Should -BeNullOrEmpty + Should-BeFalsy } } } @@ -199,30 +199,30 @@ Describe 'Get-SqlDscDatabasePermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = Get-SqlDscDatabasePermission -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'Zebes\SamusAran' -ErrorAction 'Stop' - $mockResult | Should -HaveCount 2 + $mockResult | Should-BeCollection -Count 2 - $mockResult[0].PermissionState | Should -Be 'Grant' - $mockResult[0].PermissionType.Connect | Should -BeTrue - $mockResult[0].PermissionType.Update | Should -BeFalse + $mockResult[0].PermissionState | Should-Be 'Grant' + $mockResult[0].PermissionType.Connect | Should-BeTrue + $mockResult[0].PermissionType.Update | Should-BeFalse - $mockResult[1].PermissionState | Should -Be 'Grant' - $mockResult[1].PermissionType.Connect | Should -BeFalse - $mockResult[1].PermissionType.Update | Should -BeTrue + $mockResult[1].PermissionState | Should-Be 'Grant' + $mockResult[1].PermissionType.Connect | Should-BeFalse + $mockResult[1].PermissionType.Update | Should-BeTrue } Context 'When passing ServerObject over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerObject | Get-SqlDscDatabasePermission -DatabaseName 'AdventureWorks' -Name 'Zebes\SamusAran' -ErrorAction 'Stop' - $mockResult | Should -HaveCount 2 + $mockResult | Should-BeCollection -Count 2 - $mockResult[0].PermissionState | Should -Be 'Grant' - $mockResult[0].PermissionType.Connect | Should -BeTrue - $mockResult[0].PermissionType.Update | Should -BeFalse + $mockResult[0].PermissionState | Should-Be 'Grant' + $mockResult[0].PermissionType.Connect | Should-BeTrue + $mockResult[0].PermissionType.Update | Should-BeFalse - $mockResult[1].PermissionState | Should -Be 'Grant' - $mockResult[1].PermissionType.Connect | Should -BeFalse - $mockResult[1].PermissionType.Update | Should -BeTrue + $mockResult[1].PermissionState | Should-Be 'Grant' + $mockResult[1].PermissionType.Connect | Should-BeFalse + $mockResult[1].PermissionType.Update | Should-BeTrue } } } diff --git a/tests/Unit/Public/Get-SqlDscManagedComputer.Tests.ps1 b/tests/Unit/Public/Get-SqlDscManagedComputer.Tests.ps1 index 237b18684..ba556fab2 100644 --- a/tests/Unit/Public/Get-SqlDscManagedComputer.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscManagedComputer.Tests.ps1 @@ -62,9 +62,9 @@ Describe 'Get-SqlDscManagedComputer' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscManagedComputer - $result | Should -Be 'MockManagedComputer' + $result | Should-Be 'MockManagedComputer' - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 } } @@ -81,9 +81,9 @@ Describe 'Get-SqlDscManagedComputer' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscManagedComputer -ServerName 'localhost' - $result | Should -Be 'MockManagedComputer' + $result | Should-Be 'MockManagedComputer' - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It + Should-Invoke -CommandName New-Object -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Get-SqlDscManagedComputerService.Tests.ps1 b/tests/Unit/Public/Get-SqlDscManagedComputerService.Tests.ps1 index 0bd82579a..206981e6d 100644 --- a/tests/Unit/Public/Get-SqlDscManagedComputerService.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscManagedComputerService.Tests.ps1 @@ -76,12 +76,12 @@ Describe 'Get-SqlDscManagedComputerService' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscManagedComputerService - $result | Should -HaveCount 3 - $result.Name | Should -Contain 'MSSQL$SQL2022' - $result.Name | Should -Contain 'SQLBrowser' - $result.Name | Should -Contain 'MSSQLSERVER' + $result | Should-BeCollection -Count 3 + $result.Name | Should-ContainCollection 'MSSQL$SQL2022' + $result.Name | Should-ContainCollection 'SQLBrowser' + $result.Name | Should-ContainCollection 'MSSQLSERVER' - Should -Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Scope It -Times 1 } } @@ -89,12 +89,12 @@ Describe 'Get-SqlDscManagedComputerService' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscManagedComputerService -ServerName 'localhost' - $result | Should -HaveCount 3 - $result.Name | Should -Contain 'MSSQL$SQL2022' - $result.Name | Should -Contain 'SQLBrowser' - $result.Name | Should -Contain 'MSSQLSERVER' + $result | Should-BeCollection -Count 3 + $result.Name | Should-ContainCollection 'MSSQL$SQL2022' + $result.Name | Should-ContainCollection 'SQLBrowser' + $result.Name | Should-ContainCollection 'MSSQLSERVER' - Should -Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Scope It -Times 1 } Context 'When passing parameter ManagedComputerObject over the pipeline' { @@ -132,12 +132,12 @@ Describe 'Get-SqlDscManagedComputerService' -Tag 'Public' { $managedComputerObject2 ) | Get-SqlDscManagedComputerService - $result | Should -HaveCount 3 - $result.Name | Should -Contain 'MSSQL$SQL2022' - $result.Name | Should -Contain 'SQLBrowser' - $result.Name | Should -Contain 'MSSQLSERVER' + $result | Should-BeCollection -Count 3 + $result.Name | Should-ContainCollection 'MSSQL$SQL2022' + $result.Name | Should-ContainCollection 'SQLBrowser' + $result.Name | Should-ContainCollection 'MSSQLSERVER' - Should -Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Scope It -Times 0 } } } @@ -146,11 +146,11 @@ Describe 'Get-SqlDscManagedComputerService' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscManagedComputerService -ServiceType 'DatabaseEngine' - $result | Should -HaveCount 2 - $result.Name | Should -Contain 'MSSQL$SQL2022' - $result.Name | Should -Contain 'MSSQLSERVER' + $result | Should-BeCollection -Count 2 + $result.Name | Should-ContainCollection 'MSSQL$SQL2022' + $result.Name | Should-ContainCollection 'MSSQLSERVER' - Should -Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Scope It -Times 1 } } @@ -158,10 +158,10 @@ Describe 'Get-SqlDscManagedComputerService' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscManagedComputerService -InstanceName 'SQL2022' - $result | Should -HaveCount 1 - $result.Name | Should -Contain 'MSSQL$SQL2022' + $result | Should-BeCollection -Count 1 + $result.Name | Should-ContainCollection 'MSSQL$SQL2022' - Should -Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputer -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1 b/tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1 index 37f82480a..73371b358 100644 --- a/tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When no parameters are specified' { @@ -82,9 +82,9 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return $null' { - Get-SqlDscPreferredModule -ErrorAction 'SilentlyContinue' -ErrorVariable mockError | Should -BeNullOrEmpty + Get-SqlDscPreferredModule -ErrorAction 'SilentlyContinue' -ErrorVariable mockError | Should-BeFalsy - $mockError | Should -HaveCount 1 + $mockError | Should-BeCollection -Count 1 } } @@ -94,9 +94,9 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return $null' { - Get-SqlDscPreferredModule -ErrorAction 'Ignore' -ErrorVariable mockError | Should -BeNullOrEmpty + Get-SqlDscPreferredModule -ErrorAction 'Ignore' -ErrorVariable mockError | Should-BeFalsy - $mockError | Should -BeNullOrEmpty + $mockError | Should-BeFalsy } } @@ -110,7 +110,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { $script:localizedData.PreferredModule_ModuleNotFound } - { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage $errorMessage + { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage $errorMessage } } } @@ -128,7 +128,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module' { - Get-SqlDscPreferredModule | Should -Be $sqlServerModule + Get-SqlDscPreferredModule | Should-Be $sqlServerModule } } @@ -145,7 +145,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module name' { - Get-SqlDscPreferredModule | Should -Be $sqlpsModule + Get-SqlDscPreferredModule | Should-Be $sqlpsModule } } @@ -169,7 +169,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module name' { - Get-SqlDscPreferredModule | Should -Be $sqlServerModule + Get-SqlDscPreferredModule | Should-Be $sqlServerModule } } @@ -203,7 +203,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the latest version of the first default preferred module' { - Get-SqlDscPreferredModule | Should -Be $sqlServerModule2 + Get-SqlDscPreferredModule | Should-Be $sqlServerModule2 } } @@ -227,7 +227,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the latest version of the first default preferred module' { - Get-SqlDscPreferredModule | Should -Be $sqlServerModule2 + Get-SqlDscPreferredModule | Should-Be $sqlServerModule2 } } @@ -251,7 +251,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the latest version of the second default preferred module' { - Get-SqlDscPreferredModule | Should -Be $sqlpsModule2 + Get-SqlDscPreferredModule | Should-Be $sqlpsModule2 } } } @@ -264,9 +264,9 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return $null' { - Get-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'SilentlyContinue' -ErrorVariable mockError | Should -BeNullOrEmpty + Get-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'SilentlyContinue' -ErrorVariable mockError | Should-BeFalsy - $mockError | Should -HaveCount 1 + $mockError | Should-BeCollection -Count 1 } } @@ -276,9 +276,9 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return $null' { - Get-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'Ignore' -ErrorVariable mockError | Should -BeNullOrEmpty + Get-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'Ignore' -ErrorVariable mockError | Should-BeFalsy - $mockError | Should -BeNullOrEmpty + $mockError | Should-BeFalsy } } @@ -292,7 +292,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { $script:localizedData.PreferredModule_ModuleNotFound } - { Get-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage $errorMessage + { Get-SqlDscPreferredModule -Name 'SqlServer' -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage $errorMessage } } } @@ -309,7 +309,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module name' { - Get-SqlDscPreferredModule -Name 'SqlServer' | Should -Be $sqlServerModule + Get-SqlDscPreferredModule -Name 'SqlServer' | Should-Be $sqlServerModule } } @@ -325,7 +325,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module name' { - Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlpsModule + Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should-Be $sqlpsModule } } @@ -349,7 +349,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the first preferred module' { - Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule + Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should-Be $sqlServerModule } } @@ -398,7 +398,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the latest first preferred module' { - Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule3 + Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should-Be $sqlServerModule3 } Context 'When the environment variable SMODefaultModuleVersion is assigned a module version' { @@ -412,7 +412,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the specified module version' { - Get-SqlDscPreferredModule | Should -Be $sqlServerModule1 + Get-SqlDscPreferredModule | Should-Be $sqlServerModule1 } } @@ -430,7 +430,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { $script:localizedData.PreferredModule_ModuleVersionNotFound } - { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage ($errorMessage -f $env:SMODefaultModuleVersion) + { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage ($errorMessage -f $env:SMODefaultModuleVersion) } } } @@ -456,7 +456,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the latest version of the first preferred module' { - Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlServerModule2 + Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should-Be $sqlServerModule2 } Context 'When the environment variable SMODefaultModuleVersion is assigned a module version' { @@ -470,7 +470,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the specified module version' { - Get-SqlDscPreferredModule | Should -Be $sqlServerModule1 + Get-SqlDscPreferredModule | Should-Be $sqlServerModule1 } } @@ -488,7 +488,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { $script:localizedData.PreferredModule_ModuleVersionNotFound } - { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage ($errorMessage -f $env:SMODefaultModuleVersion) + { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage ($errorMessage -f $env:SMODefaultModuleVersion) } } } @@ -514,7 +514,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the latest version of the second preferred module' { - Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should -Be $sqlpsModule2 + Get-SqlDscPreferredModule -Name @('SqlServer', 'SQLPS') | Should-Be $sqlpsModule2 } Context 'When the environment variable SMODefaultModuleVersion is assigned a module version' { @@ -528,7 +528,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the specified module version' { - Get-SqlDscPreferredModule | Should -Be $sqlpsModule1 + Get-SqlDscPreferredModule | Should-Be $sqlpsModule1 } } @@ -546,7 +546,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { $script:localizedData.PreferredModule_ModuleVersionNotFound } - { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage ($errorMessage -f $env:SMODefaultModuleVersion) + { Get-SqlDscPreferredModule -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage ($errorMessage -f $env:SMODefaultModuleVersion) } } } @@ -576,9 +576,9 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module name' { - Get-SqlDscPreferredModule -Refresh | Should -Be $sqlServerModule + Get-SqlDscPreferredModule -Refresh | Should-Be $sqlServerModule - Should -Invoke -CommandName Set-PSModulePath -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Set-PSModulePath -Exactly -Scope It -Times 1 } } @@ -601,7 +601,7 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' { } It 'Should return the correct module name' { - Get-SqlDscPreferredModule | Should -Be $otherModule + Get-SqlDscPreferredModule | Should-Be $otherModule } } } diff --git a/tests/Unit/Public/Get-SqlDscServerPermission.Tests.ps1 b/tests/Unit/Public/Get-SqlDscServerPermission.Tests.ps1 index 9bd485449..1317822ba 100644 --- a/tests/Unit/Public/Get-SqlDscServerPermission.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscServerPermission.Tests.ps1 @@ -69,14 +69,14 @@ Describe 'Get-SqlDscServerPermission' -Tag 'Public' { It 'Should throw the correct error' { { Get-SqlDscServerPermission -ServerObject $mockServerObject -Name 'UnknownUser' -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'UnknownUser', 'MockInstance') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'UnknownUser', 'MockInstance') } } Context 'When ignoring the error' { It 'Should not throw an exception and return $null' { Get-SqlDscServerPermission -ServerObject $mockServerObject -Name 'UnknownUser' -ErrorAction 'SilentlyContinue' | - Should -BeNullOrEmpty + Should-BeFalsy } } } @@ -119,30 +119,30 @@ Describe 'Get-SqlDscServerPermission' -Tag 'Public' { It 'Should return the correct values' { $mockResult = Get-SqlDscServerPermission -ServerObject $mockServerObject -Name 'Zebes\SamusAran' -ErrorAction 'Stop' - $mockResult | Should -HaveCount 2 + $mockResult | Should-BeCollection -Count 2 - $mockResult[0].PermissionState | Should -Be 'Grant' - $mockResult[0].PermissionType.ConnectSql | Should -BeTrue - $mockResult[0].PermissionType.AlterAnyAvailabilityGroup | Should -BeFalse + $mockResult[0].PermissionState | Should-Be 'Grant' + $mockResult[0].PermissionType.ConnectSql | Should-BeTrue + $mockResult[0].PermissionType.AlterAnyAvailabilityGroup | Should-BeFalse - $mockResult[1].PermissionState | Should -Be 'Grant' - $mockResult[1].PermissionType.ConnectSql | Should -BeFalse - $mockResult[1].PermissionType.AlterAnyAvailabilityGroup | Should -BeTrue + $mockResult[1].PermissionState | Should-Be 'Grant' + $mockResult[1].PermissionType.ConnectSql | Should-BeFalse + $mockResult[1].PermissionType.AlterAnyAvailabilityGroup | Should-BeTrue } Context 'When passing ServerObject over the pipeline' { It 'Should return the correct values' { $mockResult = $mockServerObject | Get-SqlDscServerPermission -Name 'Zebes\SamusAran' -ErrorAction 'Stop' - $mockResult | Should -HaveCount 2 + $mockResult | Should-BeCollection -Count 2 - $mockResult[0].PermissionState | Should -Be 'Grant' - $mockResult[0].PermissionType.ConnectSql | Should -BeTrue - $mockResult[0].PermissionType.AlterAnyAvailabilityGroup | Should -BeFalse + $mockResult[0].PermissionState | Should-Be 'Grant' + $mockResult[0].PermissionType.ConnectSql | Should-BeTrue + $mockResult[0].PermissionType.AlterAnyAvailabilityGroup | Should-BeFalse - $mockResult[1].PermissionState | Should -Be 'Grant' - $mockResult[1].PermissionType.ConnectSql | Should -BeFalse - $mockResult[1].PermissionType.AlterAnyAvailabilityGroup | Should -BeTrue + $mockResult[1].PermissionState | Should-Be 'Grant' + $mockResult[1].PermissionType.ConnectSql | Should-BeFalse + $mockResult[1].PermissionType.AlterAnyAvailabilityGroup | Should-BeTrue } } } diff --git a/tests/Unit/Public/Get-SqlDscStartupParameter.Tests.ps1 b/tests/Unit/Public/Get-SqlDscStartupParameter.Tests.ps1 index 673ad0e08..3b0372722 100644 --- a/tests/Unit/Public/Get-SqlDscStartupParameter.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscStartupParameter.Tests.ps1 @@ -75,15 +75,15 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When passing $null as ServiceObject' { It 'Should throw the correct error' { $mockErrorMessage = 'Cannot bind argument to parameter ''ServiceObject'' because it is null.' - { Get-SqlDscStartupParameter -ServiceObject $null } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-SqlDscStartupParameter -ServiceObject $null } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -104,7 +104,7 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { $mockErrorMessage = $mockErrorMessage -f 'SqlServer', 'SqlAgent' { Get-SqlDscStartupParameter -ServiceObject $mockServiceObject -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage $mockErrorMessage + Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -117,7 +117,7 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { $mockErrorMessage = $mockErrorMessage -f 'SqlServer', 'SqlAgent' { Get-SqlDscStartupParameter -ServiceObject $mockServiceObject -ErrorAction 'SilentlyContinue' } | - Should -Throw -ExpectedMessage $mockErrorMessage + Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -135,9 +135,9 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { It 'Should not throw and return an empty array' { $result = Get-SqlDscStartupParameter -ServerName 'localhost' -ErrorAction 'SilentlyContinue' - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Scope It -Times 1 } } @@ -147,9 +147,9 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { $script:localizedData.TraceFlag_Get_FailedToFindServiceObject } - { Get-SqlDscStartupParameter -ServerName 'localhost' -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-SqlDscStartupParameter -ServerName 'localhost' -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Scope It -Times 1 } } } @@ -173,19 +173,19 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscStartupParameter - Should -ActualValue $result -BeOfType (InModuleScope -ScriptBlock { [StartupParameters] }) + Should-HaveType (InModuleScope -ScriptBlock { [StartupParameters] }) -Actual $result - Should -ActualValue $result.TraceFlag -BeOfType 'System.UInt32[]' - Should -ActualValue $result.DataFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.LogFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.ErrorLogPath -BeOfType 'System.String[]' + Should-HaveType 'System.UInt32[]' -Actual $result.TraceFlag + Should-HaveType 'System.String[]' -Actual $result.DataFilePath + Should-HaveType 'System.String[]' -Actual $result.LogFilePath + Should-HaveType 'System.String[]' -Actual $result.ErrorLogPath - $result.DataFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' - $result.LogFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' - $result.ErrorLogPath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' - $result.TraceFlag | Should -BeNullOrEmpty + $result.DataFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' + $result.LogFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' + $result.ErrorLogPath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' + $result.TraceFlag | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Scope It -Times 1 } } @@ -193,21 +193,21 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscStartupParameter -ServerName 'localhost' - Should -ActualValue $result -BeOfType (InModuleScope -ScriptBlock { [StartupParameters] }) + Should-HaveType (InModuleScope -ScriptBlock { [StartupParameters] }) -Actual $result - Should -ActualValue $result.TraceFlag -BeOfType 'System.UInt32[]' - Should -ActualValue $result.DataFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.LogFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.ErrorLogPath -BeOfType 'System.String[]' + Should-HaveType 'System.UInt32[]' -Actual $result.TraceFlag + Should-HaveType 'System.String[]' -Actual $result.DataFilePath + Should-HaveType 'System.String[]' -Actual $result.LogFilePath + Should-HaveType 'System.String[]' -Actual $result.ErrorLogPath - $result.DataFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' - $result.LogFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' - $result.ErrorLogPath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' - $result.TraceFlag | Should -BeNullOrEmpty + $result.DataFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' + $result.LogFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' + $result.ErrorLogPath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' + $result.TraceFlag | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscManagedComputerService -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -ParameterFilter { $ServerName -eq 'localhost' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -215,21 +215,21 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscStartupParameter -InstanceName 'SQL2022' - Should -ActualValue $result -BeOfType (InModuleScope -ScriptBlock { [StartupParameters] }) + Should-HaveType (InModuleScope -ScriptBlock { [StartupParameters] }) -Actual $result - Should -ActualValue $result.TraceFlag -BeOfType 'System.UInt32[]' - Should -ActualValue $result.DataFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.LogFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.ErrorLogPath -BeOfType 'System.String[]' + Should-HaveType 'System.UInt32[]' -Actual $result.TraceFlag + Should-HaveType 'System.String[]' -Actual $result.DataFilePath + Should-HaveType 'System.String[]' -Actual $result.LogFilePath + Should-HaveType 'System.String[]' -Actual $result.ErrorLogPath - $result.DataFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' - $result.LogFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' - $result.ErrorLogPath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' - $result.TraceFlag | Should -BeNullOrEmpty + $result.DataFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' + $result.LogFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' + $result.ErrorLogPath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' + $result.TraceFlag | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscManagedComputerService -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -ParameterFilter { $InstanceName -eq 'SQL2022' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -237,19 +237,19 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscStartupParameter -ServiceObject $mockServiceObject - Should -ActualValue $result -BeOfType (InModuleScope -ScriptBlock { [StartupParameters] }) + Should-HaveType (InModuleScope -ScriptBlock { [StartupParameters] }) -Actual $result - Should -ActualValue $result.TraceFlag -BeOfType 'System.UInt32[]' - Should -ActualValue $result.DataFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.LogFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.ErrorLogPath -BeOfType 'System.String[]' + Should-HaveType 'System.UInt32[]' -Actual $result.TraceFlag + Should-HaveType 'System.String[]' -Actual $result.DataFilePath + Should-HaveType 'System.String[]' -Actual $result.LogFilePath + Should-HaveType 'System.String[]' -Actual $result.ErrorLogPath - $result.DataFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' - $result.LogFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' - $result.ErrorLogPath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' - $result.TraceFlag | Should -BeNullOrEmpty + $result.DataFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' + $result.LogFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' + $result.ErrorLogPath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' + $result.TraceFlag | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Scope It -Times 0 } } } @@ -268,18 +268,18 @@ Describe 'Get-SqlDscStartupParameter' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscStartupParameter -ServiceObject $mockServiceObject - Should -ActualValue $result -BeOfType (InModuleScope -ScriptBlock { [StartupParameters] }) + Should-HaveType (InModuleScope -ScriptBlock { [StartupParameters] }) -Actual $result - Should -ActualValue $result.TraceFlag -BeOfType 'System.UInt32[]' - Should -ActualValue $result.DataFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.LogFilePath -BeOfType 'System.String[]' - Should -ActualValue $result.ErrorLogPath -BeOfType 'System.String[]' + Should-HaveType 'System.UInt32[]' -Actual $result.TraceFlag + Should-HaveType 'System.String[]' -Actual $result.DataFilePath + Should-HaveType 'System.String[]' -Actual $result.LogFilePath + Should-HaveType 'System.String[]' -Actual $result.ErrorLogPath - $result.DataFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' - $result.LogFilePath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' - $result.ErrorLogPath | Should -Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' - $result.TraceFlag | Should -HaveCount 1 - $result.TraceFlag | Should -Contain 4199 + $result.DataFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\master.mdf' + $result.LogFilePath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\DATA\log.ldf' + $result.ErrorLogPath | Should-Be 'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Log\ERRORLOG' + $result.TraceFlag | Should-BeCollection -Count 1 + $result.TraceFlag | Should-ContainCollection 4199 } } } diff --git a/tests/Unit/Public/Get-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Get-SqlDscTraceFlag.Tests.ps1 index 41b0fe7bd..fb84dd665 100644 --- a/tests/Unit/Public/Get-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Get-SqlDscTraceFlag.Tests.ps1 @@ -75,15 +75,15 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When passing $null as ServiceObject' { It 'Should throw the correct error' { $mockErrorMessage = 'Cannot bind argument to parameter ''ServiceObject'' because it is null.' - { Get-SqlDscTraceFlag -ServiceObject $null } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-SqlDscTraceFlag -ServiceObject $null } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -100,11 +100,11 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscTraceFlag - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Scope It -Times 1 } } @@ -112,13 +112,13 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscTraceFlag -ServerName 'localhost' - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -ParameterFilter { $ServerName -eq 'localhost' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -126,13 +126,13 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return an empty array' { $result = Get-SqlDscTraceFlag -InstanceName 'SQL2022' - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -ParameterFilter { $InstanceName -eq 'SQL2022' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -146,11 +146,11 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { $result = Get-SqlDscTraceFlag -ServiceObject $mockServiceObject - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Scope It -Times 1 } } } @@ -168,12 +168,12 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscTraceFlag - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 1 - $result | Should -Contain 4199 + $result | Should-BeCollection -Count 1 + $result | Should-ContainCollection 4199 - Should -Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Scope It -Times 1 } } @@ -181,14 +181,14 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscTraceFlag -ServerName 'localhost' - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 1 - $result | Should -Contain 4199 + $result | Should-BeCollection -Count 1 + $result | Should-ContainCollection 4199 - Should -Invoke -CommandName Get-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -ParameterFilter { $ServerName -eq 'localhost' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -196,14 +196,14 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscTraceFlag -InstanceName 'SQL2022' - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 1 - $result | Should -Contain 4199 + $result | Should-BeCollection -Count 1 + $result | Should-ContainCollection 4199 - Should -Invoke -CommandName Get-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -ParameterFilter { $InstanceName -eq 'SQL2022' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -217,12 +217,12 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { $result = Get-SqlDscTraceFlag -ServiceObject $mockServiceObject - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 1 - $result | Should -Contain 4199 + $result | Should-BeCollection -Count 1 + $result | Should-ContainCollection 4199 - Should -Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Scope It -Times 1 } } } @@ -240,13 +240,13 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscTraceFlag - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 2 - $result | Should -Contain 4199 - $result | Should -Contain 3226 + $result | Should-BeCollection -Count 2 + $result | Should-ContainCollection 4199 + $result | Should-ContainCollection 3226 - Should -Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Scope It -Times 1 } } @@ -254,15 +254,15 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscTraceFlag -ServerName 'localhost' - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 2 - $result | Should -Contain 4199 - $result | Should -Contain 3226 + $result | Should-BeCollection -Count 2 + $result | Should-ContainCollection 4199 + $result | Should-ContainCollection 3226 - Should -Invoke -CommandName Get-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -ParameterFilter { $ServerName -eq 'localhost' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -270,15 +270,15 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { It 'Should return the correct values' { $result = Get-SqlDscTraceFlag -InstanceName 'SQL2022' - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 2 - $result | Should -Contain 4199 - $result | Should -Contain 3226 + $result | Should-BeCollection -Count 2 + $result | Should-ContainCollection 4199 + $result | Should-ContainCollection 3226 - Should -Invoke -CommandName Get-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -ParameterFilter { $InstanceName -eq 'SQL2022' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -292,13 +292,13 @@ Describe 'Get-SqlDscTraceFlag' -Tag 'Public' { $result = Get-SqlDscTraceFlag -ServiceObject $mockServiceObject - Should -ActualValue $result -BeOfType 'System.UInt32[]' + Should-HaveType 'System.UInt32[]' -Actual $result - $result | Should -HaveCount 2 - $result | Should -Contain 4199 - $result | Should -Contain 3226 + $result | Should-BeCollection -Count 2 + $result | Should-ContainCollection 4199 + $result | Should-ContainCollection 3226 - Should -Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscStartupParameter -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 b/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 index 58face496..f0a81bd7d 100644 --- a/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 +++ b/tests/Unit/Public/Import-SqlDscPreferredModule.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } BeforeAll { @@ -156,9 +156,9 @@ 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 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 0 } } @@ -181,9 +181,9 @@ 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 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 0 } } @@ -205,12 +205,12 @@ 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 - Should -Invoke -CommandName Pop-Location -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Import-Module -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Push-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Pop-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 1 } } @@ -231,12 +231,12 @@ 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 - Should -Invoke -CommandName Pop-Location -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Import-Module -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Push-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Pop-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 1 } } @@ -258,16 +258,16 @@ 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 { + Should-Invoke -CommandName Get-SqlDscPreferredModule -Exactly -ParameterFilter { $PesterBoundParameters.ContainsKey('Refresh') -and $Refresh -eq $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 - Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Pop-Location -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-Module -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Import-Module -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Push-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Pop-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-Module -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 1 } } @@ -283,13 +283,13 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { $script:localizedData.PreferredModule_FailedFinding } - { Import-SqlDscPreferredModule } | Should -Throw -ExpectedMessage $mockErrorMessage + { Import-SqlDscPreferredModule } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-Module -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Push-Location -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Pop-Location -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Import-Module -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Get-Module -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Push-Location -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Pop-Location -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 0 } } @@ -311,14 +311,14 @@ Describe 'Import-SqlDscPreferredModule' -Tag 'Public' { } It 'Should import the SQLPD module without throwing' { - { Import-SqlDscPreferredModule -Name 'OtherModule' -Force } | Should -Not -Throw - - Should -Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-Module -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-Module -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Push-Location -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Pop-Location -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Import-Module -Exactly -Times 1 -Scope It + $null = & ({ Import-SqlDscPreferredModule -Name 'OtherModule' -Force }) + + Should-Invoke -CommandName Get-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-Module -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-Module -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Push-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Pop-Location -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Import-Module -Exactly -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Initialize-SqlDscRebuildDatabase.Tests.ps1 b/tests/Unit/Public/Initialize-SqlDscRebuildDatabase.Tests.ps1 index 92395bb03..4f6a66e85 100644 --- a/tests/Unit/Public/Initialize-SqlDscRebuildDatabase.Tests.ps1 +++ b/tests/Unit/Public/Initialize-SqlDscRebuildDatabase.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Initialize-SqlDscRebuildDatabase' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''RebuildDatabase''' { @@ -103,14 +103,11 @@ Describe 'Initialize-SqlDscRebuildDatabase' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Initialize-SqlDscRebuildDatabase -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RebuildDatabase' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RebuildDatabase' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -118,14 +115,11 @@ Describe 'Initialize-SqlDscRebuildDatabase' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Initialize-SqlDscRebuildDatabase -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RebuildDatabase' - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RebuildDatabase' -and + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -133,7 +127,7 @@ Describe 'Initialize-SqlDscRebuildDatabase' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Initialize-SqlDscRebuildDatabase -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -208,12 +202,9 @@ Describe 'Initialize-SqlDscRebuildDatabase' -Tag 'Public' { Initialize-SqlDscRebuildDatabase @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 b/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 index c95fd4244..41efa11f6 100644 --- a/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 +++ b/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 @@ -110,8 +110,8 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''Install''' { @@ -147,16 +147,13 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE,AZUREEXTENSION' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE,AZUREEXTENSION' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -164,16 +161,13 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE,AZUREEXTENSION' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE,AZUREEXTENSION' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -181,7 +175,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -210,12 +204,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } @@ -644,12 +635,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } @@ -717,6 +705,10 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Force = $true ErrorAction = 'Stop' } + + $mockVerboseMessage = InModuleScope -ScriptBlock { + $script:localizedData.Server_SetupArguments + } } BeforeEach { @@ -729,23 +721,10 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { # Redirect all verbose stream to $null to ge no output from ShouldProcess. Install-SqlDscServer @installSqlDscServerParameters -Verbose 4> $null - $mockVerboseMessage = InModuleScope -ScriptBlock { - $script:localizedData.Server_SetupArguments - } - - Should -Invoke -CommandName Write-Verbose -ParameterFilter { - # Only test the command that output the string that should be tested. - $correctMessage = $Message -match $mockVerboseMessage - - # Only test string if it is the correct verbose command - if ($correctMessage) - { - $Message | Should -MatchExactly $MockExpectedRegEx - } - - # Return wether the correct command was called or not. - $correctMessage - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Write-Verbose -Exactly -ParameterFilter { + # Only test the verbose message that output the string that should be tested. + $Message -match $mockVerboseMessage -and $Message -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -780,14 +759,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Upgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Upgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -795,14 +771,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Upgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Upgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -810,7 +783,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -907,12 +880,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -958,19 +928,16 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=InstallFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=InstallFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } @@ -978,19 +945,16 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=InstallFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' # cspell: disable-line - $ArgumentList | Should -MatchExactly ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=InstallFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line + $ArgumentList -match '\/SQLSYSADMINACCOUNTS="DOMAIN\\User" "COMPANY\\SQL Administrators"' -and # cspell: disable-line + $ArgumentList -match '\/INSTALLSQLDATADIR="C:\\Program Files\\Microsoft SQL Server\\MSSQL13.INST2016\\MSSQL\\Data"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/FAILOVERCLUSTERNETWORKNAME="TESTCLU01A"' -and # cspell: disable-line + $ArgumentList -match ([System.Text.RegularExpressions.Regex]::Escape('/FAILOVERCLUSTERIPADDRESSES="IPv4;172.16.0.0;ClusterNetwork1;172.31.255.255" "IPv6;2001:db8:23:1002:20f:1fff:feff:b3a3;ClusterNetwork2" "IPv6;DHCP;ClusterNetwork3" "IPv4;DHCP;ClusterNetwork4"')) # cspell: disable-line + } -Scope It -Times 1 } } @@ -998,7 +962,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -1030,12 +994,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } @@ -1357,12 +1318,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1399,14 +1357,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -1414,14 +1369,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareFailoverCluster' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareFailoverCluster' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -1429,7 +1381,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -1457,12 +1409,10 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -1629,12 +1579,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1673,13 +1620,10 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { # cspell: disable-next - $ArgumentList | Should -MatchExactly '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + $ArgumentList -match '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' + } -Scope It -Times 1 } } @@ -1687,13 +1631,10 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { # cspell: disable-next - $ArgumentList | Should -MatchExactly '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + $ArgumentList -match '\/CONFIGURATIONFILE="C:\\MyConfig\.ini"' + } -Scope It -Times 1 } } @@ -1701,7 +1642,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -1755,12 +1696,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1796,15 +1734,12 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=EditionUpgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/PID="22222-00000-00000-00000-00000"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=EditionUpgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/PID="22222-00000-00000-00000-00000"' + } -Scope It -Times 1 } } @@ -1812,15 +1747,12 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=EditionUpgrade' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/PID="22222-00000-00000-00000-00000"' - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=EditionUpgrade' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' -and # cspell: disable-line + $ArgumentList -match '\/PID="22222-00000-00000-00000-00000"' + } -Scope It -Times 1 } } @@ -1828,7 +1760,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -1865,12 +1797,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -1907,15 +1836,12 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareImage' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCEID="Instance"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareImage' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCEID="Instance"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -1923,15 +1849,12 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=PrepareImage' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCEID="Instance"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=PrepareImage' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCEID="Instance"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -1939,7 +1862,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2022,12 +1945,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2067,20 +1987,17 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURERESOURCEGROUP="MyResourceGroup"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZUREREGION="West-US"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=AZUREEXTENSION' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' -and # cspell: disable-line + $ArgumentList -match '\/AZURERESOURCEGROUP="MyResourceGroup"' -and # cspell: disable-line + $ArgumentList -match '\/AZUREREGION="West-US"' -and # cspell: disable-line + $ArgumentList -match '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=AZUREEXTENSION' # cspell: disable-line + } -Scope It -Times 1 } } @@ -2088,20 +2005,17 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURERESOURCEGROUP="MyResourceGroup"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZUREREGION="West-US"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/FEATURES=AZUREEXTENSION' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/AZURESUBSCRIPTIONID="5d19794a-89a4-4f0b-8d4e-58f213ea3546"' -and # cspell: disable-line + $ArgumentList -match '\/AZURERESOURCEGROUP="MyResourceGroup"' -and # cspell: disable-line + $ArgumentList -match '\/AZUREREGION="West-US"' -and # cspell: disable-line + $ArgumentList -match '\/AZURETENANTID="7e52fb9e-6aad-426c-98c4-7d2f11f7e94b"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPAL="MyServicePrincipal"' -and # cspell: disable-line + $ArgumentList -match '\/AZURESERVICEPRINCIPALSECRET="jT7ELPbD2GGuvLmjABDL"' -and # cspell: disable-line + $ArgumentList -match '\/FEATURES=AZUREEXTENSION' # cspell: disable-line + } -Scope It -Times 1 } } @@ -2109,7 +2023,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2150,12 +2064,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2191,14 +2102,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line + } -Scope It -Times 1 } } @@ -2206,14 +2114,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=SPI_AS_NEWFARM' # cspell: disable-line + } -Scope It -Times 1 } } @@ -2221,7 +2126,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2272,12 +2177,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } @@ -2307,6 +2209,10 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Force = $true ErrorAction = 'Stop' } + + $mockVerboseMessage = InModuleScope -ScriptBlock { + $script:localizedData.Server_SetupArguments + } } BeforeEach { @@ -2319,23 +2225,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { # Redirect all verbose stream to $null to ge no output from ShouldProcess. Install-SqlDscServer @installSqlDscServerParameters -Verbose 4> $null - $mockVerboseMessage = InModuleScope -ScriptBlock { - $script:localizedData.Server_SetupArguments - } - - Should -Invoke -CommandName Write-Verbose -ParameterFilter { - # Only test the command that output the string that should be tested. - $correctMessage = $Message -match $mockVerboseMessage - - # Only test string if it is the correct verbose command - if ($correctMessage) - { - $Message | Should -MatchExactly $MockExpectedRegEx - } - # Return wether the correct command was called or not. - $correctMessage - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Write-Verbose -Exactly -ParameterFilter { + # Only test the verbose message that output the string that should be tested. + $Message -match $mockVerboseMessage -and $Message -match $MockExpectedRegEx + } -Scope It -Times 1 } } } @@ -2360,14 +2254,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line + } -Scope It -Times 1 } } @@ -2375,14 +2266,11 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Install' - $ArgumentList | Should -MatchExactly '\/IACCEPTSQLSERVERLICENSETERMS' # cspell: disable-line - $ArgumentList | Should -MatchExactly '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Install' -and + $ArgumentList -match '\/IACCEPTSQLSERVERLICENSETERMS' -and # cspell: disable-line + $ArgumentList -match '\/ROLE=ALLFEATURES_WITHDEFAULTS' # cspell: disable-line + } -Scope It -Times 1 } } @@ -2390,7 +2278,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Install-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -2431,12 +2319,9 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { Install-SqlDscServer @installSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Invoke-SqlDscQuery.Tests.ps1 b/tests/Unit/Public/Invoke-SqlDscQuery.Tests.ps1 index c3b72b4e4..cb9625720 100644 --- a/tests/Unit/Public/Invoke-SqlDscQuery.Tests.ps1 +++ b/tests/Unit/Public/Invoke-SqlDscQuery.Tests.ps1 @@ -78,8 +78,8 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When executing a query that cannot return any results' { @@ -120,9 +120,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Confirm:$false - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 } } @@ -130,9 +130,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 } } @@ -140,9 +140,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -WhatIf - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 0 + $mockMethodExecuteNonQueryCallCount | Should-Be 0 } } @@ -150,9 +150,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = $mockServerObject | Invoke-SqlDscQuery -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 } } } @@ -161,9 +161,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -StatementTimeout 900 -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 } } @@ -171,9 +171,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -RedactText @('MyString') -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 } } } @@ -194,24 +194,24 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -ServerName 'localhost' -InstanceName 'INSTANCE' -LoginType 'WindowsUser' -Credential $mockSqlCredential -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 - Should -Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-SqlDscDatabaseEngine -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-SqlDscDatabaseEngine -Exactly -Scope It -Times 1 } Context 'When calling the command with optional parameter Encrypt' { It 'Should execute the query without throwing and without returning any result' { $result = Invoke-SqlDscQuery -Encrypt -ServerName 'localhost' -InstanceName 'INSTANCE' -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteNonQueryCallCount | Should -Be 1 + $mockMethodExecuteNonQueryCallCount | Should-Be 1 - Should -Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-SqlDscDatabaseEngine -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-SqlDscDatabaseEngine -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-SqlDscDatabaseEngine -Exactly -Scope It -Times 1 } } } @@ -255,9 +255,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and return the expected data set' { $result = Invoke-SqlDscQuery -PassThru -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Confirm:$false - $result | Should -HaveType [System.Data.DataSet] + $result | Should-HaveType ([System.Data.DataSet]) - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } @@ -265,9 +265,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and return the expected data set' { $result = Invoke-SqlDscQuery -PassThru -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -HaveType [System.Data.DataSet] + $result | Should-HaveType ([System.Data.DataSet]) - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } @@ -275,9 +275,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and return the expected data set' { $result = Invoke-SqlDscQuery -PassThru -ServerObject $mockServerObject -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -WhatIf - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteWithResultsCallCount | Should -Be 0 + $mockMethodExecuteWithResultsCallCount | Should-Be 0 } } @@ -285,9 +285,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should execute the query without throwing and return the expected data set' { $result = $mockServerObject | Invoke-SqlDscQuery -PassThru -DatabaseName 'MockDatabase' -Query 'select name from sys.databases' -Force - $result | Should -HaveType [System.Data.DataSet] + $result | Should-HaveType ([System.Data.DataSet]) - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } } @@ -339,9 +339,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should throw the correct error' { { Invoke-SqlDscQuery @mockInvokeSqlDscQueryParameters - } | Should -Throw -ExpectedMessage '*Mocked error*' + } | Should-Throw -ExceptionMessage '*Mocked error*' - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } @@ -349,9 +349,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should throw the correct error' { { Invoke-SqlDscQuery @mockInvokeSqlDscQueryParameters - } | Should -Throw -ExpectedMessage '*Mocked error*' + } | Should-Throw -ExceptionMessage '*Mocked error*' - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } } @@ -372,9 +372,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should not throw an exception and does not return any result' { $result = Invoke-SqlDscQuery @mockInvokeSqlDscQueryParameters - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } @@ -382,9 +382,9 @@ Describe 'Invoke-SqlDscQuery' -Tag 'Public' { It 'Should not throw an exception and does not return any result' { $result = Invoke-SqlDscQuery @mockInvokeSqlDscQueryParameters - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - $mockMethodExecuteWithResultsCallCount | Should -Be 1 + $mockMethodExecuteWithResultsCallCount | Should-Be 1 } } } diff --git a/tests/Unit/Public/New-SqlDscAudit.Tests.ps1 b/tests/Unit/Public/New-SqlDscAudit.Tests.ps1 index 2430decce..3f3cbda71 100644 --- a/tests/Unit/Public/New-SqlDscAudit.Tests.ps1 +++ b/tests/Unit/Public/New-SqlDscAudit.Tests.ps1 @@ -95,8 +95,8 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When adding an application log audit using mandatory parameters' { @@ -142,10 +142,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -Confirm:$false @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'ApplicationLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'ApplicationLog' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -154,10 +154,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -Force @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'ApplicationLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'ApplicationLog' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -166,10 +166,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -WhatIf @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'ApplicationLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'ApplicationLog' - $mockMethodCreateCallCount | Should -Be 0 + $mockMethodCreateCallCount | Should-Be 0 } } @@ -178,10 +178,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { $mockServerObject | New-SqlDscAudit -LogType 'ApplicationLog' -Name 'Log1' -Force # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'ApplicationLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'ApplicationLog' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } } @@ -229,10 +229,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -Confirm:$false @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'SecurityLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'SecurityLog' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -241,10 +241,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -Force @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'SecurityLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'SecurityLog' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -253,10 +253,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -WhatIf @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'SecurityLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'SecurityLog' - $mockMethodCreateCallCount | Should -Be 0 + $mockMethodCreateCallCount | Should-Be 0 } } @@ -265,10 +265,10 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { $mockServerObject | New-SqlDscAudit -LogType 'SecurityLog' -Name 'Log1' -Force # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'SecurityLog' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'SecurityLog' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } } @@ -316,11 +316,11 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -Confirm:$false @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -329,11 +329,11 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -Force @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -342,11 +342,11 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -WhatIf @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) - $mockMethodCreateCallCount | Should -Be 0 + $mockMethodCreateCallCount | Should-Be 0 } } @@ -355,11 +355,11 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { $mockServerObject | New-SqlDscAudit -Path (Get-TemporaryFolder) -Name 'Log1' -Force # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } } @@ -384,7 +384,7 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { $mockErrorMessage = "Cannot validate argument on parameter 'Path'. " + ($mockErrorMessage -f (Get-TemporaryFolder)) - { New-SqlDscAudit @mockNewSqlDscAuditParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { New-SqlDscAudit @mockNewSqlDscAuditParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -431,13 +431,13 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -MaximumFileSize 1000 -MaximumFileSizeUnit 'Megabyte' @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.MaximumFileSize | Should -Be 1000 - $mockCreateAuditObject.MaximumFileSizeUnit | Should -Be 'Mb' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.MaximumFileSize | Should-Be 1000 + $mockCreateAuditObject.MaximumFileSizeUnit | Should-Be 'Mb' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -484,12 +484,12 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -MaximumFiles 2 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.MaximumFiles | Should -Be 2 + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.MaximumFiles | Should-Be 2 - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -536,13 +536,13 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.MaximumFiles | Should -Be 2 - $mockCreateAuditObject.ReserveDiskSpace | Should -BeTrue + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.MaximumFiles | Should-Be 2 + $mockCreateAuditObject.ReserveDiskSpace | Should-BeTrue - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } Context 'When ReserveDiskSpace is set to $false' { @@ -550,13 +550,13 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace:$false @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.MaximumFiles | Should -Be 2 - $mockCreateAuditObject.ReserveDiskSpace | Should -BeFalse + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.MaximumFiles | Should-Be 2 + $mockCreateAuditObject.ReserveDiskSpace | Should-BeFalse - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } } @@ -604,12 +604,12 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -MaximumRolloverFiles 2 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.MaximumRolloverFiles | Should -Be 2 + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.MaximumRolloverFiles | Should-Be 2 - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -656,12 +656,12 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -AuditGuid 'b5962b93-a359-42ef-bf1e-193e8a5f6222' @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.Guid | Should -Be 'b5962b93-a359-42ef-bf1e-193e8a5f6222' + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.Guid | Should-Be 'b5962b93-a359-42ef-bf1e-193e8a5f6222' - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } Context 'When passing an invalid GUID' { @@ -672,7 +672,7 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { $mockErrorMessage = $mockErrorMessage -replace '\[', '`[' { New-SqlDscAudit -AuditGuid 'not a guid' @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage + '*') + Should-Throw -ExceptionMessage ($mockErrorMessage + '*') } } } @@ -731,12 +731,12 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -OnFailure $MockOnFailureValue @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.OnFailure | Should -Be $MockOnFailureValue + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.OnFailure | Should-Be $MockOnFailureValue - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } } @@ -784,12 +784,12 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.QueueDelay | Should -Be 1000 + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.QueueDelay | Should-Be 1000 - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -836,12 +836,12 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { New-SqlDscAudit -AuditFilter "([server_principal_name] like '%ADMINISTRATOR'" @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockCreateAuditObject.Name | Should -Be 'Log1' - $mockCreateAuditObject.DestinationType | Should -Be 'File' - $mockCreateAuditObject.FilePath | Should -Be (Get-TemporaryFolder) - $mockCreateAuditObject.Filter | Should -Be "([server_principal_name] like '%ADMINISTRATOR'" + $mockCreateAuditObject.Name | Should-Be 'Log1' + $mockCreateAuditObject.DestinationType | Should-Be 'File' + $mockCreateAuditObject.FilePath | Should-Be (Get-TemporaryFolder) + $mockCreateAuditObject.Filter | Should-Be "([server_principal_name] like '%ADMINISTRATOR'" - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -881,11 +881,11 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $newSqlDscAuditResult = New-SqlDscAudit -PassThru @mockDefaultParameters - $newSqlDscAuditResult.Name | Should -Be 'Log1' - $newSqlDscAuditResult.DestinationType | Should -Be 'File' - $newSqlDscAuditResult.FilePath | Should -Be (Get-TemporaryFolder) + $newSqlDscAuditResult.Name | Should-Be 'Log1' + $newSqlDscAuditResult.DestinationType | Should-Be 'File' + $newSqlDscAuditResult.FilePath | Should-Be (Get-TemporaryFolder) - $mockMethodCreateCallCount | Should -Be 1 + $mockMethodCreateCallCount | Should-Be 1 } } @@ -911,7 +911,7 @@ Describe 'New-SqlDscAudit' -Tag 'Public' { } { New-SqlDscAudit @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'Log1') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'Log1') } } } diff --git a/tests/Unit/Public/Remove-SqlDscAudit.Tests.ps1 b/tests/Unit/Public/Remove-SqlDscAudit.Tests.ps1 index 2c49eb677..3b8821c52 100644 --- a/tests/Unit/Public/Remove-SqlDscAudit.Tests.ps1 +++ b/tests/Unit/Public/Remove-SqlDscAudit.Tests.ps1 @@ -75,8 +75,8 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When removing an audit by ServerObject' { @@ -108,7 +108,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Remove-SqlDscAudit -Confirm:$false @mockDefaultParameters - $mockMethodDropIfExistsCallCount | Should -Be 1 + $mockMethodDropIfExistsCallCount | Should-Be 1 } } @@ -116,7 +116,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Remove-SqlDscAudit -Force @mockDefaultParameters - $mockMethodDropIfExistsCallCount | Should -Be 1 + $mockMethodDropIfExistsCallCount | Should-Be 1 } } @@ -124,7 +124,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Remove-SqlDscAudit -WhatIf @mockDefaultParameters - $mockMethodDropIfExistsCallCount | Should -Be 0 + $mockMethodDropIfExistsCallCount | Should-Be 0 } } @@ -132,7 +132,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $mockServerObject | Remove-SqlDscAudit -Name 'Log1' -Force - $mockMethodDropIfExistsCallCount | Should -Be 1 + $mockMethodDropIfExistsCallCount | Should-Be 1 } } } @@ -163,7 +163,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Remove-SqlDscAudit -Confirm:$false @mockDefaultParameters - $mockMethodDropIfExistsCallCount | Should -Be 1 + $mockMethodDropIfExistsCallCount | Should-Be 1 } } @@ -171,7 +171,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Remove-SqlDscAudit -Force @mockDefaultParameters - $mockMethodDropIfExistsCallCount | Should -Be 1 + $mockMethodDropIfExistsCallCount | Should-Be 1 } } @@ -179,7 +179,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Remove-SqlDscAudit -WhatIf @mockDefaultParameters - $mockMethodDropIfExistsCallCount | Should -Be 0 + $mockMethodDropIfExistsCallCount | Should-Be 0 } } @@ -187,7 +187,7 @@ Describe 'Remove-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $mockAuditObject | Remove-SqlDscAudit -Force - $mockMethodDropIfExistsCallCount | Should -Be 1 + $mockMethodDropIfExistsCallCount | Should-Be 1 } } } diff --git a/tests/Unit/Public/Remove-SqlDscNode.Tests.ps1 b/tests/Unit/Public/Remove-SqlDscNode.Tests.ps1 index e8230151d..03fbd609d 100644 --- a/tests/Unit/Public/Remove-SqlDscNode.Tests.ps1 +++ b/tests/Unit/Public/Remove-SqlDscNode.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Remove-SqlDscNode' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''RemoveNode''' { @@ -102,13 +102,10 @@ Describe 'Remove-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Remove-SqlDscNode -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RemoveNode' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RemoveNode' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -116,13 +113,10 @@ Describe 'Remove-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Remove-SqlDscNode -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=RemoveNode' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=RemoveNode' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -130,7 +124,7 @@ Describe 'Remove-SqlDscNode' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Remove-SqlDscNode -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -164,12 +158,9 @@ Describe 'Remove-SqlDscNode' -Tag 'Public' { Remove-SqlDscNode @removeSqlDscNodeParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 index bc413e003..e19e1d4e0 100644 --- a/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Remove-SqlDscTraceFlag.Tests.ps1 @@ -75,15 +75,15 @@ Describe 'Remove-SqlDscTraceFlag' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When passing $null as ServiceObject' { It 'Should throw the correct error' { $mockErrorMessage = 'Cannot bind argument to parameter ''ServiceObject'' because it is null.' - { Remove-SqlDscTraceFlag -ServiceObject $null } | Should -Throw -ExpectedMessage $mockErrorMessage + { Remove-SqlDscTraceFlag -ServiceObject $null } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -103,39 +103,39 @@ 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 0 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 0 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Scope It -Times 0 } } 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 0 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -143,29 +143,29 @@ 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 0 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag.Count -eq 0 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Scope It -Times 0 } } } @@ -181,12 +181,12 @@ 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -203,9 +203,9 @@ 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 + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -Scope It -Times 0 } } @@ -221,12 +221,12 @@ 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 { + Should-Invoke -CommandName Set-SqlDscTraceFlag -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Repair-SqlDscServer.Tests.ps1 b/tests/Unit/Public/Repair-SqlDscServer.Tests.ps1 index 220e00e3b..39397efd1 100644 --- a/tests/Unit/Public/Repair-SqlDscServer.Tests.ps1 +++ b/tests/Unit/Public/Repair-SqlDscServer.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Repair-SqlDscServer' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''Repair''' { @@ -104,14 +104,11 @@ Describe 'Repair-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Repair-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Repair' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Repair' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -119,14 +116,14 @@ Describe 'Repair-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Repair-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Repair' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Repair' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line # Return $true if none of the above throw. $true - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -134,7 +131,7 @@ Describe 'Repair-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Repair-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } @@ -160,12 +157,9 @@ Describe 'Repair-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Repair-SqlDscServer @repairSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly 'PBPORTRANGE=16450-16460' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match 'PBPORTRANGE=16450-16460' # cspell: disable-line + } -Scope It -Times 1 } } @@ -220,12 +214,9 @@ Describe 'Repair-SqlDscServer' -Tag 'Public' { Repair-SqlDscServer @repairSqlDscServerParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly $MockExpectedRegEx - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match $MockExpectedRegEx + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Save-SqlDscSqlServerMediaFile.Tests.ps1 b/tests/Unit/Public/Save-SqlDscSqlServerMediaFile.Tests.ps1 index faa3bdd0d..fd05aae70 100644 --- a/tests/Unit/Public/Save-SqlDscSqlServerMediaFile.Tests.ps1 +++ b/tests/Unit/Public/Save-SqlDscSqlServerMediaFile.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } BeforeAll { @@ -108,7 +108,7 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { It 'Should call Invoke-WebRequest to download the media file' { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false - Should -Invoke -CommandName Invoke-WebRequest -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Invoke-WebRequest -Exactly -Scope It -Times 1 } } @@ -126,25 +126,25 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { It 'Should call Invoke-WebRequest to download the executable file' { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false - Should -Invoke -CommandName Invoke-WebRequest -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Invoke-WebRequest -Exactly -Scope It -Times 1 } It 'Should call Start-Process to initiate download using the downloaded executable file' { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should call Remove-Item to remove the executable file' { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false - Should -Invoke -CommandName Remove-Item -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-Item -Exactly -Scope It -Times 1 } It 'Should call Rename-Item to rename the downloaded ISO file to the specified name' { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false - Should -Invoke -CommandName Rename-Item -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Rename-Item -Exactly -Scope It -Times 1 } } @@ -163,8 +163,8 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { Save-SqlDscSqlServerMediaFile -Url 'https://example.com/media.iso' -DestinationPath 'C:\Temp' -Force - Should -Invoke -CommandName Invoke-WebRequest -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Remove-Item -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Invoke-WebRequest -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Remove-Item -Exactly -Scope It -Times 1 } } @@ -174,7 +174,7 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { Save-SqlDscSqlServerMediaFile -Url 'https://example.com/media.iso' -DestinationPath 'C:\Temp' -Force - Should -Invoke -CommandName Invoke-WebRequest -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Invoke-WebRequest -Exactly -Scope It -Times 1 } } @@ -184,7 +184,7 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { Save-SqlDscSqlServerMediaFile -Url 'https://example.com/media.iso' -DestinationPath 'C:\Temp' -Quiet -Confirm:$false - Should -Invoke -CommandName Invoke-WebRequest -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Invoke-WebRequest -Exactly -Scope It -Times 1 } } @@ -195,8 +195,8 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { Save-SqlDscSqlServerMediaFile -Url 'https://example.com/media.exe' -DestinationPath 'C:\Temp' -Language 'fr-FR' -Confirm:$false - Should -Invoke -CommandName Invoke-WebRequest -Times 1 -Exactly - Should -Invoke -CommandName Start-Process -Times 1 -Exactly + Should-Invoke -CommandName Invoke-WebRequest -Exactly -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Times 1 } } @@ -214,7 +214,7 @@ Describe 'Save-SqlDscSqlServerMediaFile' -Tag 'Public' { $script:localizedData.SqlServerMediaFile_Save_InvalidDestinationFolder } - { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false } | Should -Throw $mockErrorMessage + { Save-SqlDscSqlServerMediaFile -Url $Url -DestinationPath $DestinationPath -Confirm:$false } | Should-Throw $mockErrorMessage } } } diff --git a/tests/Unit/Public/Set-SqlDscAudit.Tests.ps1 b/tests/Unit/Public/Set-SqlDscAudit.Tests.ps1 index 104548756..ea38b5791 100644 --- a/tests/Unit/Public/Set-SqlDscAudit.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscAudit.Tests.ps1 @@ -115,8 +115,8 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setting an audit by an ServerObject' { @@ -157,10 +157,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -Confirm:$false -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -169,10 +169,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -Force -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -181,10 +181,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -WhatIf -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -BeNullOrEmpty + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-BeFalsy - $mockMethodAlterCallCount | Should -Be 0 + $mockMethodAlterCallCount | Should-Be 0 } } @@ -193,10 +193,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { $mockServerObject | Set-SqlDscAudit -Name 'Log1' -QueueDelay 1000 -Force # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } } @@ -228,10 +228,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -Confirm:$false -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -240,10 +240,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -Force -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -252,10 +252,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -WhatIf -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -BeNullOrEmpty + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-BeFalsy - $mockMethodAlterCallCount | Should -Be 0 + $mockMethodAlterCallCount | Should-Be 0 } } @@ -264,10 +264,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { $mockAuditObject | Set-SqlDscAudit -QueueDelay 1000 -Force # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } } @@ -292,7 +292,7 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { $mockErrorMessage = "Cannot validate argument on parameter 'Path'. " + ($mockErrorMessage -f (Get-TemporaryFolder)) - { Set-SqlDscAudit @mockNewSqlDscAuditParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-SqlDscAudit @mockNewSqlDscAuditParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -309,7 +309,7 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { $script:localizedData.Audit_MaximumFileSizeParameterValueInvalid } - { Set-SqlDscAudit @mockNewSqlDscAuditParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-SqlDscAudit @mockNewSqlDscAuditParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -326,7 +326,7 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { $script:localizedData.Audit_QueueDelayParameterValueInvalid } - { Set-SqlDscAudit @mockNewSqlDscAuditParameters } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-SqlDscAudit @mockNewSqlDscAuditParameters } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -359,10 +359,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -Path (Get-TemporaryFolder) @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.FilePath | Should -Be (Get-TemporaryFolder) + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.FilePath | Should-Be (Get-TemporaryFolder) - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -395,11 +395,11 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -MaximumFileSize 1000 -MaximumFileSizeUnit 'Megabyte' @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumFileSize | Should -Be 1000 - $mockAuditObject.MaximumFileSizeUnit | Should -Be 'Mb' + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumFileSize | Should-Be 1000 + $mockAuditObject.MaximumFileSizeUnit | Should-Be 'Mb' - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -432,10 +432,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -MaximumFiles 2 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumFiles | Should -Be 2 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumFiles | Should-Be 2 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -468,11 +468,11 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumFiles | Should -Be 2 - $mockAuditObject.ReserveDiskSpace | Should -BeTrue + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumFiles | Should-Be 2 + $mockAuditObject.ReserveDiskSpace | Should-BeTrue - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } Context 'When ReserveDiskSpace is set to $false' { @@ -480,11 +480,11 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -MaximumFiles 2 -ReserveDiskSpace:$false @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumFiles | Should -Be 2 - $mockAuditObject.ReserveDiskSpace | Should -BeFalse + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumFiles | Should-Be 2 + $mockAuditObject.ReserveDiskSpace | Should-BeFalse - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } } @@ -518,10 +518,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -MaximumRolloverFiles 2 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumRolloverFiles | Should -Be 2 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumRolloverFiles | Should-Be 2 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -554,10 +554,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -AuditGuid 'b5962b93-a359-42ef-bf1e-193e8a5f6222' @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.Guid | Should -Be 'b5962b93-a359-42ef-bf1e-193e8a5f6222' + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.Guid | Should-Be 'b5962b93-a359-42ef-bf1e-193e8a5f6222' - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } Context 'When passing an invalid GUID' { @@ -568,7 +568,7 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { $mockErrorMessage = $mockErrorMessage -replace '\[', '`[' { Set-SqlDscAudit -AuditGuid 'not a guid' @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage + '*') + Should-Throw -ExceptionMessage ($mockErrorMessage + '*') } } } @@ -613,10 +613,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -OnFailure $MockOnFailureValue @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.OnFailure | Should -Be $MockOnFailureValue + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.OnFailure | Should-Be $MockOnFailureValue - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } } @@ -650,10 +650,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -QueueDelay 1000 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -686,10 +686,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { Set-SqlDscAudit -AuditFilter "([server_principal_name] like '%ADMINISTRATOR'" @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.Filter | Should -Be "([server_principal_name] like '%ADMINISTRATOR'" + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.Filter | Should-Be "([server_principal_name] like '%ADMINISTRATOR'" - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -721,10 +721,10 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { $newSqlDscAuditResult = Set-SqlDscAudit -QueueDelay 1000 -PassThru @mockDefaultParameters - $newSqlDscAuditResult.Name | Should -Be 'Log1' - $newSqlDscAuditResult.QueueDelay | Should -Be 1000 + $newSqlDscAuditResult.Name | Should-Be 'Log1' + $newSqlDscAuditResult.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -760,11 +760,11 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { It 'Should call the mocked method and have correct values in the object' { Set-SqlDscAudit -QueueDelay 1000 -Refresh @mockDefaultParameters - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.QueueDelay | Should -Be 1000 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.QueueDelay | Should-Be 1000 - $mockMethodAlterCallCount | Should -Be 1 - $mockMethodRefreshCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 + $mockMethodRefreshCallCount | Should-Be 1 } } @@ -796,16 +796,16 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { } It 'Should call the mocked method and have correct values in the object' { - $mockAuditObject.MaximumRolloverFiles | Should -Be 10 -Because 'there has to be a value greater than 0 in the object that is passed to the command in this test' + $mockAuditObject.MaximumRolloverFiles | Should-Be 10 -Because 'there has to be a value greater than 0 in the object that is passed to the command in this test' Set-SqlDscAudit -MaximumFiles 2 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumRolloverFiles | Should -Be 0 - $mockAuditObject.MaximumFiles | Should -Be 2 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumRolloverFiles | Should-Be 0 + $mockAuditObject.MaximumFiles | Should-Be 2 - $mockMethodAlterCallCount | Should -Be 2 -Because 'the call to Alter() need to happen twice, first to set MaximumRolloverFiles to 0, then another to set MaximumFiles to the new value' + $mockMethodAlterCallCount | Should-Be 2 -Because 'the call to Alter() need to happen twice, first to set MaximumRolloverFiles to 0, then another to set MaximumFiles to the new value' } } @@ -837,16 +837,16 @@ Describe 'Set-SqlDscAudit' -Tag 'Public' { } It 'Should call the mocked method and have correct values in the object' { - $mockAuditObject.MaximumFiles | Should -Be 10 -Because 'there has to be a value greater than 0 in the object that is passed to the command in this test' + $mockAuditObject.MaximumFiles | Should-Be 10 -Because 'there has to be a value greater than 0 in the object that is passed to the command in this test' Set-SqlDscAudit -MaximumRolloverFiles 2 @mockDefaultParameters # This is the object created by the mock and modified by the command. - $mockAuditObject.Name | Should -Be 'Log1' - $mockAuditObject.MaximumFiles | Should -Be 0 - $mockAuditObject.MaximumRolloverFiles | Should -Be 2 + $mockAuditObject.Name | Should-Be 'Log1' + $mockAuditObject.MaximumFiles | Should-Be 0 + $mockAuditObject.MaximumRolloverFiles | Should-Be 2 - $mockMethodAlterCallCount | Should -Be 2 -Because 'the call to Alter() need to happen twice, first to set MaximumFiles to 0, then another to set MaximumRolloverFiles to the new value' + $mockMethodAlterCallCount | Should-Be 2 -Because 'the call to Alter() need to happen twice, first to set MaximumFiles to 0, then another to set MaximumRolloverFiles to the new value' } } } diff --git a/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 b/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 index ad5523d8d..73f97ae0c 100644 --- a/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscDatabasePermission.Tests.ps1 @@ -71,7 +71,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'MissingDatabase') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'MissingDatabase') } } @@ -100,7 +100,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'MissingDatabase') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'MissingDatabase') } } @@ -132,7 +132,7 @@ Describe 'Set-SqlDscDatabasePermission' -Tag 'Public' { } { Set-SqlDscDatabasePermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'UnknownUser', 'AdventureWorks') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'UnknownUser', 'AdventureWorks') } } @@ -170,10 +170,9 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 1 } } @@ -210,10 +209,9 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 1 } } @@ -250,10 +248,9 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 0 } } @@ -290,18 +287,16 @@ 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 + $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 + $script:mockMethodGrantCallCount | Should-Be 1 } } } @@ -355,18 +350,16 @@ 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 + $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 + $script:mockMethodGrantUsingWithGrantCallCount | Should-Be 1 } } } @@ -404,18 +397,16 @@ 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 + $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 + $script:mockMethodRevokeCallCount | Should-Be 1 } } } @@ -472,18 +463,16 @@ 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 + $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 + $script:mockMethodGrantUsingWithGrantCallCount | Should-Be 1 } } } @@ -521,18 +510,16 @@ 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 + $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 + $script:mockMethodDenyCallCount | Should-Be 1 } } @@ -546,12 +533,11 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 1 - Should -Invoke -CommandName 'Write-Warning' -ParameterFilter { + Should-Invoke -CommandName 'Write-Warning' -ParameterFilter { $Message -eq $mockWarningMessage } } diff --git a/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 b/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 index 9eec9075b..7929620e2 100644 --- a/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 @@ -72,7 +72,7 @@ Describe 'Set-SqlDscServerPermission' -Tag 'Public' { } { Set-SqlDscServerPermission -ServerObject $mockServerObject @mockDefaultParameters } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'UnknownUser', 'MockInstance') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'UnknownUser', 'MockInstance') } } @@ -103,10 +103,9 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 1 } } @@ -137,10 +136,9 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 1 } } @@ -171,10 +169,9 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 0 } } @@ -204,18 +201,16 @@ 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 + $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 + $script:mockMethodGrantCallCount | Should-Be 1 } } } @@ -263,18 +258,16 @@ 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 + $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 + $script:mockMethodGrantUsingWithGrantCallCount | Should-Be 1 } } } @@ -305,18 +298,16 @@ 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 + $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 + $script:mockMethodRevokeCallCount | Should-Be 1 } } } @@ -366,18 +357,16 @@ 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 + $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 + $script:mockMethodGrantUsingWithGrantCallCount | Should-Be 1 } } } @@ -408,18 +397,16 @@ 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 + $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 + $script:mockMethodDenyCallCount | Should-Be 1 } } @@ -433,12 +420,11 @@ 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 + $script:mockMethodDenyCallCount | Should-Be 1 - Should -Invoke -CommandName 'Write-Warning' -ParameterFilter { + Should-Invoke -CommandName 'Write-Warning' -ParameterFilter { $Message -eq $mockWarningMessage } } diff --git a/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 b/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 index 710237c65..a232914fb 100644 --- a/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscStartupParameter.Tests.ps1 @@ -75,15 +75,15 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When passing $null as ServiceObject' { It 'Should throw the correct error' { $mockErrorMessage = 'Cannot bind argument to parameter ''ServiceObject'' because it is null.' - { Set-SqlDscStartupParameter -ServiceObject $null } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-SqlDscStartupParameter -ServiceObject $null } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -104,7 +104,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { $mockErrorMessage = $mockErrorMessage -f 'SqlServer', 'SqlAgent' { Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag @() -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage $mockErrorMessage + Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -117,7 +117,7 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { $mockErrorMessage = $mockErrorMessage -f 'SqlServer', 'SqlAgent' { Set-SqlDscStartupParameter -ServiceObject $mockServiceObject -TraceFlag @() -ErrorAction 'SilentlyContinue' } | - Should -Throw -ExpectedMessage $mockErrorMessage + Should-Throw -ExceptionMessage $mockErrorMessage } } } @@ -133,9 +133,9 @@ 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 + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Scope It -Times 1 } } @@ -145,9 +145,9 @@ Describe 'Set-SqlDscStartupParameter' -Tag 'Public' { $script:localizedData.TraceFlag_Set_FailedToFindServiceObject } - { Set-SqlDscStartupParameter -ServerName 'localhost' -TraceFlag @() -ErrorAction 'Stop' } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-SqlDscStartupParameter -ServerName 'localhost' -TraceFlag @() -ErrorAction 'Stop' } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-SqlDscManagedComputerService -Exactly -Scope It -Times 1 } } } @@ -175,45 +175,45 @@ 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') + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive ($mockStartupParameters + ';-T4199') - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } 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') + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive ($mockStartupParameters + ';-T4199') - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } 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 + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive $mockStartupParameters - $mockMethodAlterCallCount | Should -Be 0 + $mockMethodAlterCallCount | Should-Be 0 } } 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') + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive ($mockStartupParameters + ';-T4199') - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } } @@ -243,34 +243,34 @@ 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') + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive ($mockStartupParameters + ';-T4199') - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } 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') + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive ($mockStartupParameters + ';-T4199') - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } 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 + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive $mockStartupParameters - $mockMethodAlterCallCount | Should -Be 0 + $mockMethodAlterCallCount | Should-Be 0 } } } @@ -300,12 +300,12 @@ 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 + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive $mockExpectedStartupParameters - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -333,12 +333,12 @@ 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') + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive ($mockStartupParameters + ';-t8688') - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } @@ -367,12 +367,12 @@ 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 + $mockServiceObject.StartupParameters | Should-BeString -CaseSensitive $mockExpectedStartupParameters - $mockMethodAlterCallCount | Should -Be 1 + $mockMethodAlterCallCount | Should-Be 1 } } } diff --git a/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 b/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 index da48bf1ba..a84527220 100644 --- a/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 +++ b/tests/Unit/Public/Set-SqlDscTraceFlag.Tests.ps1 @@ -75,15 +75,15 @@ Describe 'Set-SqlDscTraceFlag' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When passing $null as ServiceObject' { It 'Should throw the correct error' { $mockErrorMessage = 'Cannot bind argument to parameter ''ServiceObject'' because it is null.' - { Set-SqlDscTraceFlag -ServiceObject $null } | Should -Throw -ExpectedMessage $mockErrorMessage + { Set-SqlDscTraceFlag -ServiceObject $null } | Should-Throw -ExceptionMessage $mockErrorMessage } } @@ -97,39 +97,39 @@ 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -Scope It -Times 0 } } 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -141,29 +141,29 @@ 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -ParameterFilter { $TraceFlag -contains 4199 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -Scope It -Times 0 } } } @@ -174,11 +174,11 @@ 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 }) - Should -Invoke -CommandName Set-SqlDscStartupParameter -ParameterFilter { + Should-Invoke -CommandName Set-SqlDscStartupParameter -Exactly -ParameterFilter { $TraceFlag.Count -eq 0 - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } diff --git a/tests/Unit/Public/Test-SqlDscIsDatabasePrincipal.Tests.ps1 b/tests/Unit/Public/Test-SqlDscIsDatabasePrincipal.Tests.ps1 index 64c4c40fa..071b1e584 100644 --- a/tests/Unit/Public/Test-SqlDscIsDatabasePrincipal.Tests.ps1 +++ b/tests/Unit/Public/Test-SqlDscIsDatabasePrincipal.Tests.ps1 @@ -68,7 +68,7 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should throw the correct error' { { Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'MissingDatabase' -Name 'KnownUser' } | - Should -Throw -ExpectedMessage ($mockErrorMessage -f 'MissingDatabase') + Should-Throw -ExceptionMessage ($mockErrorMessage -f 'MissingDatabase') } } @@ -109,7 +109,7 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $false' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'UnknownUser' - $result | Should -BeFalse + $result | Should-BeFalse } } @@ -151,14 +151,14 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $true' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'Zebes\SamusAran' - $result | Should -BeTrue + $result | Should-BeTrue } Context 'When passing ServerObject over the pipeline' { It 'Should return $true' { $result = $mockServerObject | Test-SqlDscIsDatabasePrincipal -DatabaseName 'AdventureWorks' -Name 'Zebes\SamusAran' - $result | Should -BeTrue + $result | Should-BeTrue } } @@ -166,7 +166,7 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $false' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'Zebes\SamusAran' -ExcludeUsers - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -208,14 +208,14 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $true' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'MyAppRole' - $result | Should -BeTrue + $result | Should-BeTrue } Context 'When application roles are excluded from evaluation' { It 'Should return $false' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'MyAppRole' -ExcludeApplicationRoles - $result | Should -BeFalse + $result | Should-BeFalse } } } @@ -257,14 +257,14 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $true' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'UserDefinedRole' - $result | Should -BeTrue + $result | Should-BeTrue } Context 'When roles are excluded from evaluation' { It 'Should return $false' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'UserDefinedRole' -ExcludeRoles - $result | Should -BeFalse + $result | Should-BeFalse } } @@ -307,7 +307,7 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $true' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'UserDefinedRole' -ExcludeFixedRoles - $result | Should -BeTrue + $result | Should-BeTrue } } } @@ -349,14 +349,14 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $true' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'db_datareader' - $result | Should -BeTrue + $result | Should-BeTrue } Context 'When roles are excluded from evaluation' { It 'Should return $false' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'db_datareader' -ExcludeRoles - $result | Should -BeFalse + $result | Should-BeFalse } } @@ -399,7 +399,7 @@ Describe 'Test-SqlDscIsDatabasePrincipal' -Tag 'Public' { It 'Should return $false' { $result = Test-SqlDscIsDatabasePrincipal -ServerObject $mockServerObject -DatabaseName 'AdventureWorks' -Name 'db_datareader' -ExcludeFixedRoles - $result | Should -BeFalse + $result | Should-BeFalse } } } diff --git a/tests/Unit/Public/Test-SqlDscIsLogin.Tests.ps1 b/tests/Unit/Public/Test-SqlDscIsLogin.Tests.ps1 index b2de941c1..da015c2f2 100644 --- a/tests/Unit/Public/Test-SqlDscIsLogin.Tests.ps1 +++ b/tests/Unit/Public/Test-SqlDscIsLogin.Tests.ps1 @@ -64,7 +64,7 @@ Describe 'Test-SqlDscIsLogin' -Tag 'Public' { It 'Should return $false' { $result = Test-SqlDscIsLogin -ServerObject $mockServerObject -Name 'UnknownUser' - $result | Should -BeFalse + $result | Should-BeFalse } } @@ -82,14 +82,14 @@ Describe 'Test-SqlDscIsLogin' -Tag 'Public' { It 'Should return $true' { $result = Test-SqlDscIsLogin -ServerObject $mockServerObject -Name 'DOMAIN\MyLogin' - $result | Should -BeTrue + $result | Should-BeTrue } Context 'When passing ServerObject over the pipeline' { It 'Should return $true' { $result = $mockServerObject | Test-SqlDscIsLogin -Name 'DOMAIN\MyLogin' - $result | Should -BeTrue + $result | Should-BeTrue } } } diff --git a/tests/Unit/Public/Test-SqlDscIsSupportedFeature.Tests.ps1 b/tests/Unit/Public/Test-SqlDscIsSupportedFeature.Tests.ps1 index 5754777e4..ce5520831 100644 --- a/tests/Unit/Public/Test-SqlDscIsSupportedFeature.Tests.ps1 +++ b/tests/Unit/Public/Test-SqlDscIsSupportedFeature.Tests.ps1 @@ -52,57 +52,57 @@ AfterAll { Describe 'Test-SqlDscIsSupportedFeature' -Tag 'Public' { Context 'When testing a feature that is not specified as neither added or removed' { It 'Should return $true for major version <_>' -ForEach @(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 999) { - Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion $_ | Should -BeTrue + Test-SqlDscIsSupportedFeature -Feature 'SQLENGINE' -ProductVersion $_ | Should-BeTrue } } Context 'When a feature has been removed for the target major version' { It 'Should return $false' { - Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion 14 | Should -BeFalse + Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion 14 | Should-BeFalse } } Context 'When a feature has been removed in a previous major version than target major version' { It 'Should return $false' { - Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion 999 | Should -BeFalse + Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion 999 | Should-BeFalse } } Context 'When a feature has been remove in a newer major version than target major version' { It 'Should return $true' { - Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion 13 | Should -BeTrue + Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion 13 | Should-BeTrue } } Context 'When a feature has been added in a newer major version than target major version' { It 'Should return $false' { - Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion 14 | Should -BeFalse + Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion 14 | Should-BeFalse } } Context 'When a feature has been added for the target major version' { It 'Should return $true' { - Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion 15 | Should -BeTrue + Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion 15 | Should-BeTrue } } Context 'When a feature has been added in a previous major version than target major version' { It 'Should return $true' { - Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion 999 | Should -BeTrue + Test-SqlDscIsSupportedFeature -Feature 'PolyBaseCore' -ProductVersion 999 | Should-BeTrue } } Context 'When a feature is only supported by a specific major version' { It 'Should return $true for the supported major version' { - Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion 15 | Should -BeTrue + Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion 15 | Should-BeTrue } It 'Should return $false for a newer major version' { - Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion 16 | Should -BeFalse + Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion 16 | Should-BeFalse } It 'Should return $false for an older major version' { - Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion 14 | Should -BeFalse + Test-SqlDscIsSupportedFeature -Feature 'PolyBaseJava' -ProductVersion 14 | Should-BeFalse } } } diff --git a/tests/Unit/Public/Uninstall-SqlDscServer.Tests.ps1 b/tests/Unit/Public/Uninstall-SqlDscServer.Tests.ps1 index 19fa0ab4a..d687e01e8 100644 --- a/tests/Unit/Public/Uninstall-SqlDscServer.Tests.ps1 +++ b/tests/Unit/Public/Uninstall-SqlDscServer.Tests.ps1 @@ -70,8 +70,8 @@ Describe 'Uninstall-SqlDscServer' -Tag 'Public' { } ) - $result.ParameterSetName | Should -Be $MockParameterSetName - $result.ParameterListAsString | Should -Be $MockExpectedParameters + $result.ParameterSetName | Should-Be $MockParameterSetName + $result.ParameterListAsString | Should-Be $MockExpectedParameters } Context 'When setup action is ''Uninstall''' { @@ -104,14 +104,11 @@ Describe 'Uninstall-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Uninstall-SqlDscServer -Confirm:$false @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Uninstall' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Uninstall' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -119,14 +116,11 @@ Describe 'Uninstall-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Uninstall-SqlDscServer -Force @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -ParameterFilter { - $ArgumentList | Should -MatchExactly '\/ACTION=Uninstall' - $ArgumentList | Should -MatchExactly '\/FEATURES=SQLENGINE' - $ArgumentList | Should -MatchExactly '\/INSTANCENAME="INSTANCE"' # cspell: disable-line - - # Return $true if none of the above throw. - $true - } -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -ParameterFilter { + $ArgumentList -match '\/ACTION=Uninstall' -and + $ArgumentList -match '\/FEATURES=SQLENGINE' -and + $ArgumentList -match '\/INSTANCENAME="INSTANCE"' # cspell: disable-line + } -Scope It -Times 1 } } @@ -134,7 +128,7 @@ Describe 'Uninstall-SqlDscServer' -Tag 'Public' { It 'Should call the mock with the correct argument string' { Uninstall-SqlDscServer -WhatIf @mockDefaultParameters - Should -Invoke -CommandName Start-SqlSetupProcess -Exactly -Times 0 -Scope It + Should-Invoke -CommandName Start-SqlSetupProcess -Exactly -Scope It -Times 0 } } } diff --git a/tests/Unit/SqlServerDsc.AnalyzerRules.Tests.ps1 b/tests/Unit/SqlServerDsc.AnalyzerRules.Tests.ps1 index 762827cf3..d7462c023 100644 --- a/tests/Unit/SqlServerDsc.AnalyzerRules.Tests.ps1 +++ b/tests/Unit/SqlServerDsc.AnalyzerRules.Tests.ps1 @@ -115,14 +115,14 @@ Describe 'Measure-CommandsNeededToLoadSMO' { $mockAst = Get-AstFromDefinition -ScriptDefinition $definition -AstType $astType - $mockAst | Should -Not -BeNullOrEmpty + $mockAst | Should-BeTruthy # We should evaluate the second function in the script definition. $record = Measure-CommandsNeededToLoadSMO -FunctionAst $mockAst[1] - ($record | Measure-Object).Count | Should -Be 1 - $record.Message | Should -Be $expectedErrorRecordMessage - $record.RuleName | Should -Be $ruleName + ($record | Measure-Object) | Should-BeCollection -Count 1 + $record.Message | Should-Be $expectedErrorRecordMessage + $record.RuleName | Should-Be $ruleName } } @@ -145,12 +145,12 @@ Describe 'Measure-CommandsNeededToLoadSMO' { $mockAst = Get-AstFromDefinition -ScriptDefinition $definition -AstType $astType - $mockAst | Should -Not -BeNullOrEmpty + $mockAst | Should-BeTruthy # We should evaluate the second function in the script definition. $record = Measure-CommandsNeededToLoadSMO -FunctionAst $mockAst[1] - $record | Should -BeNullOrEmpty + $record | Should-BeFalsy } } @@ -173,12 +173,12 @@ Describe 'Measure-CommandsNeededToLoadSMO' { $mockAst = Get-AstFromDefinition -ScriptDefinition $definition -AstType $astType - $mockAst | Should -Not -BeNullOrEmpty + $mockAst | Should-BeTruthy # We should evaluate the second function in the script definition. $record = Measure-CommandsNeededToLoadSMO -FunctionAst $mockAst[1] - $record | Should -BeNullOrEmpty + $record | Should-BeFalsy } } } @@ -210,9 +210,10 @@ Describe 'Measure-CommandsNeededToLoadSMO' { " $record = Invoke-ScriptAnalyzer @invokeScriptAnalyzerParameters - ($record | Measure-Object).Count | Should -BeExactly 1 - $record.Message | Should -Be $expectedErrorRecordMessage - $record.RuleName | Should -Be $ruleName + + ($record | Measure-Object) | Should-BeCollection -Count 1 + $record.Message | Should-Be $expectedErrorRecordMessage + $record.RuleName | Should-Be $ruleName } } @@ -230,9 +231,10 @@ Describe 'Measure-CommandsNeededToLoadSMO' { " $record = Invoke-ScriptAnalyzer @invokeScriptAnalyzerParameters - ($record | Measure-Object).Count | Should -BeExactly 1 - $record.Message | Should -Be $expectedErrorRecordMessage - $record.RuleName | Should -Be $ruleName + + ($record | Measure-Object) | Should-BeCollection -Count 1 + $record.Message | Should-Be $expectedErrorRecordMessage + $record.RuleName | Should-Be $ruleName } } @@ -254,7 +256,7 @@ Describe 'Measure-CommandsNeededToLoadSMO' { " $record = Invoke-ScriptAnalyzer @invokeScriptAnalyzerParameters - $record | Should -BeNullOrEmpty + $record | Should-BeFalsy } } @@ -276,7 +278,7 @@ Describe 'Measure-CommandsNeededToLoadSMO' { " $record = Invoke-ScriptAnalyzer @invokeScriptAnalyzerParameters - $record | Should -BeNullOrEmpty + $record | Should-BeFalsy } } } diff --git a/tests/Unit/SqlServerDsc.Common.Tests.ps1 b/tests/Unit/SqlServerDsc.Common.Tests.ps1 index 960bb8fee..4164ecdf4 100644 --- a/tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -101,9 +101,9 @@ Describe 'SqlServerDsc.Common\Get-RegistryPropertyValue' -Tag 'GetRegistryProper It 'Should return $null' { $result = Get-RegistryPropertyValue -Path $mockWrongRegistryPath -Name $mockPropertyName - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It -Module $script:subModuleName + Should-Invoke -CommandName Get-ItemProperty -Exactly -ModuleName $script:subModuleName -Scope It -Times 1 } } @@ -116,9 +116,9 @@ Describe 'SqlServerDsc.Common\Get-RegistryPropertyValue' -Tag 'GetRegistryProper It 'Should not throw an error, but return $null' { $result = Get-RegistryPropertyValue -Path $mockWrongRegistryPath -Name $mockPropertyName - $result | Should -BeNullOrEmpty + $result | Should-BeFalsy - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ItemProperty -Exactly -Scope It -Times 1 } } @@ -138,9 +138,9 @@ Describe 'SqlServerDsc.Common\Get-RegistryPropertyValue' -Tag 'GetRegistryProper It 'Should return the correct value' { $result = Get-RegistryPropertyValue -Path $mockCorrectRegistryPath -Name $mockPropertyName - $result | Should -Be $mockPropertyValue + $result | Should-Be $mockPropertyValue - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-ItemProperty -Exactly -Scope It -Times 1 } } } @@ -156,28 +156,28 @@ Describe 'SqlServerDsc.Common\Format-Path' -Tag 'FormatPath' { Context 'When there is a path that is wrongly formatted, but now formatting was requested' { It 'Should return the same wrongly formatted path' { $result = Format-Path -Path $mockPathWithTrailingBackslash - $result | Should -BeExactly $mockPathWithTrailingBackslash + $result | Should-BeString -CaseSensitive $mockPathWithTrailingBackslash } } Context 'When there is a path that is formatted correctly, and using TrailingSlash' { It 'Should return the same path' { $result = Format-Path -Path $mockCorrectPath -TrailingSlash - $result | Should -BeExactly $mockCorrectPath + $result | Should-BeString -CaseSensitive $mockCorrectPath } } Context 'When there is a path that has a trailing backslash, and using TrailingSlash' { It 'Should return the path without trailing backslash' { $result = Format-Path -Path $mockPathWithTrailingBackslash -TrailingSlash - $result | Should -BeExactly $mockCorrectPath + $result | Should-BeString -CaseSensitive $mockCorrectPath } } Context 'When there is a path that has only a qualifier, and using TrailingSlash' { It 'Should return the path with trailing backslash after the qualifier' { $result = Format-Path -Path $mockPathWithOnlyQualifier -TrailingSlash - $result | Should -BeExactly $mockCorrectQualifierPath + $result | Should-BeString -CaseSensitive $mockCorrectQualifierPath } } } @@ -256,10 +256,10 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should not use Unbuffered IO when copying' { @@ -278,10 +278,10 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } } @@ -332,12 +332,12 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' $mockLocalizedString -f $mockStartSqlSetupProcessExitCode ) - $mockErrorMessage.Exception.Message | Should -Not -BeNullOrEmpty + $mockErrorMessage.Exception.Message | Should-BeTruthy - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Throw -ExpectedMessage $mockErrorMessage + { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should throw the correct error message when error code is 16' { @@ -357,12 +357,12 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' $mockLocalizedString -f $mockStartSqlSetupProcessExitCode ) - $mockErrorMessage.Exception.Message | Should -Not -BeNullOrEmpty + $mockErrorMessage.Exception.Message | Should-BeTruthy - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Throw -ExpectedMessage $mockErrorMessage + { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should throw the correct error message when error code is greater than 7 (but not 8 or 16)' { @@ -381,12 +381,12 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' $mockLocalizedString -f $mockStartSqlSetupProcessExitCode ) - $mockErrorMessage | Should -Not -BeNullOrEmpty + $mockErrorMessage | Should-BeTruthy - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Throw -ExpectedMessage $mockErrorMessage + { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } } @@ -399,8 +399,8 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' } AfterEach { - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should finish successfully with exit code 1' { @@ -411,10 +411,10 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should finish successfully with exit code 2' { @@ -425,10 +425,10 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should finish successfully with exit code 3' { @@ -439,7 +439,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPath } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) } } @@ -452,8 +452,8 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' } AfterEach { - Should -Invoke -CommandName Get-Command -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Start-Process -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-Command -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Process -Exactly -Scope It -Times 1 } It 'Should finish successfully with exit code 1' { @@ -464,7 +464,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPathWithSpaces } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) } It 'Should finish successfully with exit code 2' { @@ -475,7 +475,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPathWithSpaces } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) } It 'Should finish successfully with exit code 3' { @@ -486,7 +486,7 @@ Describe 'SqlServerDsc.Common\Copy-ItemWithRobocopy' -Tag 'CopyItemWithRobocopy' DestinationPath = $mockRobocopyArgumentDestinationPathWithSpaces } - { Copy-ItemWithRobocopy @copyItemWithRobocopyParameter } | Should -Not -Throw + $null = & ({ Copy-ItemWithRobocopy @copyItemWithRobocopyParameter }) } } } @@ -529,20 +529,20 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } It 'Should call the correct mocks' { - { + $null = & ({ $invokeInstallationMediaCopyParameters = @{ SourcePath = $mockSourcePathUNCWithLeaf SourceCredential = $mockShareCredential } Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Guid -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Get-TemporaryFolder -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Copy-ItemWithRobocopy -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Guid -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Get-TemporaryFolder -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Copy-ItemWithRobocopy -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 1 } It 'Should return the correct destination path' { @@ -554,7 +554,7 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla $invokeInstallationMediaCopyResult = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - $invokeInstallationMediaCopyResult | Should -Be ('{0}\leaf' -f $mockDestinationPath) + $invokeInstallationMediaCopyResult | Should-Be ('{0}\leaf' -f $mockDestinationPath) } } @@ -568,20 +568,20 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } It 'Should call the correct mocks' { - { + $null = & ({ $invokeInstallationMediaCopyParameters = @{ SourcePath = $mockSourcePathUNCWithLeaf SourceCredential = $mockShareCredential } Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Guid -Exactly -Times 0 -Scope It - Should -Invoke -CommandName Get-TemporaryFolder -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Copy-ItemWithRobocopy -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Guid -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Get-TemporaryFolder -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Copy-ItemWithRobocopy -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 1 } It 'Should return the correct destination path' { @@ -593,7 +593,7 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla $invokeInstallationMediaCopyResult = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - $invokeInstallationMediaCopyResult | Should -Be ('{0}\secondleaf' -f $mockDestinationPath) + $invokeInstallationMediaCopyResult | Should-Be ('{0}\secondleaf' -f $mockDestinationPath) } } @@ -607,20 +607,20 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } It 'Should call the correct mocks' { - { + $null = & ({ $invokeInstallationMediaCopyParameters = @{ SourcePath = $mockSourcePathUNC SourceCredential = $mockShareCredential } Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName Connect-UncPath -Exactly -Times 1 -Scope It - Should -Invoke -CommandName New-Guid -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-TemporaryFolder -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Copy-ItemWithRobocopy -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Disconnect-UncPath -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Connect-UncPath -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Guid -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-TemporaryFolder -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Copy-ItemWithRobocopy -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Disconnect-UncPath -Exactly -Scope It -Times 1 } It 'Should return the correct destination path' { @@ -631,7 +631,7 @@ Describe 'SqlServerDsc.Common\Invoke-InstallationMediaCopy' -Tag 'InvokeInstalla } $invokeInstallationMediaCopyResult = Invoke-InstallationMediaCopy @invokeInstallationMediaCopyParameters - $invokeInstallationMediaCopyResult | Should -Be ('{0}\{1}' -f $mockDestinationPath, $mockSourcePathGuid) + $invokeInstallationMediaCopyResult | Should-Be ('{0}\{1}' -f $mockDestinationPath, $mockSourcePathGuid) } } } @@ -700,15 +700,15 @@ 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' { - { + $null = & ({ $connectUncPathParameters = @{ RemotePath = $mockSourcePathUNC } Connect-UncPath @connectUncPathParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName New-SmbMapping -ParameterFilter { + Should-Invoke -CommandName New-SmbMapping -Exactly -ParameterFilter { <# Due to issue https://github.com/pester/Pester/issues/1542 we must use `$null -ne $UserName` instead of @@ -716,43 +716,43 @@ Describe 'SqlServerDsc.Common\Connect-UncPath' -Tag 'ConnectUncPath' { #> $RemotePath -eq $mockSourcePathUNC ` -and $null -eq $UserName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } Context 'When connecting to a UNC path with specific credentials' { It 'Should call the correct mocks' { - { + $null = & ({ $connectUncPathParameters = @{ RemotePath = $mockSourcePathUNC SourceCredential = $mockShareCredential } Connect-UncPath @connectUncPathParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName New-SmbMapping -ParameterFilter { + Should-Invoke -CommandName New-SmbMapping -Exactly -ParameterFilter { $RemotePath -eq $mockSourcePathUNC ` -and $UserName -eq $mockShareCredentialUserName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } Context 'When connecting using Fully Qualified Domain Name (FQDN)' { It 'Should call the correct mocks' { - { + $null = & ({ $connectUncPathParameters = @{ RemotePath = $mockSourcePathUNC SourceCredential = $mockFqdnShareCredential } Connect-UncPath @connectUncPathParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName New-SmbMapping -ParameterFilter { + Should-Invoke -CommandName New-SmbMapping -Exactly -ParameterFilter { $RemotePath -eq $mockSourcePathUNC ` -and $UserName -eq $mockFqdnShareCredentialUserName - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -765,7 +765,7 @@ Describe 'SqlServerDsc.Common\Connect-UncPath' -Tag 'ConnectUncPath' { } $connectUncPathResult = Connect-UncPath @connectUncPathParameters - $connectUncPathResult.RemotePath | Should -Be $mockSourcePathUNC + $connectUncPathResult.RemotePath | Should-Be $mockSourcePathUNC } } } @@ -793,15 +793,15 @@ Describe 'SqlServerDsc.Common\Disconnect-UncPath' -Tag 'DisconnectUncPath' { Context 'When disconnecting from an UNC path' { It 'Should call the correct mocks' { - { + $null = & ({ $disconnectUncPathParameters = @{ RemotePath = $mockSourcePathUNC } Disconnect-UncPath @disconnectUncPathParameters - } | Should -Not -Throw + }) - Should -Invoke -CommandName Remove-SmbMapping -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Remove-SmbMapping -Exactly -Scope It -Times 1 } } } @@ -816,9 +816,9 @@ Describe 'SqlServerDsc.Common\Test-PendingRestart' -Tag 'TestPendingRestart' { It 'Should return $true' { $testPendingRestartResult = Test-PendingRestart - $testPendingRestartResult | Should -BeTrue + $testPendingRestartResult | Should-BeTrue - Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -Scope It -Times 1 } } @@ -829,9 +829,9 @@ Describe 'SqlServerDsc.Common\Test-PendingRestart' -Tag 'TestPendingRestart' { It 'Should return $true' { $testPendingRestartResult = Test-PendingRestart - $testPendingRestartResult | Should -BeFalse + $testPendingRestartResult | Should-BeFalse - Should -Invoke -CommandName Get-RegistryPropertyValue -Exactly -Times 1 -Scope It + Should-Invoke -CommandName Get-RegistryPropertyValue -Exactly -Scope It -Times 1 } } } @@ -856,7 +856,7 @@ Describe 'SqlServerDsc.Common\Start-SqlSetupProcess' -Tag 'StartSqlSetupProcess' } $processExitCode = Start-SqlSetupProcess @startSqlSetupProcessParameters - $processExitCode | Should -BeExactly 0 + $processExitCode | Should-BeString -CaseSensitive 0 } } @@ -868,7 +868,7 @@ Describe 'SqlServerDsc.Common\Start-SqlSetupProcess' -Tag 'StartSqlSetupProcess' Timeout = 2 } - { Start-SqlSetupProcess @startSqlSetupProcessParameters } | Should -Throw -ErrorId 'ProcessNotTerminated,Microsoft.PowerShell.Commands.WaitProcessCommand' + { Start-SqlSetupProcess @startSqlSetupProcessParameters } | Should-Throw -FullyQualifiedErrorId 'ProcessNotTerminated,Microsoft.PowerShell.Commands.WaitProcessCommand' } } } @@ -936,9 +936,9 @@ 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' }) - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { <# Make sure we assert just the first call to Connect-SQL. @@ -946,19 +946,19 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { we cannot use `$PSBoundParameters.ContainsKey('ErrorAction') -eq $false`. #> $ErrorAction -ne 'SilentlyContinue' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Restart-SqlClusterService -Scope It -Exactly -Times 0 -ModuleName $subModuleName - Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Restart-SqlClusterService -Exactly -ModuleName $subModuleName -Scope It -Times 0 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 1 } 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 }) - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { <# Make sure we assert just the first call to Connect-SQL. @@ -966,20 +966,20 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { we cannot use `$PSBoundParameters.ContainsKey('ErrorAction') -eq $false`. #> $ErrorAction -ne 'SilentlyContinue' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 - Should -Invoke -CommandName Restart-SqlClusterService -Scope It -Exactly -Times 0 -ModuleName $subModuleName - Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Restart-SqlClusterService -Exactly -ModuleName $subModuleName -Scope It -Times 0 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 1 } } 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 }) - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { <# Make sure we assert just the first call to Connect-SQL. @@ -987,9 +987,9 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { we cannot use `$PSBoundParameters.ContainsKey('ErrorAction') -eq $false`. #> $ErrorAction -ne 'SilentlyContinue' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { <# Make sure we assert the second call to Connect-SQL @@ -997,12 +997,12 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { we cannot use `$PSBoundParameters.ContainsKey('ErrorAction') -eq $true`. #> $ErrorAction -eq 'SilentlyContinue' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 - Should -Invoke -CommandName Restart-SqlClusterService -Scope It -Exactly -Times 0 -ModuleName $subModuleName - Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Restart-SqlClusterService -Exactly -ModuleName $subModuleName -Scope It -Times 0 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 1 } } } @@ -1025,9 +1025,9 @@ 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' }) - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -Exactly -ParameterFilter { <# Make sure we assert just the first call to Connect-SQL. @@ -1035,39 +1035,39 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { we cannot use `$PSBoundParameters.ContainsKey('ErrorAction') -eq $false`. #> $ErrorAction -ne 'SilentlyContinue' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Restart-SqlClusterService -Scope It -Exactly -Times 1 -ModuleName $subModuleName - Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 0 - Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 0 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Restart-SqlClusterService -Exactly -ModuleName $subModuleName -Scope It -Times 1 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Restart-Service -Exactly -Scope It -Times 0 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 0 } 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 }) - Should -Invoke -CommandName Restart-SqlClusterService -ParameterFilter { + Should-Invoke -CommandName Restart-SqlClusterService -Exactly -ModuleName $subModuleName -ParameterFilter { <# Due to issue https://github.com/pester/Pester/issues/1542 we cannot use `$PSBoundParameters.ContainsKey('Timeout') -eq $true`. #> $null -ne $Timeout - } -Scope It -Exactly -Times 1 -ModuleName $subModuleName + } -Scope It -Times 1 } } 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') }) - Should -Invoke -CommandName Restart-SqlClusterService -ParameterFilter { + Should-Invoke -CommandName Restart-SqlClusterService -Exactly -ModuleName $subModuleName -ParameterFilter { <# Due to issue https://github.com/pester/Pester/issues/1542 we cannot use `$PSBoundParameters.ContainsKey('OwnerNode') -eq $true`. #> $null -ne $OwnerNode - } -Scope It -Exactly -Times 1 -ModuleName $subModuleName + } -Scope It -Times 1 } } } @@ -1097,11 +1097,11 @@ 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 }) - Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 0 } } @@ -1137,11 +1137,11 @@ 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 }) - Should -Invoke -CommandName Get-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Restart-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Restart-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 0 } } @@ -1181,17 +1181,17 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { ($mockLocalizedString -f (Get-ComputerName), 'MSSQLSERVER', 4) + '*Mock connection error*' ) - $mockErrorMessage.Exception.Message | Should -Not -BeNullOrEmpty + $mockErrorMessage.Exception.Message | Should-BeTruthy { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -Timeout 4 -SkipClusterCheck - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage <# Not using -Exactly to handle when CI is slower, result is that there are 3 calls to Connect-SQL. #> - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -ParameterFilter { <# Make sure we assert the second call to Connect-SQL @@ -1242,17 +1242,17 @@ Describe 'SqlServerDsc.Common\Restart-SqlService' -Tag 'RestartSqlService' { $mockLocalizedString -f (Get-ComputerName), 'MSSQLSERVER', 4 ) - $mockErrorMessage.Exception.Message | Should -Not -BeNullOrEmpty + $mockErrorMessage.Exception.Message | Should-BeTruthy { Restart-SqlService -ServerName (Get-ComputerName) -InstanceName 'MSSQLSERVER' -Timeout 4 -SkipClusterCheck - } | Should -Throw -ExpectedMessage $mockErrorMessage + } | Should-Throw -ExceptionMessage $mockErrorMessage <# Not using -Exactly to handle when CI is slower, result is that there are 3 calls to Connect-SQL. #> - Should -Invoke -CommandName Connect-SQL -ParameterFilter { + Should-Invoke -CommandName Connect-SQL -ParameterFilter { <# Make sure we assert the second call to Connect-SQL @@ -1278,10 +1278,10 @@ 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' }) } - Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 } } @@ -1307,19 +1307,19 @@ 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' }) } - Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 0 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 } } @@ -1356,23 +1356,23 @@ 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' }) } - Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server Agent (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 } } @@ -1408,23 +1408,23 @@ 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' }) } - Should -Invoke -CommandName Get-CimInstance -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' -and $InputObject.Name -eq 'SQL Server (DSCTEST)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server (DSCTEST)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server Agent (DSCTEST)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 } } } @@ -1461,19 +1461,19 @@ 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 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 } } @@ -1512,23 +1512,23 @@ 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 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server Agent (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 } } @@ -1566,23 +1566,23 @@ 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 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server Agent (MSSQLSERVER)' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 } } @@ -1620,23 +1620,23 @@ 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 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 1 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server (MSSQLSERVER)' - } -Scope It -Exactly -Times 1 + } -Scope It -Times 1 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' -and $InputObject.Name -eq 'SQL Server Agent (MSSQLSERVER)' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 } } @@ -1663,19 +1663,19 @@ 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 - Should -Invoke -CommandName Get-CimAssociatedInstance -Scope It -Exactly -Times 0 + Should-Invoke -CommandName Get-CimInstance -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Get-CimAssociatedInstance -Exactly -Scope It -Times 0 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'TakeOffline' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 - Should -Invoke -CommandName Invoke-CimMethod -ParameterFilter { + Should-Invoke -CommandName Invoke-CimMethod -Exactly -ParameterFilter { $MethodName -eq 'BringOnline' - } -Scope It -Exactly -Times 0 + } -Scope It -Times 0 } } } @@ -1747,11 +1747,10 @@ 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 ` - -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter + Should-Invoke -CommandName Import-SqlDscPreferredModule -Exactly -Scope It -Times 1 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } Context 'When Connected status is $false' { @@ -1772,7 +1771,7 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { $mockLocalizedString -f $mockComputerName ) - { Connect-SQLAnalysis -FeatureFlag 'AnalysisServicesConnection' } | Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + { Connect-SQLAnalysis -FeatureFlag 'AnalysisServicesConnection' } | Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } } } @@ -1781,7 +1780,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' }) } } @@ -1789,7 +1788,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' }) } } } @@ -1803,10 +1802,9 @@ 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 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } @@ -1814,10 +1812,9 @@ 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 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } @@ -1826,10 +1823,9 @@ 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 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } @@ -1837,10 +1833,9 @@ 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 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } @@ -1848,10 +1843,9 @@ 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 + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } } @@ -1871,10 +1865,9 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { $mockLocalizedString -f $mockComputerName ) - { Connect-SQLAnalysis } | Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + { Connect-SQLAnalysis } | Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } @@ -1893,10 +1886,9 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { $mockLocalizedString -f $mockComputerName ) - { Connect-SQLAnalysis } | Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + { Connect-SQLAnalysis } | Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 # Setting it back to the default so it does not disturb other tests. $mockThrowInvalidOperation = $false @@ -1921,10 +1913,9 @@ Describe 'SqlServerDsc.Common\Connect-SQLAnalysis' -Tag 'ConnectSQLAnalysis' { $mockLocalizedString -f "$($testParameters.ServerName)\$($testParameters.InstanceName)" ) - { Connect-SQLAnalysis @testParameters } | Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + { Connect-SQLAnalysis @testParameters } | Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftAnalysisServicesServer_ParameterFilter -Scope It -Times 1 } } } @@ -1935,7 +1926,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' { @@ -1950,10 +1941,10 @@ Describe 'SqlServerDsc.Common\Update-AvailabilityGroupReplica' -Tag 'UpdateAvail $mockLocalizedString -f $availabilityReplica.Name ) - $mockErrorRecord.Exception.Message | Should -Not -BeNullOrEmpty + $mockErrorRecord.Exception.Message | Should-BeTruthy { Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityReplica } | - Should -Throw -ExpectedMessage ($mockErrorRecord.Exception.Message + '*') + Should-Throw -ExceptionMessage ($mockErrorRecord.Exception.Message + '*') } } } @@ -2018,18 +2009,18 @@ Describe 'SqlServerDsc.Common\Test-LoginEffectivePermissions' -Tag 'TestLoginEff $mockInvokeQueryPermissionsSet = $mockAllServerPermissionsPresent.Clone() $testLoginEffectiveServerPermissionsParams.Permissions = $mockAllServerPermissionsPresent.Clone() - Test-LoginEffectivePermissions @testLoginEffectiveServerPermissionsParams | Should -Be $true + Test-LoginEffectivePermissions @testLoginEffectiveServerPermissionsParams | Should-BeTrue - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } It 'Should return $true when the desired login permissions are present' { $mockInvokeQueryPermissionsSet = $mockAllLoginPermissionsPresent.Clone() $testLoginEffectiveLoginPermissionsParams.Permissions = $mockAllLoginPermissionsPresent.Clone() - Test-LoginEffectivePermissions @testLoginEffectiveLoginPermissionsParams | Should -Be $true + Test-LoginEffectivePermissions @testLoginEffectiveLoginPermissionsParams | Should-BeTrue - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } @@ -2038,36 +2029,36 @@ Describe 'SqlServerDsc.Common\Test-LoginEffectivePermissions' -Tag 'TestLoginEff $mockInvokeQueryPermissionsSet = $mockServerPermissionsMissing.Clone() $testLoginEffectiveServerPermissionsParams.Permissions = $mockAllServerPermissionsPresent.Clone() - Test-LoginEffectivePermissions @testLoginEffectiveServerPermissionsParams | Should -Be $false + Test-LoginEffectivePermissions @testLoginEffectiveServerPermissionsParams | Should-BeFalse - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } It 'Should return $false when the specified login has no server permissions assigned' { $mockInvokeQueryPermissionsSet = @() $testLoginEffectiveServerPermissionsParams.Permissions = $mockAllServerPermissionsPresent.Clone() - Test-LoginEffectivePermissions @testLoginEffectiveServerPermissionsParams | Should -Be $false + Test-LoginEffectivePermissions @testLoginEffectiveServerPermissionsParams | Should-BeFalse - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } It 'Should return $false when the desired login permissions are not present' { $mockInvokeQueryPermissionsSet = $mockLoginPermissionsMissing.Clone() $testLoginEffectiveLoginPermissionsParams.Permissions = $mockAllLoginPermissionsPresent.Clone() - Test-LoginEffectivePermissions @testLoginEffectiveLoginPermissionsParams | Should -Be $false + Test-LoginEffectivePermissions @testLoginEffectiveLoginPermissionsParams | Should-BeFalse - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } It 'Should return $false when the specified login has no login permissions assigned' { $mockInvokeQueryPermissionsSet = @() $testLoginEffectiveLoginPermissionsParams.Permissions = $mockAllLoginPermissionsPresent.Clone() - Test-LoginEffectivePermissions @testLoginEffectiveLoginPermissionsParams | Should -Be $false + Test-LoginEffectivePermissions @testLoginEffectiveLoginPermissionsParams | Should-BeFalse - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } } @@ -2119,13 +2110,11 @@ Describe 'SqlServerDsc.Common\Get-SqlInstanceMajorVersion' -Tag 'GetSqlInstanceM Context 'When calling Get-SqlInstanceMajorVersion' { It 'Should return the correct major SQL version number' { $result = Get-SqlInstanceMajorVersion -InstanceName $mockInstanceName - $result | Should -Be $mockSqlMajorVersion + $result | Should-Be $mockSqlMajorVersion - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_InstanceNames_SQL + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_InstanceNames_SQL -Scope It -Times 1 - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_FullInstanceId_Setup + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_FullInstanceId_Setup -Scope It -Times 1 } } @@ -2145,15 +2134,13 @@ Describe 'SqlServerDsc.Common\Get-SqlInstanceMajorVersion' -Tag 'GetSqlInstanceM $mockLocalizedString -f $mockInstanceName ) - $mockErrorMessage | Should -Not -BeNullOrEmpty + $mockErrorMessage | Should-BeTruthy - { Get-SqlInstanceMajorVersion -InstanceName $mockInstanceName } | Should -Throw -ExpectedMessage $mockErrorMessage + { Get-SqlInstanceMajorVersion -InstanceName $mockInstanceName } | Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_InstanceNames_SQL + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_InstanceNames_SQL -Scope It -Times 1 - Should -Invoke -CommandName Get-ItemProperty -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_FullInstanceId_Setup + Should-Invoke -CommandName Get-ItemProperty -Exactly -ParameterFilter $mockGetItemProperty_ParameterFilter_MicrosoftSQLServer_FullInstanceId_Setup -Scope It -Times 1 } } } @@ -2198,10 +2185,10 @@ Describe 'SqlServerDsc.Common\Get-PrimaryReplicaServerObject' -Tag 'GetPrimaryRe It 'Should return the same server object that was supplied' { $result = Get-PrimaryReplicaServerObject -ServerObject $mockServerObject -AvailabilityGroup $mockAvailabilityGroup - $result.DomainInstanceName | Should -Be $mockServerObject.DomainInstanceName - $result.DomainInstanceName | Should -Be $mockAvailabilityGroup.PrimaryReplicaServerName + $result.DomainInstanceName | Should-Be $mockServerObject.DomainInstanceName + $result.DomainInstanceName | Should-Be $mockAvailabilityGroup.PrimaryReplicaServerName - Should -Invoke -CommandName Connect-SQL -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } It 'Should return the same server object that was supplied when the PrimaryReplicaServerNameProperty is empty' { @@ -2209,10 +2196,10 @@ Describe 'SqlServerDsc.Common\Get-PrimaryReplicaServerObject' -Tag 'GetPrimaryRe $result = Get-PrimaryReplicaServerObject -ServerObject $mockServerObject -AvailabilityGroup $mockAvailabilityGroup - $result.DomainInstanceName | Should -Be $mockServerObject.DomainInstanceName - $result.DomainInstanceName | Should -Not -Be $mockAvailabilityGroup.PrimaryReplicaServerName + $result.DomainInstanceName | Should-Be $mockServerObject.DomainInstanceName + $result.DomainInstanceName | Should-NotBe $mockAvailabilityGroup.PrimaryReplicaServerName - Should -Invoke -CommandName Connect-SQL -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 0 } } @@ -2222,10 +2209,10 @@ Describe 'SqlServerDsc.Common\Get-PrimaryReplicaServerObject' -Tag 'GetPrimaryRe $result = Get-PrimaryReplicaServerObject -ServerObject $mockServerObject -AvailabilityGroup $mockAvailabilityGroup - $result.DomainInstanceName | Should -Not -Be $mockServerObject.DomainInstanceName - $result.DomainInstanceName | Should -Be $mockAvailabilityGroup.PrimaryReplicaServerName + $result.DomainInstanceName | Should-NotBe $mockServerObject.DomainInstanceName + $result.DomainInstanceName | Should-Be $mockAvailabilityGroup.PrimaryReplicaServerName - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 } } } @@ -2274,20 +2261,20 @@ Describe 'SqlServerDsc.Common\Test-AvailabilityReplicaSeedingModeAutomatic' -Tag It 'Should return $false when the instance version is <_>' -ForEach @(11, 12) { $mockSqlVersion = $_ - Test-AvailabilityReplicaSeedingModeAutomatic @testAvailabilityReplicaSeedingModeAutomaticParams | Should -Be $false + Test-AvailabilityReplicaSeedingModeAutomatic @testAvailabilityReplicaSeedingModeAutomaticParams | Should-BeFalse - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 0 } # Test SQL 2016 and later where Seeding Mode is supported. It 'Should return $false when the instance version is <_> and the replica seeding mode is manual' -ForEach @(13, 14, 15) { $mockSqlVersion = $_ - Test-AvailabilityReplicaSeedingModeAutomatic @testAvailabilityReplicaSeedingModeAutomaticParams | Should -Be $false + Test-AvailabilityReplicaSeedingModeAutomatic @testAvailabilityReplicaSeedingModeAutomaticParams | Should-BeFalse - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } @@ -2302,10 +2289,10 @@ Describe 'SqlServerDsc.Common\Test-AvailabilityReplicaSeedingModeAutomatic' -Tag $mockSqlVersion = $_ $mockDynamic_SeedingMode = 'Automatic' - Test-AvailabilityReplicaSeedingModeAutomatic @testAvailabilityReplicaSeedingModeAutomaticParams | Should -Be $true + Test-AvailabilityReplicaSeedingModeAutomatic @testAvailabilityReplicaSeedingModeAutomaticParams | Should-BeTrue - Should -Invoke -CommandName Connect-SQL -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Invoke-SqlDscQuery -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Connect-SQL -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Invoke-SqlDscQuery -Exactly -Scope It -Times 1 } } } @@ -2347,50 +2334,50 @@ Describe 'SqlServerDsc.Common\Test-ImpersonatePermissions' -Tag 'TestImpersonate Context 'When impersonate permissions are present for the login' { It 'Should return true when the impersonate any login permissions are present for the login' { Mock -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -MockWith { $true } - Test-ImpersonatePermissions -ServerObject $mockServerObject | Should -Be $true + Test-ImpersonatePermissions -ServerObject $mockServerObject | Should-BeTrue - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -Scope It -Times 1 } It 'Should return true when the control server permissions are present for the login' { Mock -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -MockWith { $true } - Test-ImpersonatePermissions -ServerObject $mockServerObject | Should -Be $true + Test-ImpersonatePermissions -ServerObject $mockServerObject | Should-BeTrue - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -Scope It -Times 1 } It 'Should return true when the impersonate login permissions are present for the login' { Mock -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -MockWith { $true } - Test-ImpersonatePermissions -ServerObject $mockServerObject -SecurableName 'Login1' | Should -Be $true + Test-ImpersonatePermissions -ServerObject $mockServerObject -SecurableName 'Login1' | Should-BeTrue - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -Scope It -Times 1 } It 'Should return true when the control login permissions are present for the login' { Mock -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -MockWith { $true } - Test-ImpersonatePermissions -ServerObject $mockServerObject -SecurableName 'Login1' | Should -Be $true + Test-ImpersonatePermissions -ServerObject $mockServerObject -SecurableName 'Login1' | Should-BeTrue - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -Scope It -Times 1 } } Context 'When impersonate permissions are missing for the login' { It 'Should return false when the server permissions are missing for the login' { - Test-ImpersonatePermissions -ServerObject $mockServerObject | Should -Be $false + Test-ImpersonatePermissions -ServerObject $mockServerObject | Should-BeFalse - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -Scope It -Times 0 -Exactly - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -Scope It -Times 0 -Exactly + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -Scope It -Times 1 + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -Scope It -Times 1 + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -Scope It -Times 0 + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -Scope It -Times 0 } It 'Should return false when the login permissions are missing for the login' { - Test-ImpersonatePermissions -ServerObject $mockServerObject -SecurableName 'Login1' | Should -Be $false + Test-ImpersonatePermissions -ServerObject $mockServerObject -SecurableName 'Login1' | Should-BeFalse - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -Scope It -Times 1 -Exactly - Should -Invoke -CommandName Test-LoginEffectivePermissions -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -Scope It -Times 1 -Exactly + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateAnyLogin_ParameterFilter -Scope It -Times 1 + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ControlServer_ParameterFilter -Scope It -Times 1 + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ImpersonateLogin_ParameterFilter -Scope It -Times 1 + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter $mockTestLoginEffectivePermissions_ControlLogin_ParameterFilter -Scope It -Times 1 } } } @@ -2502,10 +2489,9 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL -ServerName $mockExpectedDatabaseEngineServer -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly $mockExpectedDatabaseEngineServer + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive $mockExpectedDatabaseEngineServer - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2522,13 +2508,12 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL -ServerName $mockExpectedDatabaseEngineServer -SetupCredential $mockSqlCredential -LoginType 'SqlLogin' -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.LoginSecure | Should -Be $false - $databaseEngineServerObject.ConnectionContext.Login | Should -Be $mockSqlCredentialUserName - $databaseEngineServerObject.ConnectionContext.SecurePassword | Should -Be $mockSqlCredentialSecurePassword - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly $mockExpectedDatabaseEngineServer + $databaseEngineServerObject.ConnectionContext.LoginSecure | Should-BeFalse + $databaseEngineServerObject.ConnectionContext.Login | Should-Be $mockSqlCredentialUserName + $databaseEngineServerObject.ConnectionContext.SecurePassword | Should-Be $mockSqlCredentialSecurePassword + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive $mockExpectedDatabaseEngineServer - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2545,10 +2530,9 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL -InstanceName $mockExpectedDatabaseEngineInstance -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2565,13 +2549,12 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL -InstanceName $mockExpectedDatabaseEngineInstance -SetupCredential $mockSqlCredential -LoginType 'SqlLogin' -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.LoginSecure | Should -Be $false - $databaseEngineServerObject.ConnectionContext.Login | Should -Be $mockSqlCredentialUserName - $databaseEngineServerObject.ConnectionContext.SecurePassword | Should -Be $mockSqlCredentialSecurePassword - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.LoginSecure | Should-BeFalse + $databaseEngineServerObject.ConnectionContext.Login | Should-Be $mockSqlCredentialUserName + $databaseEngineServerObject.ConnectionContext.SecurePassword | Should-Be $mockSqlCredentialSecurePassword + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2588,10 +2571,9 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL -ServerName $mockExpectedDatabaseEngineServer -InstanceName $mockExpectedDatabaseEngineInstance -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2616,15 +2598,14 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL @testParameters -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should -Be $true - $databaseEngineServerObject.ConnectionContext.ConnectAsUserPassword | Should -BeExactly $mockWinCredential.GetNetworkCredential().Password - $databaseEngineServerObject.ConnectionContext.ConnectAsUserName | Should -BeExactly $mockWinCredential.UserName - $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should -Be $true - $databaseEngineServerObject.ConnectionContext.LoginSecure | Should -Be $true + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should-BeTrue + $databaseEngineServerObject.ConnectionContext.ConnectAsUserPassword | Should-BeString -CaseSensitive $mockWinCredential.GetNetworkCredential().Password + $databaseEngineServerObject.ConnectionContext.ConnectAsUserName | Should-BeString -CaseSensitive $mockWinCredential.UserName + $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should-BeTrue + $databaseEngineServerObject.ConnectionContext.LoginSecure | Should-BeTrue - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2641,15 +2622,14 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL @testParameters -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should -Be $true - $databaseEngineServerObject.ConnectionContext.ConnectAsUserPassword | Should -BeExactly $mockWinCredential.GetNetworkCredential().Password - $databaseEngineServerObject.ConnectionContext.ConnectAsUserName | Should -BeExactly $mockWinCredential.UserName - $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should -Be $true - $databaseEngineServerObject.ConnectionContext.LoginSecure | Should -Be $true + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should-BeTrue + $databaseEngineServerObject.ConnectionContext.ConnectAsUserPassword | Should-BeString -CaseSensitive $mockWinCredential.GetNetworkCredential().Password + $databaseEngineServerObject.ConnectionContext.ConnectAsUserName | Should-BeString -CaseSensitive $mockWinCredential.UserName + $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should-BeTrue + $databaseEngineServerObject.ConnectionContext.LoginSecure | Should-BeTrue - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2665,15 +2645,14 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { It 'Should return the correct service instance' { $databaseEngineServerObject = Connect-SQL @testParameters -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should -Be $true - $databaseEngineServerObject.ConnectionContext.ConnectAsUserPassword | Should -BeExactly $mockWinFqdnCredential.GetNetworkCredential().Password - $databaseEngineServerObject.ConnectionContext.ConnectAsUserName | Should -BeExactly $mockWinFqdnCredential.UserName - $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should -Be $true - $databaseEngineServerObject.ConnectionContext.LoginSecure | Should -Be $true + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should-BeTrue + $databaseEngineServerObject.ConnectionContext.ConnectAsUserPassword | Should-BeString -CaseSensitive $mockWinFqdnCredential.GetNetworkCredential().Password + $databaseEngineServerObject.ConnectionContext.ConnectAsUserName | Should-BeString -CaseSensitive $mockWinFqdnCredential.UserName + $databaseEngineServerObject.ConnectionContext.ConnectAsUser | Should-BeTrue + $databaseEngineServerObject.ConnectionContext.LoginSecure | Should-BeTrue - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } } @@ -2692,10 +2671,9 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { # Skipping on Linux and macOS because they do not support Windows Authentication. It 'Should return the correct service instance' -Skip:($IsLinux -or $IsMacOS) { $databaseEngineServerObject = Connect-SQL -Encrypt -ServerName $mockExpectedDatabaseEngineServer -InstanceName $mockExpectedDatabaseEngineInstance -ErrorAction 'Stop' - $databaseEngineServerObject.ConnectionContext.ServerInstance | Should -BeExactly "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" + $databaseEngineServerObject.ConnectionContext.ServerInstance | Should-BeString -CaseSensitive "$mockExpectedDatabaseEngineServer\$mockExpectedDatabaseEngineInstance" - Should -Invoke -CommandName New-Object -Exactly -Times 1 -Scope It ` - -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter -Scope It -Times 1 } } @@ -2739,11 +2717,11 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { $mockErrorMessage = $mockLocalizedString -f 'localhost' { Connect-SQL -ServerName 'localhost' -ErrorAction 'Stop' } | - Should -Throw -ExpectedMessage $mockErrorMessage + Should-Throw -ExceptionMessage $mockErrorMessage - Should -Invoke -CommandName New-Object -ParameterFilter { + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.Server' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } @@ -2779,12 +2757,11 @@ 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 { + Should-Invoke -CommandName New-Object -Exactly -ParameterFilter { $TypeName -eq 'Microsoft.SqlServer.Management.Smo.Server' - } -Exactly -Times 1 -Scope It + } -Scope It -Times 1 } } } @@ -2793,11 +2770,11 @@ Describe 'SqlServerDsc.Common\Connect-SQL' -Tag 'ConnectSql' { Describe 'SqlServerDsc.Common\Split-FullSqlInstanceName' -Tag 'SplitFullSqlInstanceName' { Context 'When the "FullSqlInstanceName" parameter is not supplied' { It 'Should throw when the "FullSqlInstanceName" parameter is $null' { - { Split-FullSqlInstanceName -FullSqlInstanceName $null } | Should -Throw + { Split-FullSqlInstanceName -FullSqlInstanceName $null } | Should-Throw } It 'Should throw when the "FullSqlInstanceName" parameter is an empty string' { - { Split-FullSqlInstanceName -FullSqlInstanceName '' } | Should -Throw + { Split-FullSqlInstanceName -FullSqlInstanceName '' } | Should-Throw } } @@ -2805,17 +2782,17 @@ Describe 'SqlServerDsc.Common\Split-FullSqlInstanceName' -Tag 'SplitFullSqlInsta It 'Should throw when the "FullSqlInstanceName" parameter is "ServerName"' { $result = Split-FullSqlInstanceName -FullSqlInstanceName 'ServerName' - $result.Count | Should -Be 2 - $result.ServerName | Should -Be 'ServerName' - $result.InstanceName | Should -Be 'MSSQLSERVER' + $result.Count | Should-Be 2 + $result.ServerName | Should-Be 'ServerName' + $result.InstanceName | Should-Be 'MSSQLSERVER' } It 'Should throw when the "FullSqlInstanceName" parameter is "ServerName\InstanceName"' { $result = Split-FullSqlInstanceName -FullSqlInstanceName 'ServerName\InstanceName' - $result.Count | Should -Be 2 - $result.ServerName | Should -Be 'ServerName' - $result.InstanceName | Should -Be 'InstanceName' + $result.Count | Should-Be 2 + $result.ServerName | Should-Be 'ServerName' + $result.InstanceName | Should-Be 'InstanceName' } } } @@ -2858,25 +2835,27 @@ Describe 'SqlServerDsc.Common\Test-ClusterPermissions' -Tag 'TestClusterPermissi It "Should throw the correct error when the logins '$($clusterServiceName)' or '$($systemAccountName)' are absent" { $mockServerObject.Logins = @{} - { Test-ClusterPermissions -ServerObject $mockServerObject } | Should -Throw -ExpectedMessage ( "The cluster does not have permissions to manage the Availability Group on '{0}\{1}'. Grant 'Connect SQL', 'Alter Any Availability Group', and 'View Server State' to either '$($clusterServiceName)' or '$($systemAccountName)'. (SQLCOMMON0049)" -f $mockServerObject.NetName, $mockServerObject.ServiceName ) + { Test-ClusterPermissions -ServerObject $mockServerObject } | Should-Throw -ExceptionMessage ( "The cluster does not have permissions to manage the Availability Group on '{0}\{1}'. Grant 'Connect SQL', 'Alter Any Availability Group', and 'View Server State' to either '$($clusterServiceName)' or '$($systemAccountName)'. (SQLCOMMON0049)" -f $mockServerObject.NetName, $mockServerObject.ServiceName ) - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 0 -Exactly -ParameterFilter { + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $clusterServiceName - } - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 0 -Exactly -ParameterFilter { + } -Scope It -Times 0 + + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $systemAccountName - } + } -Scope It -Times 0 } It "Should throw the correct error when the logins '$($clusterServiceName)' and '$($systemAccountName)' do not have permissions to manage availability groups" { - { Test-ClusterPermissions -ServerObject $mockServerObject } | Should -Throw -ExpectedMessage ( "The cluster does not have permissions to manage the Availability Group on '{0}\{1}'. Grant 'Connect SQL', 'Alter Any Availability Group', and 'View Server State' to either '$($clusterServiceName)' or '$($systemAccountName)'. (SQLCOMMON0049)" -f $mockServerObject.NetName, $mockServerObject.ServiceName ) + { Test-ClusterPermissions -ServerObject $mockServerObject } | Should-Throw -ExceptionMessage ( "The cluster does not have permissions to manage the Availability Group on '{0}\{1}'. Grant 'Connect SQL', 'Alter Any Availability Group', and 'View Server State' to either '$($clusterServiceName)' or '$($systemAccountName)'. (SQLCOMMON0049)" -f $mockServerObject.NetName, $mockServerObject.ServiceName ) - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $clusterServiceName - } - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 1 -Exactly -ParameterFilter { + } -Scope It -Times 1 + + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $systemAccountName - } + } -Scope It -Times 1 } } @@ -2884,27 +2863,29 @@ Describe 'SqlServerDsc.Common\Test-ClusterPermissions' -Tag 'TestClusterPermissi It "Should return NullOrEmpty when 'NT SERVICE\ClusSvc' is present and has the permissions to manage availability groups" { $mockClusterServicePermissionsPresent = $true - Test-ClusterPermissions -ServerObject $mockServerObject | Should -Be $true + Test-ClusterPermissions -ServerObject $mockServerObject | Should-BeTrue - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $clusterServiceName - } - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 0 -Exactly -ParameterFilter { + } -Scope It -Times 1 + + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $systemAccountName - } + } -Scope It -Times 0 } It "Should return NullOrEmpty when 'NT AUTHORITY\System' is present and has the permissions to manage availability groups" { $mockSystemPermissionsPresent = $true - Test-ClusterPermissions -ServerObject $mockServerObject | Should -Be $true + Test-ClusterPermissions -ServerObject $mockServerObject | Should-BeTrue - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 1 -Exactly -ParameterFilter { + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $clusterServiceName - } - Should -Invoke -CommandName Test-LoginEffectivePermissions -Scope It -Times 1 -Exactly -ParameterFilter { + } -Scope It -Times 1 + + Should-Invoke -CommandName Test-LoginEffectivePermissions -Exactly -ParameterFilter { $LoginName -eq $systemAccountName - } + } -Scope It -Times 1 } } } @@ -2975,13 +2956,14 @@ 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 { + Should-Invoke -CommandName Get-Service -Exactly -ParameterFilter { $Name -eq $mockServiceName - } -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2 + } -Scope It -Times 1 + + Should-Invoke -CommandName Stop-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 2 } } @@ -3000,13 +2982,14 @@ 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 { + Should-Invoke -CommandName Get-Service -Exactly -ParameterFilter { $Name -eq $mockServiceName - } -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2 + } -Scope It -Times 1 + + Should-Invoke -CommandName Stop-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 2 } } @@ -3025,13 +3008,14 @@ 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 { + Should-Invoke -CommandName Get-Service -Exactly -ParameterFilter { $Name -eq $mockServiceName - } -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2 + } -Scope It -Times 1 + + Should-Invoke -CommandName Stop-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 2 } } @@ -3051,14 +3035,15 @@ 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 { + Should-Invoke -CommandName Get-Service -Exactly -ParameterFilter { $Name -eq $mockServiceName - } -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1 - Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2 - Should -Invoke -CommandName Start-Sleep -Scope It -Exactly -Times 1 + } -Scope It -Times 1 + + Should-Invoke -CommandName Stop-Service -Exactly -Scope It -Times 1 + Should-Invoke -CommandName Start-Service -Exactly -Scope It -Times 2 + Should-Invoke -CommandName Start-Sleep -Exactly -Scope It -Times 1 } } } @@ -3074,7 +3059,7 @@ Describe 'SqlServerDsc.Common\Test-ActiveNode' -Tag 'TestActiveNode' { } It 'Should return $true' { - Test-ActiveNode -ServerObject $mockServerObject | Should -BeTrue + Test-ActiveNode -ServerObject $mockServerObject | Should-BeTrue } } @@ -3095,7 +3080,7 @@ Describe 'SqlServerDsc.Common\Test-ActiveNode' -Tag 'TestActiveNode' { ) { $mockServerObject.ComputerNamePhysicalNetBIOS = $ComputerNamePhysicalNetBIOS - Test-ActiveNode -ServerObject $mockServerObject | Should -Be $Result + Test-ActiveNode -ServerObject $mockServerObject | Should-Be $Result } } } @@ -3123,7 +3108,7 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { } It 'Should throw the correct error from Import-Module' { - { Invoke-SqlScript @invokeScriptFileParameters } | Should -Throw -ExpectedMessage $throwMessage + { Invoke-SqlScript @invokeScriptFileParameters } | Should-Throw -ExceptionMessage $throwMessage } } @@ -3153,18 +3138,18 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { $invokeScriptFileParameters.Add('Credential', $credential) $null = Invoke-SqlScript @invokeScriptFileParameters - Should -Invoke -CommandName Invoke-SqlCmd -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlCmd -Exactly -ParameterFilter { $Username -eq $mockUsername -and $Password -eq $mockPasswordPlain - } -Times 1 -Exactly -Scope It + } -Scope It -Times 1 } It 'Should call Invoke-SqlCmd with correct Query ParameterSet parameters' { $invokeScriptQueryParameters.Add('Credential', $credential) $null = Invoke-SqlScript @invokeScriptQueryParameters - Should -Invoke -CommandName Invoke-SqlCmd -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlCmd -Exactly -ParameterFilter { $Username -eq $mockUsername -and $Password -eq $mockPasswordPlain - } -Times 1 -Exactly -Scope It + } -Scope It -Times 1 } } @@ -3189,11 +3174,11 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { } It 'Should throw the correct error from File ParameterSet Invoke-SqlCmd' { - { Invoke-SqlScript @invokeScriptFileParameters } | Should -Throw -ExpectedMessage $errorMessage + { Invoke-SqlScript @invokeScriptFileParameters } | Should-Throw -ExceptionMessage $errorMessage } It 'Should throw the correct error from Query ParameterSet Invoke-SqlCmd' { - { Invoke-SqlScript @invokeScriptQueryParameters } | Should -Throw -ExpectedMessage $errorMessage + { Invoke-SqlScript @invokeScriptQueryParameters } | Should-Throw -ExceptionMessage $errorMessage } } @@ -3233,9 +3218,9 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { $null = Invoke-SqlScript @mockInvokeScriptFileParameters - Should -Invoke -CommandName Invoke-SqlCmd -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlCmd -Exactly -ParameterFilter { $Encrypt -eq 'Optional' - } -Times 1 -Exactly -Scope It + } -Scope It -Times 1 } It 'Should call Invoke-SqlCmd with correct Query ParameterSet parameters' { @@ -3247,9 +3232,9 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { $null = Invoke-SqlScript @mockInvokeScriptQueryParameters - Should -Invoke -CommandName Invoke-SqlCmd -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlCmd -Exactly -ParameterFilter { $Encrypt -eq 'Optional' - } -Times 1 -Exactly -Scope It + } -Scope It -Times 1 } } @@ -3275,9 +3260,9 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { $null = Invoke-SqlScript @mockInvokeScriptFileParameters - Should -Invoke -CommandName Invoke-SqlCmd -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlCmd -Exactly -ParameterFilter { $PesterBoundParameters.Keys -notcontains 'Encrypt' - } -Times 1 -Exactly -Scope It + } -Scope It -Times 1 } It 'Should call Invoke-SqlCmd with correct Query ParameterSet parameters' { @@ -3289,9 +3274,9 @@ Describe 'SqlServerDsc.Common\Invoke-SqlScript' -Tag 'InvokeSqlScript' { $null = Invoke-SqlScript @mockInvokeScriptQueryParameters - Should -Invoke -CommandName Invoke-SqlCmd -ParameterFilter { + Should-Invoke -CommandName Invoke-SqlCmd -Exactly -ParameterFilter { $PesterBoundParameters.Keys -notcontains 'Encrypt' - } -Times 1 -Exactly -Scope It + } -Scope It -Times 1 } } } @@ -3316,28 +3301,28 @@ Describe 'SqlServerDsc.Common\Get-ServiceAccount' -Tag 'GetServiceAccount' { It 'Should return NT AUTHORITY\SYSTEM' { $returnValue = Get-ServiceAccount -ServiceAccount $mockLocalSystemAccountCredential - $returnValue.UserName | Should -Be $mockLocalSystemAccountUserName - $returnValue.Password | Should -BeNullOrEmpty + $returnValue.UserName | Should-Be $mockLocalSystemAccountUserName + $returnValue.Password | Should-BeFalsy } It 'Should return Domain Account and Password' { $returnValue = Get-ServiceAccount -ServiceAccount $mockDomainAccountCredential - $returnValue.UserName | Should -Be $mockDomainAccountUserName - $returnValue.Password | Should -Be $mockDomainAccountCredential.GetNetworkCredential().Password + $returnValue.UserName | Should-Be $mockDomainAccountUserName + $returnValue.Password | Should-Be $mockDomainAccountCredential.GetNetworkCredential().Password } It 'Should return managed service account' { $returnValue = Get-ServiceAccount -ServiceAccount $mockManagedServiceAccountCredential - $returnValue.UserName | Should -Be $mockManagedServiceAccountUserName + $returnValue.UserName | Should-Be $mockManagedServiceAccountUserName } It 'Should return local service account' { $returnValue= Get-ServiceAccount -ServiceAccount $mockLocalServiceAccountCredential - $returnValue.UserName | Should -Be $mockLocalServiceAccountUserName - $returnValue.Password | Should -BeNullOrEmpty + $returnValue.UserName | Should-Be $mockLocalServiceAccountUserName + $returnValue.Password | Should-BeFalsy } } } @@ -3353,15 +3338,15 @@ Describe 'SqlServerDsc.Common\Find-ExceptionByNumber' -Tag 'FindExceptionByNumbe Context 'When searching Exception objects' { It 'Should return true for main exception' { - Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 1 | Should -Be $true + Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 1 | Should-BeTrue } It 'Should return true for inner exception' { - Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 2 | Should -Be $true + Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 2 | Should-BeTrue } It 'Should return false when message not found' { - Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 3 | Should -Be $false + Find-ExceptionByNumber -ExceptionToSearch $mockException -ErrorNumber 3 | Should-BeFalse } } } @@ -3386,8 +3371,8 @@ Describe 'SqlServerDsc.Common\Get-ProtocolNameProperties' -Tag 'GetProtocolNameP ) { $result = Get-ProtocolNameProperties -ProtocolName $ParameterValue - $result.DisplayName | Should -Be $DisplayName - $result.Name | Should -Be $Name + $result.DisplayName | Should-Be $DisplayName + $result.Name | Should-Be $Name } } @@ -3427,10 +3412,10 @@ Describe 'SqlServerDsc.Common\Get-ServerProtocolObject' -Tag 'GetServerProtocolO $result = Get-ServerProtocolObject @mockGetServerProtocolObjectParameters - $result.IsEnabled | Should -BeTrue - $result.HasMultiIPAddresses | Should -BeTrue - $result.ProtocolProperties.ListenOnAllIPs | Should -BeTrue - $result.ProtocolProperties.KeepAlive | Should -Be 30000 + $result.IsEnabled | Should-BeTrue + $result.HasMultiIPAddresses | Should-BeTrue + $result.ProtocolProperties.ListenOnAllIPs | Should-BeTrue + $result.ProtocolProperties.KeepAlive | Should-Be 30000 } Context "When ManagedComputer object has an empty array, 'ServerInstances' value" { @@ -3463,9 +3448,9 @@ Describe 'SqlServerDsc.Common\Get-ServerProtocolObject' -Tag 'GetServerProtocolO $mockLocalizedString -f $mockInstanceName, $mockServerName ) - $mockErrorRecord.Exception.Message | Should -Not -BeNullOrEmpty + $mockErrorRecord.Exception.Message | Should-BeTruthy - { Get-ServerProtocolObject @mockGetServerProtocolObjectParameters } | Should -Throw -ExpectedMessage $mockErrorRecord.Exception.Message + { Get-ServerProtocolObject @mockGetServerProtocolObjectParameters } | Should-Throw -ExceptionMessage $mockErrorRecord.Exception.Message } } } @@ -3478,13 +3463,13 @@ Describe 'SqlServerDsc.Common\ConvertTo-ServerInstanceName' -Tag 'ConvertToServe It 'Should return correct service instance for a default instance' { $result = ConvertTo-ServerInstanceName -InstanceName 'MSSQLSERVER' -ServerName $mockComputerName - $result | Should -BeExactly $mockComputerName + $result | Should-BeString -CaseSensitive $mockComputerName } It 'Should return correct service instance for a name instance' { $result = ConvertTo-ServerInstanceName -InstanceName 'MyInstance' -ServerName $mockComputerName - $result | Should -BeExactly ('{0}\{1}' -f $mockComputerName, 'MyInstance') + $result | Should-BeString -CaseSensitive ('{0}\{1}' -f $mockComputerName, 'MyInstance') } } @@ -3504,26 +3489,26 @@ Describe 'SqlServerDsc.Common\Get-FilePathMajorVersion' -Tag 'GetFilePathMajorVe It 'Should return correct version' { $result = Get-FilePathMajorVersion -Path 'C:\AnyPath\Setup.exe' - $result | Should -Be '10' + $result | Should-Be '10' } } Describe 'Test-FeatureFlag' -Tag 'TestFeatureFlag' { Context 'When no feature flags was provided' { It 'Should return $false' { - Test-FeatureFlag -FeatureFlag $null -TestFlag 'MyFlag' | Should -Be $false + Test-FeatureFlag -FeatureFlag $null -TestFlag 'MyFlag' | Should-BeFalse } } Context 'When feature flags was provided' { It 'Should return $true' { - Test-FeatureFlag -FeatureFlag @('FirstFlag', 'SecondFlag') -TestFlag 'SecondFlag' | Should -Be $true + Test-FeatureFlag -FeatureFlag @('FirstFlag', 'SecondFlag') -TestFlag 'SecondFlag' | Should-BeTrue } } Context 'When feature flags was provided, but missing' { It 'Should return $false' { - Test-FeatureFlag -FeatureFlag @('MyFlag2') -TestFlag 'MyFlag' | Should -Be $false + Test-FeatureFlag -FeatureFlag @('MyFlag2') -TestFlag 'MyFlag' | Should-BeFalse } } }