Skip to content

Commit ffcdee3

Browse files
committed
Update Restore-SqlDscDatabase tests to use Get-SqlDscDatabase for property loading and correct point-in-time restore parameter
1 parent 7dc0265 commit ffcdee3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

tests/Integration/Commands/Restore-SqlDscDatabase.Integration.Tests.ps1

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,17 +610,13 @@ Describe 'Restore-SqlDscDatabase' -Tag @('Integration_SQL2017', 'Integration_SQL
610610
It 'Should restore database in standby mode with read-only access' {
611611
$null = Restore-SqlDscDatabase -ServerObject $script:serverObject -Name $script:standbyDbName -BackupFile $script:fullBackupFile -RelocateFile $script:standbyRelocateFiles -Standby $script:standbyFile -Force -ErrorAction 'Stop'
612612

613-
# Refresh to get current state
614-
$script:serverObject.Databases.Refresh()
615-
$restoredDb = $script:serverObject.Databases[$script:standbyDbName]
613+
# Get the database object using Get-SqlDscDatabase to ensure all properties are properly loaded
614+
$restoredDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:standbyDbName -Refresh -ErrorAction 'Stop'
616615
$restoredDb | Should -Not -BeNullOrEmpty
617616

618-
# Refresh the database object
619-
$restoredDb.Refresh()
620-
621617
# Database should be online and in standby/read-only state
622618
$restoredDb.Status | Should -Be ([Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Normal -bor [Microsoft.SqlServer.Management.Smo.DatabaseStatus]::Standby) -Because 'Database should be online in standby mode'
623-
$restoredDb.IsReadOnly | Should -BeTrue -Because 'Database should be read-only in standby mode'
619+
$restoredDb.ReadOnly | Should -BeTrue -Because 'Database should be read-only in standby mode'
624620

625621
# Verify standby file exists and has content
626622
Test-Path -Path $script:standbyFile | Should -BeTrue -Because 'Standby undo file should exist'
@@ -727,7 +723,7 @@ INSERT INTO dbo.TestData (Id, InsertTime, Value) VALUES (1, GETDATE(), 'Initial'
727723
$null = Restore-SqlDscDatabase -ServerObject $script:serverObject -Name $script:pitDbName -BackupFile $script:pitFullBackupFile -RelocateFile $script:pitRelocateFiles -NoRecovery -Force -ErrorAction 'Stop'
728724

729725
# Restore log backup to the point-in-time
730-
$null = Restore-SqlDscDatabase -ServerObject $script:serverObject -Name $script:pitDbName -BackupFile $script:pitLogBackupFile -RestoreType 'Log' -StopAt $script:pointInTime -Force -ErrorAction 'Stop'
726+
$null = Restore-SqlDscDatabase -ServerObject $script:serverObject -Name $script:pitDbName -BackupFile $script:pitLogBackupFile -RestoreType 'Log' -ToPointInTime $script:pointInTime -Force -ErrorAction 'Stop'
731727

732728
# Refresh and verify the database is online
733729
$script:serverObject.Databases.Refresh()

0 commit comments

Comments
 (0)