@@ -189,4 +189,82 @@ Describe "$($script:dscResourceFriendlyName)_Integration" -Tag @('Integration_SQ
189189 $result.actualState.Ensure | Should - Be ' Absent'
190190 }
191191 }
192+
193+ Context ' When testing the model database with a different recovery model' {
194+ It ' Should return false when recovery model is not in desired state' {
195+ $desiredParameters = @ {
196+ InstanceName = $script :instanceName
197+ ServerName = $script :serverName
198+ Name = ' model'
199+ RecoveryModel = ' Simple'
200+ Ensure = ' Present'
201+ Credential = $script :sqlAdminCredential
202+ }
203+
204+ $result = dsc -- trace-level trace resource test -- resource SqlServerDsc/ SqlDatabase -- output- format json -- input ($desiredParameters | ConvertTo-Json - Compress) | ConvertFrom-Json
205+
206+ $dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
207+
208+ if ($dscExitCode -ne 0 )
209+ {
210+ throw (' DSC executable failed with exit code {0}.' -f $dscExitCode )
211+ }
212+
213+ Write-Verbose - Message " Result:`n $ ( $result | ConvertTo-Json - Depth 5 | Out-String ) " - Verbose
214+
215+ $result.inDesiredState | Should - BeFalse
216+ }
217+ }
218+
219+ Context ' When setting the model database recovery model to Simple' {
220+ It ' Should successfully set the recovery model' {
221+ $desiredParameters = @ {
222+ InstanceName = $script :instanceName
223+ ServerName = $script :serverName
224+ Name = ' model'
225+ RecoveryModel = ' Simple'
226+ Ensure = ' Present'
227+ Credential = $script :sqlAdminCredential
228+ }
229+
230+ $result = dsc -- trace-level trace resource set -- resource SqlServerDsc/ SqlDatabase -- output- format json -- input ($desiredParameters | ConvertTo-Json - Compress) | ConvertFrom-Json
231+
232+ $dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
233+
234+ if ($dscExitCode -ne 0 )
235+ {
236+ throw (' DSC executable failed with exit code {0}.' -f $dscExitCode )
237+ }
238+
239+ Write-Verbose - Message " Result:`n $ ( $result | ConvertTo-Json - Depth 5 | Out-String ) " - Verbose
240+
241+ $result.afterState.RecoveryModel | Should - Be ' Simple'
242+ }
243+ }
244+
245+ Context ' When testing the model database after setting recovery model to Simple' {
246+ It ' Should return true when recovery model is in desired state' {
247+ $desiredParameters = @ {
248+ InstanceName = $script :instanceName
249+ ServerName = $script :serverName
250+ Name = ' model'
251+ RecoveryModel = ' Simple'
252+ Ensure = ' Present'
253+ Credential = $script :sqlAdminCredential
254+ }
255+
256+ $result = dsc -- trace-level trace resource test -- resource SqlServerDsc/ SqlDatabase -- output- format json -- input ($desiredParameters | ConvertTo-Json - Compress) | ConvertFrom-Json
257+
258+ $dscExitCode = $LASTEXITCODE # cSpell: ignore LASTEXITCODE
259+
260+ if ($dscExitCode -ne 0 )
261+ {
262+ throw (' DSC executable failed with exit code {0}.' -f $dscExitCode )
263+ }
264+
265+ Write-Verbose - Message " Result:`n $ ( $result | ConvertTo-Json - Depth 5 | Out-String ) " - Verbose
266+
267+ $result.inDesiredState | Should - BeTrue
268+ }
269+ }
192270}
0 commit comments