From 5faea8cfcac7abb96987c8c313b514528f71298d Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 27 Apr 2019 16:58:37 +0200 Subject: [PATCH] SqlDatabaseRecoveryModel: Added localization (#1340) - Changes to SqlDatabaseRecoveryModel - Added en-US localization (issue #609). --- CHANGELOG.md | 2 + .../MSFT_SqlDatabaseRecoveryModel.psm1 | 50 +++++++++++-------- ...MSFT_SqlDatabaseRecoveryModel.strings.psd1 | 8 +++ .../MSFT_SqlDatabaseRecoveryModel.Tests.ps1 | 10 ++-- 4 files changed, 43 insertions(+), 27 deletions(-) create mode 100644 DSCResources/MSFT_SqlDatabaseRecoveryModel/en-US/MSFT_SqlDatabaseRecoveryModel.strings.psd1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 083fb2a57..8027e1349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,8 @@ - Added en-US localization ([issue #613](https://github.com/PowerShell/SqlServerDsc/issues/613)). - Changes to SqlDatabaseRole - Added en-US localization ([issue #610](https://github.com/PowerShell/SqlServerDsc/issues/610)). +- Changes to SqlDatabaseRecoveryModel + - Added en-US localization ([issue #609](https://github.com/PowerShell/SqlServerDsc/issues/609)). ## 12.4.0.0 diff --git a/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 b/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 index 4d2c52792..bc8a9b180 100644 --- a/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 +++ b/DSCResources/MSFT_SqlDatabaseRecoveryModel/MSFT_SqlDatabaseRecoveryModel.psm1 @@ -7,11 +7,13 @@ Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath ' $script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'DscResource.Common' Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'DscResource.Common.psm1') +$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseRecoveryModel' + <# .SYNOPSIS This function gets all Key properties defined in the resource schema file - .PARAMETER Database + .PARAMETER Name This is the SQL database .PARAMETER RecoveryModel @@ -51,41 +53,42 @@ function Get-TargetResource $Name ) - $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName + Write-Verbose -Message ( + $script:localizedData.GetRecoveryModel -f $Name, $InstanceName + ) + $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName if ($sqlServerObject) { - Write-Verbose -Message "Getting RecoveryModel of SQL database '$Name'" $sqlDatabaseObject = $sqlServerObject.Databases[$Name] - if ($sqlDatabaseObject) { $sqlDatabaseRecoveryModel = $sqlDatabaseObject.RecoveryModel - New-VerboseMessage -Message "The current recovery model used by database $Name is '$sqlDatabaseRecoveryModel'" + + Write-Verbose -Message ( + $script:localizedData.CurrentRecoveryModel -f $sqlDatabaseRecoveryModel, $Name + ) } else { - throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Name, $ServerName, $InstanceName) ` - -ErrorCategory InvalidResult + $errorMessage = $script:localizedData.DatabaseNotFound -f $Name + New-InvalidResultException -Message $errorMessage } } - $returnValue = @{ + return @{ Name = $Name RecoveryModel = $sqlDatabaseRecoveryModel ServerName = $ServerName InstanceName = $InstanceName } - - $returnValue } <# .SYNOPSIS This function gets all Key properties defined in the resource schema file - .PARAMETER Database + .PARAMETER Name This is the SQL database .PARAMETER RecoveryModel @@ -125,26 +128,29 @@ function Set-TargetResource ) $sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName - if ($sqlServerObject) { - Write-Verbose -Message "Setting RecoveryModel of SQL database '$Name'" - $sqlDatabaseObject = $sqlServerObject.Databases[$Name] + Write-Verbose -Message ( + $script:localizedData.SetRecoveryModel -f $Name + ) + $sqlDatabaseObject = $sqlServerObject.Databases[$Name] if ($sqlDatabaseObject) { if ($sqlDatabaseObject.RecoveryModel -ne $RecoveryModel) { $sqlDatabaseObject.RecoveryModel = $RecoveryModel $sqlDatabaseObject.Alter() - New-VerboseMessage -Message "The recovery model for the database $Name is changed to '$RecoveryModel'." + + Write-Verbose -Message ( + $script:localizedData.ChangeRecoveryModel -f $Name, $RecoveryModel + ) } } else { - throw New-TerminatingError -ErrorType NoDatabase ` - -FormatArgs @($Name, $ServerName, $InstanceName) ` - -ErrorCategory InvalidResult + $errorMessage = $script:localizedData.DatabaseNotFound -f $Name + New-InvalidResultException -Message $errorMessage } } } @@ -153,7 +159,7 @@ function Set-TargetResource .SYNOPSIS This function gets all Key properties defined in the resource schema file - .PARAMETER Database + .PARAMETER Name This is the SQL database .PARAMETER RecoveryModel @@ -193,7 +199,9 @@ function Test-TargetResource $Name ) - Write-Verbose -Message "Testing RecoveryModel of database '$Name'" + Write-Verbose -Message ( + $script:localizedData.TestingConfiguration -f $Name, $InstanceName + ) $currentValues = Get-TargetResource @PSBoundParameters diff --git a/DSCResources/MSFT_SqlDatabaseRecoveryModel/en-US/MSFT_SqlDatabaseRecoveryModel.strings.psd1 b/DSCResources/MSFT_SqlDatabaseRecoveryModel/en-US/MSFT_SqlDatabaseRecoveryModel.strings.psd1 new file mode 100644 index 000000000..121e5b0ac --- /dev/null +++ b/DSCResources/MSFT_SqlDatabaseRecoveryModel/en-US/MSFT_SqlDatabaseRecoveryModel.strings.psd1 @@ -0,0 +1,8 @@ +ConvertFrom-StringData @' + GetRecoveryModel = Get the current recovery model of the database '{0}' in the instance '{1}'. + CurrentRecoveryModel = The current recovery model is '{0}' for the database '{1}'. + DatabaseNotFound = The database '{0}' does not exist. + SetRecoveryModel = Setting the recovery model of database '{0}'. + ChangeRecoveryModel = The recovery model for the database '{0}' was changed to '{1}'. + TestingConfiguration = Determines if the database '{0}' on the instance '{1}' has the desired recovery model. +'@ diff --git a/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 index 5b6c2b664..00cb72363 100644 --- a/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1 @@ -109,10 +109,9 @@ try RecoveryModel = 'Full' } - $throwInvalidOperation = ("Database 'UnknownDatabase' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") + $errorMessage = $script:localizedData.DatabaseNotFound -f $testParameters.Name - { Get-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + { Get-TargetResource @testParameters } | Should -Throw $errorMessage } It 'Should call the mock function Connect-SQL' { @@ -224,10 +223,9 @@ try RecoveryModel = 'Full' } - $throwInvalidOperation = ("Database 'UnknownDatabase' does not exist " + ` - "on SQL server 'localhost\MSSQLSERVER'.") + $errorMessage = $script:localizedData.DatabaseNotFound -f $testParameters.Name - { Set-TargetResource @testParameters } | Should -Throw $throwInvalidOperation + { Set-TargetResource @testParameters } | Should -Throw $errorMessage } It 'Should call the mock function Connect-SQL' {