diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..5613d5331 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Needed for publishing of examples, build worker defaults to core.autocrlf=input. +* text eol=crlf diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 index be415e4d5..8e184abcd 100644 --- a/.vscode/analyzersettings.psd1 +++ b/.vscode/analyzersettings.psd1 @@ -50,4 +50,6 @@ #> 'Measure-*' ) + + IncludeDefaultRules = $true } diff --git a/CHANGELOG.md b/CHANGELOG.md index a8433e723..5ba1e472c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,20 @@ ## Unreleased +- Changes to SqlServerDsc + - Add .gitattributes file to checkout file correctly with CRLF. + - Updated .vscode/analyzersettings.psd1 file to correct use PSSA rules + and custom rules in VS Code. + - Fix hashtables to align with style guideline ([issue #1437](https://github.com/PowerShell/SqlServerDsc/issues/1437)). +- Changes to SqlServerMaxDop + - Fix line endings in code which did not use the correct format. + ## 13.2.0.0 - Changes to SqlServerDsc - Fix keywords to lower-case to align with guideline. - Fix keywords to have space before a parenthesis to align with guideline. - - Fix typo in SqlSetup strings ([issue #1419](https://github.com/PowerShell/SqlServerDsc/issues/1419)) + - Fix typo in SqlSetup strings ([issue #1419](https://github.com/PowerShell/SqlServerDsc/issues/1419)). ## 13.1.0.0 diff --git a/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 b/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 index 5bdb4c10e..18632f490 100644 --- a/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 +++ b/DSCResources/MSFT_SqlDatabaseUser/MSFT_SqlDatabaseUser.psm1 @@ -517,7 +517,7 @@ function Test-TargetResource Make sure default values are part of desired values if the user did not specify them in the configuration. #> - $desiredValues = @{ } + $PSBoundParameters + $desiredValues = @{} + $PSBoundParameters $desiredValues['Ensure'] = $Ensure $desiredValues['UserType'] = $UserType diff --git a/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 b/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 index a45b793d3..91ff6e1f9 100644 --- a/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 +++ b/DSCResources/MSFT_SqlServerMaxDop/MSFT_SqlServerMaxDop.psm1 @@ -1,348 +1,348 @@ -$script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent -$script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules' - -$script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'SqlServerDsc.Common' -Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'SqlServerDsc.Common.psm1') - -$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerMaxDop' - -<# - .SYNOPSIS - This function gets the max degree of parallelism server configuration option. - - .PARAMETER ServerName - The host name of the SQL Server to be configured. - - .PARAMETER InstanceName - The name of the SQL instance to be configured. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $InstanceName, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String] - $ServerName = $env:COMPUTERNAME - ) - - Write-Verbose -Message ( - $script:localizedData.GetConfiguration -f $InstanceName - ) - - $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName - if ($sqlServerObject) - { - # Is this node actively hosting the SQL instance? - $isActiveNode = Test-ActiveNode -ServerObject $sqlServerObject - - $currentMaxDop = $sqlServerObject.Configuration.MaxDegreeOfParallelism.ConfigValue - } - - $returnValue = @{ - InstanceName = $InstanceName - ServerName = $ServerName - MaxDop = $currentMaxDop - IsActiveNode = $isActiveNode - } - - $returnValue -} - -<# - .SYNOPSIS - This function sets the max degree of parallelism server configuration option. - - .PARAMETER ServerName - The host name of the SQL Server to be configured. - - .PARAMETER InstanceName - The name of the SQL instance to be configured. - - .PARAMETER Ensure - When set to 'Present' then max degree of parallelism will be set to either the value in parameter MaxDop or dynamically configured when parameter DynamicAlloc is set to $true. - When set to 'Absent' max degree of parallelism will be set to 0 which means no limit in number of processors used in parallel plan execution. - - .PARAMETER DynamicAlloc - If set to $true then max degree of parallelism will be dynamically configured. - When this is set parameter is set to $true, the parameter MaxDop must be set to $null or not be configured. - - .PARAMETER MaxDop - A numeric value to limit the number of processors used in parallel plan execution. - - .PARAMETER ProcessOnlyOnActiveNode - Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server Instance. - Not used in Set-TargetResource. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $InstanceName, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String] - $ServerName = $env:COMPUTERNAME, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [ValidateNotNullOrEmpty()] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.Boolean] - $DynamicAlloc, - - [Parameter()] - [System.Int32] - $MaxDop, - - [Parameter()] - [System.Boolean] - $ProcessOnlyOnActiveNode - ) - - $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName - if ($sqlServerObject) - { - Write-Verbose -Message ( - $script:localizedData.SetConfiguration -f $InstanceName - ) - - switch ($Ensure) - { - 'Present' - { - if ($DynamicAlloc) - { - if ($MaxDop) - { - $errorMessage = $script:localizedData.MaxDopParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxDop' -Message $errorMessage - } - - $targetMaxDop = Get-SqlDscDynamicMaxDop -SqlServerObject $sqlServerObject - - Write-Verbose -Message ( - $script:localizedData.DynamicMaxDop -f $targetMaxDop - ) - } - else - { - $targetMaxDop = $MaxDop - } - } - - 'Absent' - { - $targetMaxDop = 0 - - Write-Verbose -Message ( - $script:localizedData.SettingDefaultValue -f $targetMaxDop - ) - } - } - - try - { - $sqlServerObject.Configuration.MaxDegreeOfParallelism.ConfigValue = $targetMaxDop - $sqlServerObject.Alter() - - Write-Verbose -Message ( - $script:localizedData.ChangeValue -f $targetMaxDop - ) - } - catch - { - $errorMessage = $script:localizedData.MaxDopSetError - New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ - } - } -} - -<# - .SYNOPSIS - This function tests the max degree of parallelism server configuration option. - - .PARAMETER ServerName - The host name of the SQL Server to be configured. - - .PARAMETER InstanceName - The name of the SQL instance to be configured. - - .PARAMETER Ensure - When set to 'Present' then max degree of parallelism will be set to either the value in parameter MaxDop or dynamically configured when parameter DynamicAlloc is set to $true. - When set to 'Absent' max degree of parallelism will be set to 0 which means no limit in number of processors used in parallel plan execution. - - .PARAMETER DynamicAlloc - If set to $true then max degree of parallelism will be dynamically configured. - When this is set parameter is set to $true, the parameter MaxDop must be set to $null or not be configured. - - .PARAMETER MaxDop - A numeric value to limit the number of processors used in parallel plan execution. - - .PARAMETER ProcessOnlyOnActiveNode - Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server Instance. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $InstanceName, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String] - $ServerName = $env:COMPUTERNAME, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [ValidateNotNullOrEmpty()] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.Boolean] - $DynamicAlloc, - - [Parameter()] - [System.Int32] - $MaxDop, - - [Parameter()] - [System.Boolean] - $ProcessOnlyOnActiveNode - ) - - Write-Verbose -Message ( - $script:localizedData.EvaluationConfiguration -f $targetMaxDop - ) - - $parameters = @{ - InstanceName = $InstanceName - ServerName = $ServerName - } - - $currentValues = Get-TargetResource @parameters - - $getMaxDop = $currentValues.MaxDop - $isMaxDopInDesiredState = $true - - <# - If this is supposed to process only the active node, and this is not the - active node, don't bother evaluating the test. - #> - if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) - { - Write-Verbose -Message ( - $script:localizedData.NotActiveNode -f $env:COMPUTERNAME, $InstanceName - ) - - return $isMaxDopInDesiredState - } - - switch ($Ensure) - { - 'Absent' - { - $defaultMaxDopValue = 0 - - if ($getMaxDop -ne $defaultMaxDopValue) - { - Write-Verbose -Message ( - $script:localizedData.WrongMaxDop -f $getMaxDop, $defaultMaxDopValue - ) - - $isMaxDopInDesiredState = $false - } - } - - 'Present' - { - if ($DynamicAlloc) - { - if ($MaxDop) - { - $errorMessage = $script:localizedData.MaxDopParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxDop' -Message $errorMessage - } - - $MaxDop = Get-SqlDscDynamicMaxDop - - Write-Verbose -Message ( - $script:localizedData.DynamicMaxDop -f $MaxDop - ) - } - - if ($getMaxDop -ne $MaxDop) - { - Write-Verbose -Message ( - $script:localizedData.WrongMaxDop -f $getMaxDop, $MaxDop - ) - - $isMaxDopInDesiredState = $false - } - } - } - - $isMaxDopInDesiredState -} - -<# - .SYNOPSIS - This cmdlet is used to return the dynamic max degree of parallelism -#> -function Get-SqlDscDynamicMaxDop -{ - $cimInstanceProc = Get-CimInstance -ClassName Win32_Processor - - # init variables - $numberOfLogicalProcessors = 0 - $numberOfCores = 0 - - # Loop through returned objects - foreach ($processor in $cimInstanceProc) - { - # increment number of processors - $numberOfLogicalProcessors += $processor.NumberOfLogicalProcessors - - # increment number of cores - $numberOfCores += $processor.NumberOfCores - } - - - if ($numberOfLogicalProcessors -eq 1) - { - $dynamicMaxDop = [Math]::Round($numberOfCores / 2, [System.MidpointRounding]::AwayFromZero) - } - elseif ($numberOfCores -ge 8) - { - $dynamicMaxDop = 8 - } - else - { - $dynamicMaxDop = $numberOfCores - } - - $dynamicMaxDop -} - -Export-ModuleMember -Function *-TargetResource +$script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent +$script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules' + +$script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'SqlServerDsc.Common' +Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'SqlServerDsc.Common.psm1') + +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerMaxDop' + +<# + .SYNOPSIS + This function gets the max degree of parallelism server configuration option. + + .PARAMETER ServerName + The host name of the SQL Server to be configured. + + .PARAMETER InstanceName + The name of the SQL instance to be configured. +#> +function Get-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Collections.Hashtable])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $InstanceName, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $ServerName = $env:COMPUTERNAME + ) + + Write-Verbose -Message ( + $script:localizedData.GetConfiguration -f $InstanceName + ) + + $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName + if ($sqlServerObject) + { + # Is this node actively hosting the SQL instance? + $isActiveNode = Test-ActiveNode -ServerObject $sqlServerObject + + $currentMaxDop = $sqlServerObject.Configuration.MaxDegreeOfParallelism.ConfigValue + } + + $returnValue = @{ + InstanceName = $InstanceName + ServerName = $ServerName + MaxDop = $currentMaxDop + IsActiveNode = $isActiveNode + } + + $returnValue +} + +<# + .SYNOPSIS + This function sets the max degree of parallelism server configuration option. + + .PARAMETER ServerName + The host name of the SQL Server to be configured. + + .PARAMETER InstanceName + The name of the SQL instance to be configured. + + .PARAMETER Ensure + When set to 'Present' then max degree of parallelism will be set to either the value in parameter MaxDop or dynamically configured when parameter DynamicAlloc is set to $true. + When set to 'Absent' max degree of parallelism will be set to 0 which means no limit in number of processors used in parallel plan execution. + + .PARAMETER DynamicAlloc + If set to $true then max degree of parallelism will be dynamically configured. + When this is set parameter is set to $true, the parameter MaxDop must be set to $null or not be configured. + + .PARAMETER MaxDop + A numeric value to limit the number of processors used in parallel plan execution. + + .PARAMETER ProcessOnlyOnActiveNode + Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server Instance. + Not used in Set-TargetResource. +#> +function Set-TargetResource +{ + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $InstanceName, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $ServerName = $env:COMPUTERNAME, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [ValidateNotNullOrEmpty()] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Boolean] + $DynamicAlloc, + + [Parameter()] + [System.Int32] + $MaxDop, + + [Parameter()] + [System.Boolean] + $ProcessOnlyOnActiveNode + ) + + $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName + if ($sqlServerObject) + { + Write-Verbose -Message ( + $script:localizedData.SetConfiguration -f $InstanceName + ) + + switch ($Ensure) + { + 'Present' + { + if ($DynamicAlloc) + { + if ($MaxDop) + { + $errorMessage = $script:localizedData.MaxDopParamMustBeNull + New-InvalidArgumentException -ArgumentName 'MaxDop' -Message $errorMessage + } + + $targetMaxDop = Get-SqlDscDynamicMaxDop -SqlServerObject $sqlServerObject + + Write-Verbose -Message ( + $script:localizedData.DynamicMaxDop -f $targetMaxDop + ) + } + else + { + $targetMaxDop = $MaxDop + } + } + + 'Absent' + { + $targetMaxDop = 0 + + Write-Verbose -Message ( + $script:localizedData.SettingDefaultValue -f $targetMaxDop + ) + } + } + + try + { + $sqlServerObject.Configuration.MaxDegreeOfParallelism.ConfigValue = $targetMaxDop + $sqlServerObject.Alter() + + Write-Verbose -Message ( + $script:localizedData.ChangeValue -f $targetMaxDop + ) + } + catch + { + $errorMessage = $script:localizedData.MaxDopSetError + New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ + } + } +} + +<# + .SYNOPSIS + This function tests the max degree of parallelism server configuration option. + + .PARAMETER ServerName + The host name of the SQL Server to be configured. + + .PARAMETER InstanceName + The name of the SQL instance to be configured. + + .PARAMETER Ensure + When set to 'Present' then max degree of parallelism will be set to either the value in parameter MaxDop or dynamically configured when parameter DynamicAlloc is set to $true. + When set to 'Absent' max degree of parallelism will be set to 0 which means no limit in number of processors used in parallel plan execution. + + .PARAMETER DynamicAlloc + If set to $true then max degree of parallelism will be dynamically configured. + When this is set parameter is set to $true, the parameter MaxDop must be set to $null or not be configured. + + .PARAMETER MaxDop + A numeric value to limit the number of processors used in parallel plan execution. + + .PARAMETER ProcessOnlyOnActiveNode + Specifies that the resource will only determine if a change is needed if the target node is the active host of the SQL Server Instance. +#> +function Test-TargetResource +{ + [CmdletBinding()] + [OutputType([System.Boolean])] + param + ( + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [System.String] + $InstanceName, + + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $ServerName = $env:COMPUTERNAME, + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [ValidateNotNullOrEmpty()] + [System.String] + $Ensure = 'Present', + + [Parameter()] + [System.Boolean] + $DynamicAlloc, + + [Parameter()] + [System.Int32] + $MaxDop, + + [Parameter()] + [System.Boolean] + $ProcessOnlyOnActiveNode + ) + + Write-Verbose -Message ( + $script:localizedData.EvaluationConfiguration -f $targetMaxDop + ) + + $parameters = @{ + InstanceName = $InstanceName + ServerName = $ServerName + } + + $currentValues = Get-TargetResource @parameters + + $getMaxDop = $currentValues.MaxDop + $isMaxDopInDesiredState = $true + + <# + If this is supposed to process only the active node, and this is not the + active node, don't bother evaluating the test. + #> + if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) + { + Write-Verbose -Message ( + $script:localizedData.NotActiveNode -f $env:COMPUTERNAME, $InstanceName + ) + + return $isMaxDopInDesiredState + } + + switch ($Ensure) + { + 'Absent' + { + $defaultMaxDopValue = 0 + + if ($getMaxDop -ne $defaultMaxDopValue) + { + Write-Verbose -Message ( + $script:localizedData.WrongMaxDop -f $getMaxDop, $defaultMaxDopValue + ) + + $isMaxDopInDesiredState = $false + } + } + + 'Present' + { + if ($DynamicAlloc) + { + if ($MaxDop) + { + $errorMessage = $script:localizedData.MaxDopParamMustBeNull + New-InvalidArgumentException -ArgumentName 'MaxDop' -Message $errorMessage + } + + $MaxDop = Get-SqlDscDynamicMaxDop + + Write-Verbose -Message ( + $script:localizedData.DynamicMaxDop -f $MaxDop + ) + } + + if ($getMaxDop -ne $MaxDop) + { + Write-Verbose -Message ( + $script:localizedData.WrongMaxDop -f $getMaxDop, $MaxDop + ) + + $isMaxDopInDesiredState = $false + } + } + } + + $isMaxDopInDesiredState +} + +<# + .SYNOPSIS + This cmdlet is used to return the dynamic max degree of parallelism +#> +function Get-SqlDscDynamicMaxDop +{ + $cimInstanceProc = Get-CimInstance -ClassName Win32_Processor + + # init variables + $numberOfLogicalProcessors = 0 + $numberOfCores = 0 + + # Loop through returned objects + foreach ($processor in $cimInstanceProc) + { + # increment number of processors + $numberOfLogicalProcessors += $processor.NumberOfLogicalProcessors + + # increment number of cores + $numberOfCores += $processor.NumberOfCores + } + + + if ($numberOfLogicalProcessors -eq 1) + { + $dynamicMaxDop = [Math]::Round($numberOfCores / 2, [System.MidpointRounding]::AwayFromZero) + } + elseif ($numberOfCores -ge 8) + { + $dynamicMaxDop = 8 + } + else + { + $dynamicMaxDop = $numberOfCores + } + + $dynamicMaxDop +} + +Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 index d9d237243..d2b49957d 100644 --- a/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 +++ b/DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1 @@ -1275,7 +1275,9 @@ function Set-TargetResource } # Add the cluster disks as a setup argument - $setupArguments += @{ FailoverClusterDisks = ($failoverClusterDisks | Sort-Object) } + $setupArguments += @{ + FailoverClusterDisks = ($failoverClusterDisks | Sort-Object) + } } # Determine network mapping for specific cluster installation types @@ -1320,7 +1322,9 @@ function Set-TargetResource } # Add the networks to the installation arguments - $setupArguments += @{ FailoverClusterIPAddresses = $clusterIPAddresses } + $setupArguments += @{ + FailoverClusterIPAddresses = $clusterIPAddresses + } } # Add standard install arguments @@ -1369,7 +1373,9 @@ function Set-TargetResource if ($SecurityMode -eq 'SQL') { - $setupArguments += @{ SAPwd = $SAPwd.GetNetworkCredential().Password } + $setupArguments += @{ + SAPwd = $SAPwd.GetNetworkCredential().Password + } } # Should not be passed when PrepareFailoverCluster is specified @@ -1382,7 +1388,9 @@ function Set-TargetResource system administrator. The username is stored in $PsDscContext.RunAsUser. #> Write-Verbose -Message ($script:localizedData.AddingFirstSystemAdministratorSqlServer -f $($PsDscContext.RunAsUser)) - $setupArguments += @{ SQLSysAdminAccounts = @($PsDscContext.RunAsUser) } + $setupArguments += @{ + SQLSysAdminAccounts = @($PsDscContext.RunAsUser) + } } if ($PSBoundParameters.ContainsKey('SQLSysAdminAccounts')) @@ -1405,31 +1413,41 @@ function Set-TargetResource # tempdb : define SqlTempdbFileCount if ($PSBoundParameters.ContainsKey('SqlTempdbFileCount')) { - $setupArguments += @{ SqlTempdbFileCount = $SqlTempdbFileCount } + $setupArguments += @{ + SqlTempdbFileCount = $SqlTempdbFileCount + } } # tempdb : define SqlTempdbFileSize if ($PSBoundParameters.ContainsKey('SqlTempdbFileSize')) { - $setupArguments += @{ SqlTempdbFileSize = $SqlTempdbFileSize } + $setupArguments += @{ + SqlTempdbFileSize = $SqlTempdbFileSize + } } # tempdb : define SqlTempdbFileGrowth if ($PSBoundParameters.ContainsKey('SqlTempdbFileGrowth')) { - $setupArguments += @{ SqlTempdbFileGrowth = $SqlTempdbFileGrowth } + $setupArguments += @{ + SqlTempdbFileGrowth = $SqlTempdbFileGrowth + } } # tempdb : define SqlTempdbLogFileSize if ($PSBoundParameters.ContainsKey('SqlTempdbLogFileSize')) { - $setupArguments += @{ SqlTempdbLogFileSize = $SqlTempdbLogFileSize } + $setupArguments += @{ + SqlTempdbLogFileSize = $SqlTempdbLogFileSize + } } # tempdb : define SqlTempdbLogFileGrowth if ($PSBoundParameters.ContainsKey('SqlTempdbLogFileGrowth')) { - $setupArguments += @{ SqlTempdbLogFileGrowth = $SqlTempdbLogFileGrowth } + $setupArguments += @{ + SqlTempdbLogFileGrowth = $SqlTempdbLogFileGrowth + } } if ($Action -in @('Install','Upgrade')) @@ -1440,12 +1458,16 @@ function Set-TargetResource } else { - $setupArguments += @{ AgtSvcStartupType = 'Automatic' } + $setupArguments += @{ + AgtSvcStartupType = 'Automatic' + } } if ($PSBoundParameters.ContainsKey('SqlSvcStartupType')) { - $setupArguments += @{ SqlSvcStartupType = $SqlSvcStartupType} + $setupArguments += @{ + SqlSvcStartupType = $SqlSvcStartupType + } } } } @@ -1466,11 +1488,15 @@ function Set-TargetResource } if ($PSBoundParameters.ContainsKey('RsSvcStartupType')) { - $setupArguments += @{ RsSvcStartupType = $RsSvcStartupType} + $setupArguments += @{ + RsSvcStartupType = $RsSvcStartupType + } } if ($PSBoundParameters.ContainsKey('RSInstallMode')) { - $setupArguments += @{ RSINSTALLMODE = $RSInstallMode} + $setupArguments += @{ + RSINSTALLMODE = $RSInstallMode + } } } @@ -1505,7 +1531,9 @@ function Set-TargetResource system administrator. The username is stored in $PsDscContext.RunAsUser. #> Write-Verbose -Message ($script:localizedData.AddingFirstSystemAdministratorAnalysisServices -f $($PsDscContext.RunAsUser)) - $setupArguments += @{ ASSysAdminAccounts = @($PsDscContext.RunAsUser) } + $setupArguments += @{ + ASSysAdminAccounts = @($PsDscContext.RunAsUser) + } } if ($PSBoundParameters.ContainsKey("ASSysAdminAccounts")) @@ -1516,7 +1544,9 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('AsSvcStartupType')) { - $setupArguments += @{ AsSvcStartupType = $AsSvcStartupType} + $setupArguments += @{ + AsSvcStartupType = $AsSvcStartupType + } } } @@ -1529,7 +1559,9 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('IsSvcStartupType')) { - $setupArguments += @{ IsSvcStartupType = $IsSvcStartupType} + $setupArguments += @{ + IsSvcStartupType = $IsSvcStartupType + } } } @@ -1538,14 +1570,18 @@ function Set-TargetResource { if ($argument -eq 'ProductKey') { - $setupArguments += @{ 'PID' = (Get-Variable -Name $argument -ValueOnly) } + $setupArguments += @{ + 'PID' = (Get-Variable -Name $argument -ValueOnly) + } } else { # If the argument contains a value, then add the argument to the setup argument list if (Get-Variable -Name $argument -ValueOnly) { - $setupArguments += @{ $argument = (Get-Variable -Name $argument -ValueOnly) } + $setupArguments += @{ + $argument = (Get-Variable -Name $argument -ValueOnly) + } } } } @@ -1564,7 +1600,11 @@ function Set-TargetResource } elseif ($currentSetupArgument.Value -is [System.Boolean]) { - $setupArgumentValue = @{ $true = 'True'; $false = 'False' }[$currentSetupArgument.Value] + $setupArgumentValue = @{ + $true = 'True' + $false = 'False' + }[$currentSetupArgument.Value] + $setupArgumentValue = '"{0}"' -f $setupArgumentValue } else diff --git a/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 b/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 index 3dc00e4ce..0a386b6d1 100644 --- a/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 +++ b/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1 @@ -1412,17 +1412,23 @@ function Restart-SqlService # Stop the SQL Server and dependent resources Write-Verbose -Message ($script:localizedData.BringClusterResourcesOffline -f $resourceNames) -Verbose - $sqlService | Invoke-CimMethod -MethodName TakeOffline -Arguments @{ Timeout = $Timeout } + $sqlService | Invoke-CimMethod -MethodName TakeOffline -Arguments @{ + Timeout = $Timeout + } # Start the SQL server resource Write-Verbose -Message ($script:localizedData.BringSqlServerClusterResourcesOnline) -Verbose - $sqlService | Invoke-CimMethod -MethodName BringOnline -Arguments @{ Timeout = $Timeout } + $sqlService | Invoke-CimMethod -MethodName BringOnline -Arguments @{ + Timeout = $Timeout + } # Start the SQL Agent resource if ($agentService) { Write-Verbose -Message ($script:localizedData.BringSqlServerAgentClusterResourcesOnline) -Verbose - $agentService | Invoke-CimMethod -MethodName BringOnline -Arguments @{ Timeout = $Timeout } + $agentService | Invoke-CimMethod -MethodName BringOnline -Arguments @{ + Timeout = $Timeout + } } } else diff --git a/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 b/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 index 2237aa797..4e1534cc3 100644 --- a/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerReplication.Tests.ps1 @@ -44,25 +44,35 @@ try InModuleScope $script:dscResourceName { Describe 'Helper functions' { Context 'Get-SqlServerMajorVersion' { - - Mock -CommandName Get-ItemProperty ` - -MockWith { return [pscustomobject]@{ MSSQLSERVER = 'MSSQL12.MSSQLSERVER'} } ` - -ParameterFilter { $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL' } + Mock -CommandName Get-ItemProperty -MockWith { + return [PSCustomObject] @{ + MSSQLSERVER = 'MSSQL12.MSSQLSERVER' + } + } -ParameterFilter { + $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL' + } It 'Should return correct major version for default instance' { - - Mock -CommandName Get-ItemProperty ` - -MockWith { return [pscustomobject]@{ Version = '12.1.4100.1' } } ` - -ParameterFilter { $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.MSSQLSERVER\Setup' } + Mock -CommandName Get-ItemProperty -MockWith { + return [PSCustomObject] @{ + Version = '12.1.4100.1' + } + } -ParameterFilter { + $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.MSSQLSERVER\Setup' + } Get-SqlServerMajorVersion -InstanceName 'MSSQLSERVER' | Should -Be '12' } It 'Should throw error if major version cannot be resolved' { - Mock -CommandName Get-ItemProperty ` - -MockWith { return [pscustomobject]@{ Version = '' } }` - -ParameterFilter { $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.MSSQLSERVER\Setup' } + Mock -CommandName Get-ItemProperty -MockWith { + return [PSCustomObject] @{ + Version = '' + } + } -ParameterFilter { + $Path -eq 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.MSSQLSERVER\Setup' + } { Get-SqlServerMajorVersion -InstanceName 'MSSQLSERVER' } | Should -Throw ($script:localizedData.FailedToDetectSqlVersion -f 'MSSQLSERVER') } @@ -96,12 +106,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $false IsPublisher = $false DistributionDatabase = '' @@ -109,7 +119,7 @@ try WorkingDirectory = '' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } @@ -230,12 +240,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME\INSTANCENAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $false IsPublisher = $false DistributionDatabase = '' @@ -243,7 +253,7 @@ try WorkingDirectory = '' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } @@ -375,12 +385,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $true IsPublisher = $true DistributionDatabase = 'distribution' @@ -388,7 +398,7 @@ try WorkingDirectory = 'C:\temp' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } @@ -503,12 +513,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME\INSTANCENAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $false IsPublisher = $true DistributionDatabase = 'distribution' @@ -516,13 +526,13 @@ try WorkingDirectory = 'C:\temp' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } Mock -CommandName Uninstall-Distributor -MockWith {} - Context 'Get methot' { + Context 'Get method' { $result = Get-TargetResource @testParameters It 'Get method calls Get-SqlServerMajorVersion with $InstanceName = INSTANCENAME' { Assert-MockCalled -CommandName Get-SqlServerMajorVersion -Times 1 ` @@ -630,12 +640,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $true IsPublisher = $true DistributionDatabase = 'distribution' @@ -643,7 +653,7 @@ try WorkingDirectory = 'C:\temp' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } @@ -760,12 +770,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME\INSTANCENAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $false IsPublisher = $true DistributionDatabase = 'distribution' @@ -773,13 +783,13 @@ try WorkingDirectory = 'C:\temp' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } Mock -CommandName Uninstall-Distributor -MockWith {} - Context 'Get methot' { + Context 'Get method' { $result = Get-TargetResource @testParameters It 'Get method calls Get-SqlServerMajorVersion with $InstanceName = INSTANCENAME' { Assert-MockCalled -CommandName Get-SqlServerMajorVersion -Times 1 ` @@ -888,12 +898,12 @@ try Mock -CommandName Get-SqlServerMajorVersion -MockWith { return '99' } Mock -CommandName Get-SqlLocalServerName -MockWith { return 'SERVERNAME' } Mock -CommandName New-ServerConnection -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ ServerInstance = $SqlServerName } } Mock -CommandName New-ReplicationServer -MockWith { - return [pscustomobject]@{ + return [PSCustomObject] @{ IsDistributor = $false IsPublisher = $false DistributionDatabase = '' @@ -901,7 +911,7 @@ try WorkingDirectory = '' } } - Mock -CommandName New-DistributionDatabase -MockWith { return [pscustomobject]@{} } + Mock -CommandName New-DistributionDatabase -MockWith { return [PSCustomObject] @{} } Mock -CommandName Install-LocalDistributor -MockWith { } Mock -CommandName Install-RemoteDistributor -MockWith { } Mock -CommandName Register-DistributorPublisher -MockWith { } diff --git a/Tests/Unit/MSFT_SqlSetup.Tests.ps1 b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 index af8860924..d824b620f 100644 --- a/Tests/Unit/MSFT_SqlSetup.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlSetup.Tests.ps1 @@ -717,7 +717,9 @@ try New-Object -TypeName Microsoft.Management.Infrastructure.CimInstance 'MSCluster_Resource','root/MSCluster' | Add-Member -MemberType NoteProperty -Name 'Name' -Value "SQL Server ($mockCurrentInstanceName)" -PassThru -Force | Add-Member -MemberType NoteProperty -Name 'Type' -Value 'SQL Server' -TypeName 'String' -PassThru -Force | - Add-Member -MemberType NoteProperty -Name 'PrivateProperties' -Value @{ InstanceName = $mockCurrentInstanceName } -PassThru -Force + Add-Member -MemberType NoteProperty -Name 'PrivateProperties' -Value @{ + InstanceName = $mockCurrentInstanceName + } -PassThru -Force ) ) } @@ -836,12 +838,16 @@ try { 'Network Name' { - $propertyValue.Value = @{ DnsName = $mockDefaultInstance_FailoverClusterNetworkName } + $propertyValue.Value = @{ + DnsName = $mockDefaultInstance_FailoverClusterNetworkName + } } 'IP Address' { - $propertyValue.Value = @{ Address = $mockDefaultInstance_FailoverClusterIPAddress } + $propertyValue.Value = @{ + Address = $mockDefaultInstance_FailoverClusterIPAddress + } } } diff --git a/Tests/Unit/SqlServerDsc.Common.Tests.ps1 b/Tests/Unit/SqlServerDsc.Common.Tests.ps1 index 482697f2e..04a75aa51 100644 --- a/Tests/Unit/SqlServerDsc.Common.Tests.ps1 +++ b/Tests/Unit/SqlServerDsc.Common.Tests.ps1 @@ -32,7 +32,9 @@ InModuleScope 'SqlServerDsc.Common' { Describe 'SqlServerDsc.Common\Test-DscParameterState' -Tag 'TestDscParameterState' { Context -Name 'When passing values' -Fixture { It 'Should return true for two identical tables' { - $mockDesiredValues = @{ Example = 'test' } + $mockDesiredValues = @{ + Example = 'test' + } $testParameters = @{ CurrentValues = $mockDesiredValues @@ -43,8 +45,13 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when a value is different for [System.String]' { - $mockCurrentValues = @{ Example = [System.String] 'something' } - $mockDesiredValues = @{ Example = [System.String] 'test' } + $mockCurrentValues = @{ + Example = [System.String] 'something' + } + + $mockDesiredValues = @{ + Example = [System.String] 'test' + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -55,8 +62,13 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when a value is different for [System.Int32]' { - $mockCurrentValues = @{ Example = [System.Int32] 1 } - $mockDesiredValues = @{ Example = [System.Int32] 2 } + $mockCurrentValues = @{ + Example = [System.Int32] 1 + } + + $mockDesiredValues = @{ + Example = [System.Int32] 2 + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -67,8 +79,13 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when a value is different for [Int16]' { - $mockCurrentValues = @{ Example = [System.Int16] 1 } - $mockDesiredValues = @{ Example = [System.Int16] 2 } + $mockCurrentValues = @{ + Example = [System.Int16] 1 + } + + $mockDesiredValues = @{ + Example = [System.Int16] 2 + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -79,8 +96,13 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when a value is different for [UInt16]' { - $mockCurrentValues = @{ Example = [System.UInt16] 1 } - $mockDesiredValues = @{ Example = [System.UInt16] 2 } + $mockCurrentValues = @{ + Example = [System.UInt16] 1 + } + + $mockDesiredValues = @{ + Example = [System.UInt16] 2 + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -91,8 +113,13 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when a value is different for [Boolean]' { - $mockCurrentValues = @{ Example = [System.Boolean] $true } - $mockDesiredValues = @{ Example = [System.Boolean] $false } + $mockCurrentValues = @{ + Example = [System.Boolean] $true + } + + $mockDesiredValues = @{ + Example = [System.Boolean] $false + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -103,8 +130,10 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when a value is missing' { - $mockCurrentValues = @{ } - $mockDesiredValues = @{ Example = 'test' } + $mockCurrentValues = @{} + $mockDesiredValues = @{ + Example = 'test' + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -115,8 +144,15 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return true when only a specified value matches, but other non-listed values do not' { - $mockCurrentValues = @{ Example = 'test'; SecondExample = 'true' } - $mockDesiredValues = @{ Example = 'test'; SecondExample = 'false' } + $mockCurrentValues = @{ + Example = 'test' + SecondExample = 'true' + } + + $mockDesiredValues = @{ + Example = 'test' + SecondExample = 'false' + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -128,8 +164,15 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when only specified values do not match, but other non-listed values do ' { - $mockCurrentValues = @{ Example = 'test'; SecondExample = 'true' } - $mockDesiredValues = @{ Example = 'test'; SecondExample = 'false' } + $mockCurrentValues = @{ + Example = 'test' + SecondExample = 'true' + } + + $mockDesiredValues = @{ + Example = 'test' + SecondExample = 'false' + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -141,8 +184,11 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when an empty hash table is used in the current values' { - $mockCurrentValues = @{ } - $mockDesiredValues = @{ Example = 'test'; SecondExample = 'false' } + $mockCurrentValues = @{} + $mockDesiredValues = @{ + Example = 'test' + SecondExample = 'false' + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -153,7 +199,10 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return true when evaluating a table against a CimInstance' { - $mockCurrentValues = @{ Handle = '0'; ProcessId = '1000' } + $mockCurrentValues = @{ + Handle = '0' + ProcessId = '1000' + } $mockWin32ProcessProperties = @{ Handle = 0 @@ -179,7 +228,10 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when evaluating a table against a CimInstance and a value is wrong' { - $mockCurrentValues = @{ Handle = '1'; ProcessId = '1000' } + $mockCurrentValues = @{ + Handle = '1' + ProcessId = '1000' + } $mockWin32ProcessProperties = @{ Handle = 0 @@ -205,8 +257,15 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return true when evaluating a hash table containing an array' { - $mockCurrentValues = @{ Example = 'test'; SecondExample = @('1','2') } - $mockDesiredValues = @{ Example = 'test'; SecondExample = @('1','2') } + $mockCurrentValues = @{ + Example = 'test' + SecondExample = @('1','2') + } + + $mockDesiredValues = @{ + Example = 'test' + SecondExample = @('1','2') + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -217,8 +276,15 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when evaluating a hash table containing an array with wrong values' { - $mockCurrentValues = @{ Example = 'test'; SecondExample = @('A','B') } - $mockDesiredValues = @{ Example = 'test'; SecondExample = @('1','2') } + $mockCurrentValues = @{ + Example = 'test' + SecondExample = @('A','B') + } + + $mockDesiredValues = @{ + Example = 'test' + SecondExample = @('1','2') + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -229,8 +295,14 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when evaluating a hash table containing an array, but the CurrentValues are missing an array' { - $mockCurrentValues = @{ Example = 'test' } - $mockDesiredValues = @{ Example = 'test'; SecondExample = @('1','2') } + $mockCurrentValues = @{ + Example = 'test' + } + + $mockDesiredValues = @{ + Example = 'test' + SecondExample = @('1','2') + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -241,8 +313,15 @@ InModuleScope 'SqlServerDsc.Common' { } It 'Should return false when evaluating a hash table containing an array, but the property i CurrentValues is $null' { - $mockCurrentValues = @{ Example = 'test'; SecondExample = $null } - $mockDesiredValues = @{ Example = 'test'; SecondExample = @('1','2') } + $mockCurrentValues = @{ + Example = 'test' + SecondExample = $null + } + + $mockDesiredValues = @{ + Example = 'test' + SecondExample = @('1','2') + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -255,7 +334,10 @@ InModuleScope 'SqlServerDsc.Common' { Context -Name 'When passing invalid types for DesiredValues' -Fixture { It 'Should throw the correct error when DesiredValues is of wrong type' { - $mockCurrentValues = @{ Example = 'something' } + $mockCurrentValues = @{ + Example = 'something' + } + $mockDesiredValues = 'NotHashTable' $testParameters = @{ @@ -286,8 +368,13 @@ InModuleScope 'SqlServerDsc.Common' { } } - $mockCurrentValues = @{ Example = New-Object -TypeName MockUnknownType } - $mockDesiredValues = @{ Example = New-Object -TypeName MockUnknownType } + $mockCurrentValues = @{ + Example = New-Object -TypeName MockUnknownType + } + + $mockDesiredValues = @{ + Example = New-Object -TypeName MockUnknownType + } $testParameters = @{ CurrentValues = $mockCurrentValues @@ -302,7 +389,9 @@ InModuleScope 'SqlServerDsc.Common' { Context -Name 'When passing an CimInstance as DesiredValue and ValuesToCheck is $null' -Fixture { It 'Should throw the correct error' { - $mockCurrentValues = @{ Example = 'something' } + $mockCurrentValues = @{ + Example = 'something' + } $mockWin32ProcessProperties = @{ Handle = 0 @@ -1190,7 +1279,9 @@ InModuleScope 'SqlServerDsc.Common' { $mock | Add-Member -MemberType NoteProperty -Name 'Name' -Value "SQL Server ($($_))" -TypeName 'String' $mock | Add-Member -MemberType NoteProperty -Name 'Type' -Value 'SQL Server' -TypeName 'String' - $mock | Add-Member -MemberType NoteProperty -Name 'PrivateProperties' -Value @{ InstanceName = $_ } + $mock | Add-Member -MemberType NoteProperty -Name 'PrivateProperties' -Value @{ + InstanceName = $_ + } return $mock } @@ -1201,7 +1292,12 @@ InModuleScope 'SqlServerDsc.Common' { $mock | Add-Member -MemberType NoteProperty -Name 'Name' -Value "SQL Server Agent ($($InputObject.PrivateProperties.InstanceName))" -TypeName 'String' $mock | Add-Member -MemberType NoteProperty -Name 'Type' -Value 'SQL Server Agent' -TypeName 'String' - $mock | Add-Member -MemberType NoteProperty -Name 'State' -Value (@{ $true = 3; $false = 2 }[($InputObject.PrivateProperties.InstanceName -eq 'STOPPEDAGENT')]) -TypeName 'Int32' + $mock | Add-Member -MemberType NoteProperty -Name 'State' -Value ( + @{ + $true = 3 + $false = 2 + }[($InputObject.PrivateProperties.InstanceName -eq 'STOPPEDAGENT')] + ) -TypeName 'Int32' return $mock } -Verifiable -ParameterFilter { $ResultClassName -eq 'MSCluster_Resource' }