diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cab18d5c..95bea7b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,19 +42,29 @@ renamed the repository the security token was changed ([issue #1012](https://github.com/PowerShell/SqlServerDsc/issues/1012)). - Fixed typo in comment-base help for helper function Test-AvailabilityReplicaSeedingModeAutomatic. + - Style cleanup in helper function tests. +- Changes to SqlAG + - Fixed typos in tests. + - Style cleanup in tests. +- Changes to SqlAGDatabase + - Style cleanup in tests. - Changes to SqlAGListener - Fixed typo in comment-based help. + - Style cleanup in tests. - Changes to SqlAGReplica - Minor code style cleanup. Removed unused variable and instead piped the cmdlet Join-SqlAvailabilityGroup to Out-Null. - Fixed minor typos in comment-based help. - Fixed minor typos in comment. + - Style cleanup in tests. - Changes to SqlAlias - Fixed issue where exception was thrown if reg keys did not exist ([issue #949](https://github.com/PowerShell/SqlServerDsc/issues/949)). + - Style cleanup in tests. - Changes to SqlAlwaysOnService - Refactor integration tests slightly to improve run time performance ([issue #1001](https://github.com/PowerShell/SqlServerDsc/issues/1001)). + - Style cleanup in tests. - Changes to SqlDatabase - Fix minor Script Analyzer warning. - Changes to SqlDatabaseDefaultLocation @@ -71,16 +81,21 @@ ([issue #634](https://github.com/PowerShell/SqlServerDsc/issues/634)). - Refactor integration tests slightly to improve run time performance ([issue #1001](https://github.com/PowerShell/SqlServerDsc/issues/1001)). +- Changes to SqlScript + - Style cleanup in tests. - Changes to SqlServerConfiguration - Fixed minor typos in comment-based help. + - Style cleanup in tests. - Changes to SqlServerEndpoint - Updated README.md with links to the examples ([issue #504](https://github.com/PowerShell/SqlServerDsc/issues/504)). + - Style cleanup in tests. - Changes to SqlServerLogin - Added integration tests ([issue #748](https://github.com/PowerShell/SqlServerDsc/issues/748)). - Minor code style cleanup. - Removed unused variable and instead piped the helper function Connect-SQL to Out-Null. + - Style cleanup in tests. - Changes to SqlServerMaxDop - Minor style changes in the helper function Get-SqlDscDynamicMaxDop. - Changes to SqlServerMemory @@ -121,6 +136,7 @@ - Added PSSA rule 'PSUseDeclaredVarsMoreThanAssignments' override in the function Set-TargetResource for the variable $global:DSCMachineStatus. - Style cleanup in helper function ConvertTo-Decimal. + - Style cleanup in tests. - Changes to SqlWindowsFirewall - Fixed minor typos in comment-based help. - Minor code style cleanup. diff --git a/Tests/Unit/MSFT_SqlAG.Tests.ps1 b/Tests/Unit/MSFT_SqlAG.Tests.ps1 index 67d0c09bb..c7f350efe 100644 --- a/Tests/Unit/MSFT_SqlAG.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAG.Tests.ps1 @@ -78,7 +78,7 @@ try $mockIsHadrEnabled = $true $mockIsDatabaseMirroringEndpointPresent = $true - $mockServerObjectProperies = @{ + $mockServerObjectProperties = @{ Server1 = @{ NetName = 'Server1' } @@ -96,7 +96,7 @@ try FailureConditionLevel = 'OnCriticalServerErrors' # Not the default parameter value HealthCheckTimeout = 20000 Name = $mockNameParameters.PresentAvailabilityGroup - PrimaryReplicaServerName = $mockServerObjectProperies.Server1.NetName + PrimaryReplicaServerName = $mockServerObjectProperties.Server1.NetName } $mockAvailabilityGroupReplicaProperties = @{ @@ -105,11 +105,11 @@ try BackupPriority = 49 # Not the default parameter value ConnectionModeInPrimaryRole = 'AllowAllConnections' # Not the default parameter value ConnectionModeInSecondaryRole = 'AllowNoConnections' # Not the default parameter value - EndpointHostName = $mockServerObjectProperies.Server1.NetName + EndpointHostName = $mockServerObjectProperties.Server1.NetName EndpointProtocol = 'TCP' EndpointPort = 5022 FailoverMode = 'Automatic' # Not the default parameter value - Name = $mockServerObjectProperies.Server1.NetName + Name = $mockServerObjectProperties.Server1.NetName Role = 'Primary' } @@ -118,11 +118,11 @@ try BackupPriority = 49 # Not the default parameter value ConnectionModeInPrimaryRole = 'AllowAllConnections' # Not the default parameter value ConnectionModeInSecondaryRole = 'AllowNoConnections' # Not the default parameter value - EndpointHostName = $mockServerObjectProperies.Server2.NetName + EndpointHostName = $mockServerObjectProperties.Server2.NetName EndpointProtocol = 'TCP' EndpointPort = 5022 FailoverMode = 'Automatic' # Not the default parameter value - Name = $mockServerObjectProperies.Server2.NetName + Name = $mockServerObjectProperties.Server2.NetName Role = 'Primary' } } @@ -488,7 +488,7 @@ try { $mockSqlServer = $SQLServer } - $mockCurrentServerObjectProperties = $mockServerObjectProperies.$mockSqlServer + $mockCurrentServerObjectProperties = $mockServerObjectProperties.$mockSqlServer # Build the domain instance name if ( ( $SQLInstanceName -eq 'MSSQLSERVER' ) -or [string]::IsNullOrEmpty($SQLInstanceName) ) @@ -597,7 +597,7 @@ try } # Mock the Update-AvailabilityGroup function to ensure the specified property was set correctly - $mockUpdateAvailabiltyGroup = { + $mockUpdateAvailabilityGroup = { param ( [Parameter()] @@ -623,7 +623,7 @@ try } # Mock the Update-AvailabilityGroupReplica function to ensure the specified property was set correctly - $mockUpdateAvailabiltyGroupReplica = { + $mockUpdateAvailabilityGroupReplica = { param ( [Parameter()] @@ -774,13 +774,13 @@ try BeforeAll { Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable Mock -CommandName Get-PrimaryReplicaServerObject -MockWith $mockConnectSql -Verifiable - Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable + Mock -CommandName Import-SQLPSModule -Verifiable Mock -CommandName New-SqlAvailabilityGroup $mockNewSqlAvailabilityGroup -Verifiable Mock -CommandName New-SqlAvailabilityReplica -MockWith $mockNewSqlAvailabilityGroupReplica -Verifiable Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -Verifiable - Mock -CommandName Remove-SqlAvailabilityGroup -MockWith {} -Verifiable -ParameterFilter { + Mock -CommandName Remove-SqlAvailabilityGroup -Verifiable -ParameterFilter { $InputObject.Name -eq $mockNameParameters.PresentAvailabilityGroup } Mock -CommandName Remove-SqlAvailabilityGroup -MockWith { @@ -788,9 +788,9 @@ try } -Verifiable -ParameterFilter { $InputObject.Name -eq $mockNameParameters.RemoveAvailabilityGroupFailed } - Mock -CommandName Test-ClusterPermissions -MockWith {} -Verifiable - Mock -CommandName Update-AvailabilityGroup -MockWith $mockUpdateAvailabiltyGroup -Verifiable - Mock -CommandName Update-AvailabilityGroupReplica -MockWith $mockUpdateAvailabiltyGroupReplica -Verifiable + Mock -CommandName Test-ClusterPermissions -Verifiable + Mock -CommandName Update-AvailabilityGroup -MockWith $mockUpdateAvailabilityGroup -Verifiable + Mock -CommandName Update-AvailabilityGroupReplica -MockWith $mockUpdateAvailabilityGroupReplica -Verifiable } Context 'When the Availability Group is Absent and the desired state is Present and a parameter is supplied' { @@ -920,13 +920,13 @@ try if ( $mockAvailabilityGroupProperties.Keys -contains $ParameterName ) { - $assertUpdateAvailbilityGroupMockCalled = 1 - $assertUpdateAvailbilityGroupReplicaMockCalled = 0 + $assertUpdateAvailabilityGroupMockCalled = 1 + $assertUpdateAvailabilityGroupReplicaMockCalled = 0 } elseif ( $mockAvailabilityGroupReplicaProperties.Server1.Keys -contains $ParameterName ) { - $assertUpdateAvailbilityGroupMockCalled = 0 - $assertUpdateAvailbilityGroupReplicaMockCalled = 1 + $assertUpdateAvailabilityGroupMockCalled = 0 + $assertUpdateAvailabilityGroupReplicaMockCalled = 1 } Set-TargetResource @setTargetResourceParameters @@ -945,8 +945,8 @@ try $InputObject.Name -eq $mockNameParameters.RemoveAvailabilityGroupFailed } Assert-MockCalled -CommandName Test-ClusterPermissions -Scope It -Times 1 -Exactly - Assert-MockCalled -CommandName Update-AvailabilityGroup -Scope It -Times $assertUpdateAvailbilityGroupMockCalled -Exactly - Assert-MockCalled -CommandName Update-AvailabilityGroupReplica -Scope It -Times $assertUpdateAvailbilityGroupReplicaMockCalled -Exactly + Assert-MockCalled -CommandName Update-AvailabilityGroup -Scope It -Times $assertUpdateAvailabilityGroupMockCalled -Exactly + Assert-MockCalled -CommandName Update-AvailabilityGroupReplica -Scope It -Times $assertUpdateAvailabilityGroupReplicaMockCalled -Exactly } } @@ -1303,7 +1303,7 @@ try } } - Context 'When the Availability Group is Present an Enpoint property is incorrect' { + Context 'When the Availability Group is Present an Endpoint property is incorrect' { AfterEach { # Restore up the original endpoint url settings $mockAvailabilityGroupReplicaProperties.Server1 = $mockAvailabilityGroupReplicaPropertiesServer1Original.Clone() @@ -1406,7 +1406,7 @@ try Assert-MockCalled -CommandName New-TerminatingError -Scope It -Times 0 -Exactly } - It 'Should throw the correct error, AlterAvailabilityGroupFailed, when altering the Availaiblity Group fails' { + It 'Should throw the correct error, AlterAvailabilityGroupFailed, when altering the Availability Group fails' { $mockAvailabilityGroup.Name = 'AlterFailed' diff --git a/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 index 599642481..ecc60beb9 100644 --- a/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGDatabase.Tests.ps1 @@ -357,7 +357,7 @@ WITH NORECOVERY' Describe 'SqlAGDatabase\Get-TargetResource' { BeforeAll { Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable - Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable + Mock -CommandName Import-SQLPSModule -Verifiable } BeforeEach { @@ -426,14 +426,14 @@ WITH NORECOVERY' BeforeAll { Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server1' } Mock -CommandName Get-PrimaryReplicaServerObject -MockWith { return $mockServer2Object } -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq 'Server2' } - Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable - Mock -CommandName Invoke-Query -MockWith {} -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabase - Mock -CommandName Invoke-Query -MockWith {} -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs + Mock -CommandName Import-SQLPSModule -Verifiable + Mock -CommandName Invoke-Query -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabase + Mock -CommandName Invoke-Query -Verifiable -ParameterFilter $mockInvokeQueryParameterRestoreDatabaseWithExecuteAs Mock -CommandName Join-Path -MockWith { [IO.Path]::Combine($databaseMembershipClass.BackupPath,"$($database.Name)_Full_$(Get-Date -Format 'yyyyMMddhhmmss').bak") } -Verifiable -ParameterFilter { $ChildPath -like '*_Full_*.bak' } Mock -CommandName Join-Path -MockWith { [IO.Path]::Combine($databaseMembershipClass.BackupPath,"$($database.Name)_Log_$(Get-Date -Format 'yyyyMMddhhmmss').trn") } -Verifiable -ParameterFilter { $ChildPath -like '*_Log_*.trn' } Mock -CommandName New-TerminatingError { $ErrorType } -Verifiable - Mock -CommandName Remove-Item -MockWith {} -Verifiable - Mock -CommandName Restore-SqlDatabase -MockWith {} -Verifiable + Mock -CommandName Remove-Item -Verifiable + Mock -CommandName Restore-SqlDatabase -Verifiable } BeforeEach { @@ -448,17 +448,17 @@ WITH NORECOVERY' MatchDatabaseOwner = $true } - Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } - Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } - Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Primary' } - Mock -CommandName Add-SqlAvailabilityDatabase -MockWith {} -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Secondary' } - Mock -CommandName Backup-SqlDatabase -MockWith {} -Verifiable -ParameterFilter { $BackupAction -eq 'Database' } - Mock -CommandName Backup-SqlDatabase -MockWith {} -Verifiable -ParameterFilter { $BackupAction -eq 'Log'} + Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Primary' } + Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server1' -and $InputObject.LocalReplicaRole -eq 'Secondary' } + Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Primary' } + Mock -CommandName Add-SqlAvailabilityDatabase -Verifiable -ParameterFilter { $InputObject.PrimaryReplicaServerName -eq 'Server2' -and $InputObject.LocalReplicaRole -eq 'Secondary' } + Mock -CommandName Backup-SqlDatabase -Verifiable -ParameterFilter { $BackupAction -eq 'Database' } + Mock -CommandName Backup-SqlDatabase -Verifiable -ParameterFilter { $BackupAction -eq 'Log'} Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $SqlServer -eq 'Server1' -and $SQLInstanceName -eq 'MSSQLSERVER' } Mock -CommandName Connect-SQL -MockWith { return $mockServerObject } -Verifiable -ParameterFilter { $SqlServer -eq 'Server1' } Mock -CommandName Connect-SQL -MockWith { return $mockServer2Object } -Verifiable -ParameterFilter { $SqlServer -eq 'Server2' } Mock -CommandName Invoke-Query -MockWith $mockResultInvokeQueryFileExist -Verifiable -ParameterFilter { $Query -like 'EXEC master.dbo.xp_fileexist *' } - Mock -CommandName Remove-SqlAvailabilityDatabase -MockWith {} -Verifiable + Mock -CommandName Remove-SqlAvailabilityDatabase -Verifiable Mock -CommandName Test-ImpersonatePermissions -MockWith { $true } -Verifiable } diff --git a/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 b/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 index b1d06d8d7..01c2feaef 100644 --- a/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGListener.Tests.ps1 @@ -104,7 +104,7 @@ try Context 'When the system is not in the desired state' { - Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -Verifiable + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Verifiable It 'Should return the desired state as absent' { $result = Get-TargetResource @testParameters @@ -238,7 +238,7 @@ try $testParameters['Port'] = 5030 $testParameters['DHCP'] = $false - Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -Verifiable + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Verifiable $result = Test-TargetResource @testParameters $result | Should -Be $false @@ -404,7 +404,7 @@ try $testParameters['Port'] = 5030 $testParameters['DHCP'] = $false - Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -MockWith {} -Verifiable + Mock -CommandName Get-SQLAlwaysOnAvailabilityGroupListener -Verifiable $result = Test-TargetResource @testParameters $result | Should -Be $true @@ -516,9 +516,9 @@ try $testParameters = $defaultParameters.Clone() Mock -CommandName Connect-SQL -MockWith $mockConnectSql -Verifiable - Mock -CommandName New-SqlAvailabilityGroupListener -MockWith {} -Verifiable - Mock -CommandName Set-SqlAvailabilityGroupListener -MockWith {} -Verifiable - Mock -CommandName Add-SqlAvailabilityGroupListenerStaticIp -MockWith {} -Verifiable + Mock -CommandName New-SqlAvailabilityGroupListener -Verifiable + Mock -CommandName Set-SqlAvailabilityGroupListener -Verifiable + Mock -CommandName Add-SqlAvailabilityGroupListenerStaticIp -Verifiable } Context 'When the system is not in the desired state' { diff --git a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 index d94ba1a20..e37274f92 100644 --- a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 @@ -605,7 +605,7 @@ try Describe 'SqlAGReplica\Set-TargetResource' { BeforeAll { - Mock -CommandName Import-SQLPSModule -MockWith {} -Verifiable + Mock -CommandName Import-SQLPSModule -Verifiable Mock -CommandName New-TerminatingError { $ErrorType } -Verifiable @@ -634,8 +634,8 @@ try Mock -CommandName Get-PrimaryReplicaServerObject -MockWith $mockConnectSqlServer3 -Verifiable -ParameterFilter { $AvailabilityGroup.PrimaryReplicaServerName -eq $mockServer3Name } - Mock -CommandName Join-SqlAvailabilityGroup -MockWith {} -Verifiable - Mock -CommandName New-SqlAvailabilityReplica {} -Verifiable + Mock -CommandName Join-SqlAvailabilityGroup -Verifiable + Mock -CommandName New-SqlAvailabilityReplica -Verifiable Mock -CommandName Test-ClusterPermissions -MockWith { $null } -Verifiable @@ -644,7 +644,7 @@ try Context 'When the desired state is absent' { BeforeAll { - Mock -CommandName Update-AvailabilityGroupReplica {} -Verifiable + Mock -CommandName Update-AvailabilityGroupReplica -Verifiable } BeforeEach { @@ -659,7 +659,7 @@ try It 'Should silently remove the availability group replica' { - Mock -CommandName Remove-SqlAvailabilityReplica -MockWith {} -Verifiable + Mock -CommandName Remove-SqlAvailabilityReplica -Verifiable { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw @@ -727,8 +727,8 @@ try Context 'When the desired state is present and the availability group is absent' { BeforeAll { - Mock -CommandName Remove-SqlAvailabilityReplica -MockWith {} -Verifiable - Mock -CommandName Update-AvailabilityGroupReplica {} -Verifiable + Mock -CommandName Remove-SqlAvailabilityReplica -Verifiable + Mock -CommandName Update-AvailabilityGroupReplica -Verifiable } BeforeEach { @@ -1052,7 +1052,7 @@ try Context 'When the desired state is present and the availability group is present' { BeforeAll { - Mock -CommandName Remove-SqlAvailabilityReplica -MockWith {} -Verifiable + Mock -CommandName Remove-SqlAvailabilityReplica -Verifiable Mock -CommandName Update-AvailabilityGroupReplica -MockWith $mockUpdateAvailabilityGroupReplica -Verifiable # Create a hash table to provide test properties and values for the update tests diff --git a/Tests/Unit/MSFT_SqlAlias.Tests.ps1 b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 index 1105bf34f..3c21c64f0 100644 --- a/Tests/Unit/MSFT_SqlAlias.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlias.Tests.ps1 @@ -830,9 +830,9 @@ try #region Set-TargetResource Describe "$($script:DSCResourceName)\Set-TargetResource" { - Mock -CommandName New-Item -MockWith {} -ModuleName $script:DSCResourceName -Verifiable - Mock -CommandName Set-ItemProperty -MockWith {} -ModuleName $script:DSCResourceName -Verifiable - Mock -CommandName Remove-ItemProperty -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName New-Item -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName Set-ItemProperty -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName Remove-ItemProperty -ModuleName $script:DSCResourceName -Verifiable Mock -CommandName Test-Path -MockWith { return $false } -ModuleName $script:DSCResourceName -Verifiable diff --git a/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 b/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 index 02da5f12f..d1559adc1 100644 --- a/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAlwaysOnService.Tests.ps1 @@ -115,12 +115,12 @@ try # Loading stub cmdlets Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force - Mock -CommandName Disable-SqlAlwaysOn -MockWith {} -ModuleName $script:DSCResourceName - Mock -CommandName Enable-SqlAlwaysOn -MockWith {} -ModuleName $script:DSCResourceName - Mock -CommandName Import-SQLPSModule -MockWith {} -ModuleName $script:DSCResourceName + Mock -CommandName Disable-SqlAlwaysOn -ModuleName $script:DSCResourceName + Mock -CommandName Enable-SqlAlwaysOn -ModuleName $script:DSCResourceName + Mock -CommandName Import-SQLPSModule -ModuleName $script:DSCResourceName Mock -CommandName New-TerminatingError { $ErrorType } -ModuleName $script:DSCResourceName - Mock -CommandName New-VerboseMessage -MockWith {} -ModuleName $script:DSCResourceName - Mock -CommandName Restart-SqlService -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName New-VerboseMessage -ModuleName $script:DSCResourceName + Mock -CommandName Restart-SqlService -ModuleName $script:DSCResourceName -Verifiable Context 'When HADR is not in the desired state' { It 'Should enable SQL Always On when Ensure is set to Present' { diff --git a/Tests/Unit/MSFT_SqlScript.Tests.ps1 b/Tests/Unit/MSFT_SqlScript.Tests.ps1 index 579c68c2b..722392078 100644 --- a/Tests/Unit/MSFT_SqlScript.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlScript.Tests.ps1 @@ -252,7 +252,7 @@ try $user = "User" Mock -CommandName Import-SQLPSModule -MockWith {} - Mock -CommandName Invoke-Sqlcmd -MockWith {} -ParameterFilter { + Mock -CommandName Invoke-Sqlcmd -ParameterFilter { ($Username -eq $user) -and ($Password -eq $passwordPlain) } diff --git a/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 b/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 index 2499fea41..c0b4acab2 100644 --- a/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerConfiguration.Tests.ps1 @@ -67,7 +67,7 @@ try { Describe "$($script:DSCResourceName)\Get-TargetResource" { - Mock -CommandName New-VerboseMessage -MockWith {} -ModuleName $script:DSCResourceName + Mock -CommandName New-VerboseMessage -ModuleName $script:DSCResourceName Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName @@ -175,7 +175,7 @@ try Describe "$($script:DSCResourceName)\Test-TargetResource" { - Mock -CommandName New-VerboseMessage -MockWith {} -ModuleName $script:DSCResourceName + Mock -CommandName New-VerboseMessage -ModuleName $script:DSCResourceName Mock -CommandName Connect-SQL -MockWith { $mock = New-Object -TypeName PSObject -Property @{ @@ -205,9 +205,9 @@ try } Describe "$($script:DSCResourceName)\Set-TargetResource" { - Mock -CommandName New-VerboseMessage -MockWith {} -ModuleName $script:DSCResourceName + Mock -CommandName New-VerboseMessage -ModuleName $script:DSCResourceName - Mock -CommandName New-TerminatingError -MockWith {} -ModuleName $script:DSCResourceName + Mock -CommandName New-TerminatingError -ModuleName $script:DSCResourceName Mock -CommandName Connect-SQL -MockWith { $mock = New-Object -TypeName PSObject -Property @{ @@ -247,9 +247,9 @@ try return $mock } -ModuleName $script:DSCResourceName -Verifiable -ParameterFilter { $SQLServer -eq 'CLU02' } - Mock -CommandName Restart-SqlService -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName Restart-SqlService -ModuleName $script:DSCResourceName -Verifiable - Mock -CommandName New-WarningMessage -MockWith {} -ModuleName $script:DSCResourceName -Verifiable + Mock -CommandName New-WarningMessage -ModuleName $script:DSCResourceName -Verifiable Context 'Change the system to the desired state' { It 'Should not restart SQL for a dynamic option' { diff --git a/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 index 4f7aadedd..907bde075 100644 --- a/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1 @@ -525,7 +525,7 @@ try Context 'When Connect-SQL returns nothing' { It 'Should throw the correct error' { - Mock -CommandName Get-TargetResource -MockWith {} -Verifiable + Mock -CommandName Get-TargetResource -Verifiable Mock -CommandName Connect-SQL -MockWith { return $null } diff --git a/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 b/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 index 9d2d4ed35..1d23e7120 100644 --- a/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerLogin.Tests.ps1 @@ -508,10 +508,10 @@ try Describe 'MSFT_SqlServerLogin\Set-TargetResource' { Mock -CommandName New-TerminatingError -MockWith { $ErrorType } -ModuleName $script:DSCResourceName - Mock -CommandName Update-SQLServerLogin -MockWith {} -ModuleName $script:DSCResourceName - Mock -CommandName New-SQLServerLogin -MockWith {} -ModuleName $script:DSCResourceName - Mock -CommandName Remove-SQLServerLogin -MockWith {} -ModuleName $script:DSCResourceName - Mock -CommandName Set-SQLServerLoginPassword -MockWith {} -ModuleName $script:DSCResourceName + Mock -CommandName Update-SQLServerLogin -ModuleName $script:DSCResourceName + Mock -CommandName New-SQLServerLogin -ModuleName $script:DSCResourceName + Mock -CommandName Remove-SQLServerLogin -ModuleName $script:DSCResourceName + Mock -CommandName Set-SQLServerLoginPassword -ModuleName $script:DSCResourceName Context 'When the desired state is Absent' { BeforeEach { diff --git a/Tests/Unit/MSFT_SqlSetup.Tests.ps1 b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 index 9dadd1952..e1d76e2ed 100644 --- a/Tests/Unit/MSFT_SqlSetup.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 @@ -1055,23 +1055,23 @@ try Mock -CommandName Get-CimInstance -MockWith $mockEmptyHashtable -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockDefaultInstance_InstanceId\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\DQ\*" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockDefaultInstance_InstanceId\Setup" -and $Name -eq 'SqlProgramDir' - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should return the same values as passed as parameters' { @@ -1182,23 +1182,23 @@ try Mock -CommandName Get-Service -MockWith $mockEmptyHashtable -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockDefaultInstance_InstanceId\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\DQ\*" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockDefaultInstance_InstanceId\Setup" -and $Name -eq 'SqlProgramDir' - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should return the same values as passed as parameters' { @@ -1238,11 +1238,11 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable $result = Get-TargetResource @testParameters $result.Features | Should -Be '' @@ -1890,23 +1890,23 @@ try Mock -CommandName Get-CimInstance -MockWith $mockEmptyHashtable -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockNamedInstance_InstanceId\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\DQ\*" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockNamedInstance_InstanceId\Setup" -and $Name -eq 'SqlProgramDir' - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should return the same values as passed as parameters' { @@ -1943,11 +1943,11 @@ try It 'Should not return any names of installed features' { Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable $result = Get-TargetResource @testParameters $result.Features | Should -Be '' @@ -2202,9 +2202,9 @@ try Mock -CommandName Connect-SQL -MockWith $mockConnectSQL -Verifiable - Mock -CommandName Get-CimInstance -MockWith {} -Verifiable + Mock -CommandName Get-CimInstance -Verifiable - Mock -CommandName Get-CimAssociatedInstance -MockWith {} -Verifiable + Mock -CommandName Get-CimAssociatedInstance -Verifiable Mock -CommandName Get-ItemProperty -MockWith $mockGetItemProperty_Setup -Verifiable @@ -3308,11 +3308,11 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should set the system in the desired state when feature is SQLENGINE' { @@ -3481,11 +3481,11 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should set the system in the desired state when feature is SQLENGINE' { @@ -3657,11 +3657,11 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should set the system in the desired state when feature is SQLENGINE' { @@ -3839,11 +3839,11 @@ try BeforeEach { Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should pass proper parameters to setup' { @@ -3931,7 +3931,7 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockDefaultInstance_InstanceId\Setup" -and $Name -eq 'SqlProgramDir' @@ -3944,7 +3944,7 @@ try BeforeEach { Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should pass proper parameters to setup' { @@ -4225,7 +4225,7 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$mockDefaultInstance_InstanceId\Setup" -and $Name -eq 'SqlProgramDir' @@ -4233,23 +4233,23 @@ try Mock -CommandName Start-SqlSetupProcess -MockWith $mockStartSqlSetupProcess -Verifiable - Mock -CommandName Get-CimInstance -MockWith {} -ParameterFilter { + Mock -CommandName Get-CimInstance -ParameterFilter { ($Namespace -eq 'root/MSCluster') -and ($ClassName -eq 'MSCluster_ResourceGroup') -and ($Filter -eq "Name = 'Available Storage'") } -Verifiable - Mock -CommandName Get-CimAssociatedInstance -MockWith {} -ParameterFilter { + Mock -CommandName Get-CimAssociatedInstance -ParameterFilter { ($Association -eq 'MSCluster_ResourceGroupToResource') -and ($ResultClassName -eq 'MSCluster_Resource') } -Verifiable - Mock -CommandName Get-CimAssociatedInstance -MockWith {} -ParameterFilter { + Mock -CommandName Get-CimAssociatedInstance -ParameterFilter { $Association -eq 'MSCluster_ResourceToPossibleOwner' } -Verifiable - Mock -CommandName Get-CimAssociatedInstance -MockWith {} -ParameterFilter { + Mock -CommandName Get-CimAssociatedInstance -ParameterFilter { $ResultClass -eq 'MSCluster_DiskPartition' } -Verifiable - Mock -CommandName Get-CimInstance -MockWith {} -ParameterFilter { + Mock -CommandName Get-CimInstance -ParameterFilter { ($Namespace -eq 'root/MSCluster') -and ($ClassName -eq 'MSCluster_Network') -and ($Filter -eq 'Role >= 2') } -Verifiable } @@ -4257,7 +4257,7 @@ try BeforeEach { Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable } It 'Should pass correct arguments to the setup process' { @@ -4332,11 +4332,11 @@ try Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\Tools\Setup\Client_Components_Full" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-ItemProperty -ParameterFilter { $Path -eq "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($mockSqlMajorVersion)0\ConfigurationState" - } -MockWith {} -Verifiable + } -Verifiable Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance_MSClusterResourceGroup_AvailableStorage -ParameterFilter { $Filter -eq "Name = 'Available Storage'" diff --git a/Tests/Unit/SqlServerDSCHelper.Tests.ps1 b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 index 04b1a73cd..e28588418 100644 --- a/Tests/Unit/SqlServerDSCHelper.Tests.ps1 +++ b/Tests/Unit/SqlServerDSCHelper.Tests.ps1 @@ -190,9 +190,9 @@ InModuleScope $script:moduleName { } } -Verifiable -ParameterFilter { $DisplayName -eq 'SQL Server (STOPPEDAGENT)' } - Mock -CommandName Restart-Service {} -Verifiable + Mock -CommandName Restart-Service -Verifiable - Mock -CommandName Start-Service {} -Verifiable + Mock -CommandName Start-Service -Verifiable It 'Should restart SQL Service and running SQL Agent service' { { Restart-SqlService -SQLServer $env:ComputerName -SQLInstanceName 'MSSQLSERVER' } | Should -Not -Throw @@ -272,9 +272,9 @@ InModuleScope $script:moduleName { return $mock } -Verifiable -ParameterFilter { $ResultClassName -eq 'MSCluster_Resource' } - Mock -CommandName Invoke-CimMethod -MockWith {} -Verifiable -ParameterFilter { $MethodName -eq 'TakeOffline' } + Mock -CommandName Invoke-CimMethod -Verifiable -ParameterFilter { $MethodName -eq 'TakeOffline' } - Mock -CommandName Invoke-CimMethod -MockWith {} -Verifiable -ParameterFilter { $MethodName -eq 'BringOnline' } + Mock -CommandName Invoke-CimMethod -Verifiable -ParameterFilter { $MethodName -eq 'BringOnline' } It 'Should restart SQL Server and SQL Agent resources for a clustered default instance' { { Restart-SqlService -SQLServer 'CLU01' } | Should -Not -Throw @@ -387,7 +387,7 @@ InModuleScope $script:moduleName { # This test is to test the mock so that it throws correct when data source is not the expected data source Context 'When connecting to the named instance using another data source then expected' { It 'Should throw the correct error' { - $mockExpectedDataSource = "Force wrong datasource" + $mockExpectedDataSource = "Force wrong data source" $testParameters = @{ SQLServer = 'DummyHost' @@ -1013,7 +1013,7 @@ InModuleScope $script:moduleName { } Context 'When the replica seeding mode is manual' { - # Test SQL 2012 and 2014. Not testing earlier versions because Availaiblity Groups were intoduced in SQL 2012. + # Test SQL 2012 and 2014. Not testing earlier versions because Availability Groups were introduced in SQL 2012. foreach ( $instanceVersion in @(11,12) ) { It ( 'Should return $false when the instance version is {0}' -f $instanceVersion ) {