@@ -66,14 +66,19 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
6666 $mockDatabaseObject | Add-Member - MemberType ' ScriptProperty' - Name ' Parent' - Value {
6767 $mockParent = New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.Server'
6868 $mockParent | Add-Member - MemberType ' NoteProperty' - Name ' InstanceName' - Value ' TestInstance' - Force
69+
6970 return $mockParent
7071 } - Force
72+
7173 $script :setSnapshotIsolationCalled = $false
7274 $script :setSnapshotIsolationValue = $null
75+
7376 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' SetSnapshotIsolation' - Value {
7477 param ($Enable )
78+
7579 $script :setSnapshotIsolationCalled = $true
7680 $script :setSnapshotIsolationValue = $Enable
81+
7782 if ($Enable )
7883 {
7984 $this.SnapshotIsolationState = ' Enabled'
@@ -83,6 +88,7 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
8388 $this.SnapshotIsolationState = ' Disabled'
8489 }
8590 } - Force
91+
8692 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' Refresh' - Value {
8793 # Mock implementation - in real SMO this updates properties from server
8894 } - Force
@@ -101,7 +107,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
101107 It ' Should enable snapshot isolation successfully' {
102108 $script :setSnapshotIsolationCalled = $false
103109 $script :setSnapshotIsolationValue = $null
110+
104111 $null = Enable-SqlDscDatabaseSnapshotIsolation - ServerObject $mockServerObject - Name ' TestDatabase' - Force
112+
105113 $mockDatabaseObject.SnapshotIsolationState | Should - Be ' Enabled'
106114 $script :setSnapshotIsolationCalled | Should - BeTrue - Because ' SetSnapshotIsolation should be called to enable snapshot isolation'
107115 $script :setSnapshotIsolationValue | Should - BeTrue - Because ' SetSnapshotIsolation should be called with $true'
@@ -111,7 +119,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
111119 # Reset state to ensure the test starts with snapshot isolation disabled
112120 $mockDatabaseObject.SnapshotIsolationState = ' Disabled'
113121 $script :setSnapshotIsolationCalled = $false
122+
114123 $result = Enable-SqlDscDatabaseSnapshotIsolation - ServerObject $mockServerObject - Name ' TestDatabase' - Force - PassThru
124+
115125 $result | Should -Not - BeNullOrEmpty
116126 $result.Name | Should - Be ' TestDatabase'
117127 }
@@ -120,7 +130,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
120130 # Reset state for this test
121131 $mockDatabaseObject.SnapshotIsolationState = ' Disabled'
122132 $script :setSnapshotIsolationCalled = $false
133+
123134 $null = Enable-SqlDscDatabaseSnapshotIsolation - ServerObject $mockServerObject - Name ' TestDatabase' - Force - Refresh
135+
124136 $mockDatabaseObject.SnapshotIsolationState | Should - Be ' Enabled'
125137 }
126138
@@ -129,7 +141,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
129141 $mockDatabaseObject.SnapshotIsolationState = ' Disabled'
130142 $script :setSnapshotIsolationCalled = $false
131143 $script :setSnapshotIsolationValue = $null
144+
132145 $null = Enable-SqlDscDatabaseSnapshotIsolation - ServerObject $mockServerObject - Name ' TestDatabase' - Force
146+
133147 $mockDatabaseObject.SnapshotIsolationState | Should - Be ' Enabled'
134148 $script :setSnapshotIsolationCalled | Should - BeTrue - Because ' SetSnapshotIsolation should be called'
135149 $script :setSnapshotIsolationValue | Should - BeTrue - Because ' SetSnapshotIsolation should be called with $true'
@@ -144,14 +158,19 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
144158 $mockDatabaseObject | Add-Member - MemberType ' ScriptProperty' - Name ' Parent' - Value {
145159 $mockParent = New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.Server'
146160 $mockParent | Add-Member - MemberType ' NoteProperty' - Name ' InstanceName' - Value ' TestInstance' - Force
161+
147162 return $mockParent
148163 } - Force
164+
149165 $script :setSnapshotIsolationCalled = $false
150166 $script :setSnapshotIsolationValue = $null
167+
151168 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' SetSnapshotIsolation' - Value {
152169 param ($Enable )
170+
153171 $script :setSnapshotIsolationCalled = $true
154172 $script :setSnapshotIsolationValue = $Enable
173+
155174 if ($Enable )
156175 {
157176 $this.SnapshotIsolationState = ' Enabled'
@@ -161,6 +180,7 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
161180 $this.SnapshotIsolationState = ' Disabled'
162181 }
163182 } - Force
183+
164184 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' Refresh' - Value {
165185 # Mock implementation - in real SMO this updates properties from server
166186 } - Force
@@ -169,7 +189,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
169189 It ' Should enable snapshot isolation successfully' {
170190 $script :setSnapshotIsolationCalled = $false
171191 $script :setSnapshotIsolationValue = $null
192+
172193 $null = Enable-SqlDscDatabaseSnapshotIsolation - DatabaseObject $mockDatabaseObject - Force
194+
173195 $mockDatabaseObject.SnapshotIsolationState | Should - Be ' Enabled'
174196 $script :setSnapshotIsolationCalled | Should - BeTrue - Because ' SetSnapshotIsolation should be called'
175197 $script :setSnapshotIsolationValue | Should - BeTrue - Because ' SetSnapshotIsolation should be called with $true'
@@ -179,7 +201,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
179201 # Reset state to ensure the test starts with snapshot isolation disabled
180202 $mockDatabaseObject.SnapshotIsolationState = ' Disabled'
181203 $script :setSnapshotIsolationCalled = $false
204+
182205 $result = Enable-SqlDscDatabaseSnapshotIsolation - DatabaseObject $mockDatabaseObject - Force - PassThru
206+
183207 $result | Should -Not - BeNullOrEmpty
184208 $result.Name | Should - Be ' TestDatabase'
185209 }
@@ -188,7 +212,9 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
188212 $mockDatabaseObject.SnapshotIsolationState = ' Disabled'
189213 $script :setSnapshotIsolationCalled = $false
190214 $script :setSnapshotIsolationValue = $null
215+
191216 $null = Enable-SqlDscDatabaseSnapshotIsolation - DatabaseObject $mockDatabaseObject - Force
217+
192218 $mockDatabaseObject.SnapshotIsolationState | Should - Be ' Enabled'
193219 $script :setSnapshotIsolationCalled | Should - BeTrue - Because ' SetSnapshotIsolation should be called'
194220 $script :setSnapshotIsolationValue | Should - BeTrue - Because ' SetSnapshotIsolation should be called with $true'
@@ -203,13 +229,18 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
203229 $mockDatabaseObject | Add-Member - MemberType ' ScriptProperty' - Name ' Parent' - Value {
204230 $mockParent = New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.Server'
205231 $mockParent | Add-Member - MemberType ' NoteProperty' - Name ' InstanceName' - Value ' TestInstance' - Force
232+
206233 return $mockParent
207234 } - Force
235+
208236 # Track whether SetSnapshotIsolation was called using script-scoped variables
209237 $script :setSnapshotIsolationCalled = $false
238+
210239 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' SetSnapshotIsolation' - Value {
211240 param ($Enable )
241+
212242 $script :setSnapshotIsolationCalled = $true
243+
213244 if ($Enable )
214245 {
215246 $this.SnapshotIsolationState = ' Enabled'
@@ -219,6 +250,7 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
219250 $this.SnapshotIsolationState = ' Disabled'
220251 }
221252 } - Force
253+
222254 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' Refresh' - Value {
223255 # Mock implementation - in real SMO this updates properties from server
224256 } - Force
@@ -228,10 +260,8 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
228260 # Reset the flags before the test
229261 $script :setSnapshotIsolationCalled = $false
230262
231- # The command should skip calling SetSnapshotIsolation when already enabled
232263 $null = Enable-SqlDscDatabaseSnapshotIsolation - DatabaseObject $mockDatabaseObject - Force
233264
234- # Verify SetSnapshotIsolation was not called (idempotent behavior)
235265 $script :setSnapshotIsolationCalled | Should - BeFalse - Because ' SetSnapshotIsolation should not be called when snapshot isolation is already enabled'
236266 $mockDatabaseObject.SnapshotIsolationState | Should - Be ' Enabled'
237267 }
@@ -245,12 +275,16 @@ Describe 'Enable-SqlDscDatabaseSnapshotIsolation' -Tag 'Public' {
245275 $mockDatabaseObject | Add-Member - MemberType ' ScriptProperty' - Name ' Parent' - Value {
246276 $mockParent = New-Object - TypeName ' Microsoft.SqlServer.Management.Smo.Server'
247277 $mockParent | Add-Member - MemberType ' NoteProperty' - Name ' InstanceName' - Value ' TestInstance' - Force
278+
248279 return $mockParent
249280 } - Force
281+
250282 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' SetSnapshotIsolation' - Value {
251283 param ($Enable )
284+
252285 throw ' Simulated SetSnapshotIsolation() failure'
253286 } - Force
287+
254288 $mockDatabaseObject | Add-Member - MemberType ' ScriptMethod' - Name ' Refresh' - Value {
255289 # Mock implementation - in real SMO this updates properties from server
256290 } - Force
0 commit comments