Skip to content

Commit 9b1590a

Browse files
committed
Update output descriptions and enhance tests for snapshot isolation commands
1 parent 9b8fa13 commit 9b1590a

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

source/Public/Disable-SqlDscDatabaseSnapshotIsolation.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@
6262
.OUTPUTS
6363
None.
6464
65-
When PassThru is specified the output is [Microsoft.SqlServer.Management.Smo.Database].
65+
By default, no output is returned.
66+
67+
.OUTPUTS
68+
Microsoft.SqlServer.Management.Smo.Database
69+
70+
When PassThru is specified, the updated database object is returned.
6671
#>
6772
function Disable-SqlDscDatabaseSnapshotIsolation
6873
{
@@ -128,11 +133,11 @@ function Disable-SqlDscDatabaseSnapshotIsolation
128133
}
129134
}
130135

131-
$verboseDescriptionMessage = $script:localizedData.DatabaseSnapshotIsolation_Disable_ShouldProcessVerboseDescription -f $sqlDatabaseObject.Name, $sqlDatabaseObject.Parent.InstanceName
132-
$verboseWarningMessage = $script:localizedData.DatabaseSnapshotIsolation_Disable_ShouldProcessVerboseWarning -f $sqlDatabaseObject.Name
136+
$descriptionMessage = $script:localizedData.DatabaseSnapshotIsolation_Disable_ShouldProcessVerboseDescription -f $sqlDatabaseObject.Name, $sqlDatabaseObject.Parent.InstanceName
137+
$confirmationMessage = $script:localizedData.DatabaseSnapshotIsolation_Disable_ShouldProcessVerboseWarning -f $sqlDatabaseObject.Name
133138
$captionMessage = $script:localizedData.DatabaseSnapshotIsolation_Disable_ShouldProcessCaption
134139

135-
if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
140+
if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
136141
{
137142
# Check if snapshot isolation is already disabled (idempotence)
138143
if ($sqlDatabaseObject.SnapshotIsolationState -eq 'Disabled')

source/Public/Enable-SqlDscDatabaseSnapshotIsolation.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@
6262
.OUTPUTS
6363
None.
6464
65-
When PassThru is specified the output is [Microsoft.SqlServer.Management.Smo.Database].
65+
By default, no output is returned.
66+
67+
.OUTPUTS
68+
Microsoft.SqlServer.Management.Smo.Database
69+
70+
When PassThru is specified, the updated database object is returned.
6671
#>
6772
function Enable-SqlDscDatabaseSnapshotIsolation
6873
{
@@ -128,11 +133,11 @@ function Enable-SqlDscDatabaseSnapshotIsolation
128133
}
129134
}
130135

131-
$verboseDescriptionMessage = $script:localizedData.DatabaseSnapshotIsolation_Enable_ShouldProcessVerboseDescription -f $sqlDatabaseObject.Name, $sqlDatabaseObject.Parent.InstanceName
132-
$verboseWarningMessage = $script:localizedData.DatabaseSnapshotIsolation_Enable_ShouldProcessVerboseWarning -f $sqlDatabaseObject.Name
136+
$descriptionMessage = $script:localizedData.DatabaseSnapshotIsolation_Enable_ShouldProcessVerboseDescription -f $sqlDatabaseObject.Name, $sqlDatabaseObject.Parent.InstanceName
137+
$confirmationMessage = $script:localizedData.DatabaseSnapshotIsolation_Enable_ShouldProcessVerboseWarning -f $sqlDatabaseObject.Name
133138
$captionMessage = $script:localizedData.DatabaseSnapshotIsolation_Enable_ShouldProcessCaption
134139

135-
if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage))
140+
if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
136141
{
137142
# Check if snapshot isolation is already enabled (idempotence)
138143
if ($sqlDatabaseObject.SnapshotIsolationState -eq 'Enabled')

tests/Integration/Commands/Disable-SqlDscDatabaseSnapshotIsolation.Integration.Tests.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,30 @@ Describe 'Disable-SqlDscDatabaseSnapshotIsolation' -Tag @('Integration_SQL2017',
130130
$updatedDb.SnapshotIsolationState | Should -Be 'Disabled'
131131
}
132132
}
133+
134+
Context 'When using the Refresh parameter' {
135+
It 'Should refresh the database collection before disabling snapshot isolation' {
136+
# First ensure it's enabled
137+
$null = Enable-SqlDscDatabaseSnapshotIsolation -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop'
138+
139+
$null = Disable-SqlDscDatabaseSnapshotIsolation -ServerObject $script:serverObject -Name $script:testDatabaseName -Refresh -Force -ErrorAction 'Stop'
140+
141+
# Verify the change
142+
$updatedDb = Get-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Refresh -ErrorAction 'Stop'
143+
$updatedDb.SnapshotIsolationState | Should -Be 'Disabled'
144+
}
145+
}
146+
147+
Context 'When using the PassThru parameter' {
148+
It 'Should return the database object when PassThru is specified' {
149+
# First ensure it's enabled
150+
$null = Enable-SqlDscDatabaseSnapshotIsolation -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop'
151+
152+
$resultDb = Disable-SqlDscDatabaseSnapshotIsolation -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -PassThru -ErrorAction 'Stop'
153+
154+
$resultDb | Should -Not -BeNullOrEmpty
155+
$resultDb.Name | Should -Be $script:testDatabaseName
156+
$resultDb.SnapshotIsolationState | Should -Be 'Disabled'
157+
}
158+
}
133159
}

tests/Unit/Public/Disable-SqlDscDatabaseSnapshotIsolation.Tests.ps1

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Describe 'Disable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
9898
} -Force
9999
}
100100

101-
It 'Should disable snapshot isolation successfully' {
101+
It 'Should call SetSnapshotIsolation with false and change state to Disabled' {
102102
$script:setSnapshotIsolationCalled = $false
103103
$script:setSnapshotIsolationValue = $null
104104
$null = Disable-SqlDscDatabaseSnapshotIsolation -ServerObject $mockServerObject -Name 'TestDatabase' -Force
@@ -123,17 +123,6 @@ Describe 'Disable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
123123
$null = Disable-SqlDscDatabaseSnapshotIsolation -ServerObject $mockServerObject -Name 'TestDatabase' -Force -Refresh
124124
$mockDatabaseObject.SnapshotIsolationState | Should -Be 'Disabled'
125125
}
126-
127-
It 'Should call SetSnapshotIsolation with false' {
128-
# Reset state for this test
129-
$mockDatabaseObject.SnapshotIsolationState = 'Enabled'
130-
$script:setSnapshotIsolationCalled = $false
131-
$script:setSnapshotIsolationValue = $null
132-
$null = Disable-SqlDscDatabaseSnapshotIsolation -ServerObject $mockServerObject -Name 'TestDatabase' -Force
133-
$mockDatabaseObject.SnapshotIsolationState | Should -Be 'Disabled'
134-
$script:setSnapshotIsolationCalled | Should -BeTrue -Because 'SetSnapshotIsolation should be called'
135-
$script:setSnapshotIsolationValue | Should -BeFalse -Because 'SetSnapshotIsolation should be called with $false'
136-
}
137126
}
138127

139128
Context 'When disabling snapshot isolation using DatabaseObject' {
@@ -166,7 +155,7 @@ Describe 'Disable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
166155
} -Force
167156
}
168157

169-
It 'Should disable snapshot isolation successfully' {
158+
It 'Should call SetSnapshotIsolation with false and change state to Disabled' {
170159
$script:setSnapshotIsolationCalled = $false
171160
$script:setSnapshotIsolationValue = $null
172161
$null = Disable-SqlDscDatabaseSnapshotIsolation -DatabaseObject $mockDatabaseObject -Force
@@ -183,16 +172,6 @@ Describe 'Disable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
183172
$result | Should -Not -BeNullOrEmpty
184173
$result.Name | Should -Be 'TestDatabase'
185174
}
186-
187-
It 'Should call SetSnapshotIsolation with false' {
188-
$mockDatabaseObject.SnapshotIsolationState = 'Enabled'
189-
$script:setSnapshotIsolationCalled = $false
190-
$script:setSnapshotIsolationValue = $null
191-
$null = Disable-SqlDscDatabaseSnapshotIsolation -DatabaseObject $mockDatabaseObject -Force
192-
$mockDatabaseObject.SnapshotIsolationState | Should -Be 'Disabled'
193-
$script:setSnapshotIsolationCalled | Should -BeTrue -Because 'SetSnapshotIsolation should be called'
194-
$script:setSnapshotIsolationValue | Should -BeFalse -Because 'SetSnapshotIsolation should be called with $false'
195-
}
196175
}
197176

198177
Context 'When snapshot isolation is already disabled' {

0 commit comments

Comments
 (0)