Skip to content

Commit

Permalink
SqlDatabaseRecoveryModel: Added localization (#1340)
Browse files Browse the repository at this point in the history
- Changes to SqlDatabaseRecoveryModel
  - Added en-US localization (issue #609).
  • Loading branch information
johlju authored Apr 27, 2019
1 parent e2a37be commit 5faea8c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
'@
10 changes: 4 additions & 6 deletions Tests/Unit/MSFT_SqlDatabaseRecoveryModel.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down Expand Up @@ -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' {
Expand Down

0 comments on commit 5faea8c

Please sign in to comment.