@@ -97,6 +97,7 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' {
9797
9898 Context ' When Get-TargetResource returns script results successfully' {
9999 BeforeAll {
100+ Mock - CommandName Test-Path - MockWith { return $true }
100101 Mock - CommandName Invoke-SqlScript - MockWith {
101102 return ' '
102103 }
@@ -120,6 +121,7 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' {
120121
121122 Context ' When Get-TargetResource returns script results successfully with query timeout' {
122123 BeforeAll {
124+ Mock - CommandName Test-Path - MockWith { return $true }
123125 Mock - CommandName Invoke-SqlScript - MockWith {
124126 return ' '
125127 }
@@ -145,6 +147,7 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' {
145147
146148 Context ' When Get-TargetResource throws an error when running the script in the GetFilePath parameter' {
147149 BeforeAll {
150+ Mock - CommandName Test-Path - MockWith { return $true }
148151 Mock - CommandName Invoke-SqlScript - MockWith {
149152 throw ' Failed to run SQL Script'
150153 }
@@ -160,6 +163,22 @@ Describe 'SqlScript\Get-TargetResource' -Tag 'Get' {
160163 }
161164 }
162165 }
166+
167+ Context ' When the GetFilePath file is missing' {
168+ BeforeAll {
169+ Mock - CommandName Test-Path - MockWith { return $false }
170+ }
171+
172+ It ' Should throw the localized file not found exception' {
173+ InModuleScope - ScriptBlock {
174+ Set-StrictMode - Version 1.0
175+
176+ $expectedError = $script :localizedData.GetScript_FileNotFound -f $script :mockGetTargetResourceParameters.GetFilePath
177+
178+ { Get-TargetResource @mockGetTargetResourceParameters } | Should - Throw - ExpectedMessage $expectedError
179+ }
180+ }
181+ }
163182}
164183
165184Describe ' SqlScript\Set-TargetResource' - Tag ' Set' {
@@ -186,6 +205,7 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' {
186205
187206 Context ' When Set-TargetResource runs script without issue' {
188207 BeforeAll {
208+ Mock - CommandName Test-Path - MockWith { return $true }
189209 Mock - CommandName Invoke-SqlScript - MockWith {
190210 return ' '
191211 }
@@ -202,6 +222,7 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' {
202222
203223 Context ' When Set-TargetResource runs script without issue using timeout' {
204224 BeforeAll {
225+ Mock - CommandName Test-Path - MockWith { return $true }
205226 Mock - CommandName Invoke-SqlScript - MockWith {
206227 return ' '
207228 }
@@ -220,6 +241,7 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' {
220241
221242 Context ' When Set-TargetResource throws an error when running the script in the SetFilePath parameter' {
222243 BeforeAll {
244+ Mock - CommandName Test-Path - MockWith { return $true }
223245 Mock - CommandName Invoke-SqlScript - MockWith {
224246 throw ' Failed to run SQL Script'
225247 }
@@ -236,6 +258,22 @@ Describe 'SqlScript\Set-TargetResource' -Tag 'Set' {
236258 }
237259 }
238260 }
261+
262+ Context ' When the SetFilePath file is missing' {
263+ BeforeAll {
264+ Mock - CommandName Test-Path - MockWith { return $false }
265+ }
266+
267+ It ' Should throw the localized file not found exception' {
268+ InModuleScope - ScriptBlock {
269+ Set-StrictMode - Version 1.0
270+
271+ $expectedError = $script :localizedData.SetScript_FileNotFound -f $script :mockSetTargetResourceParameters.SetFilePath
272+
273+ { Set-TargetResource @mockSetTargetResourceParameters } | Should - Throw - ExpectedMessage $expectedError
274+ }
275+ }
276+ }
239277}
240278
241279Describe ' SqlScript\Test-TargetResource' {
@@ -263,6 +301,7 @@ Describe 'SqlScript\Test-TargetResource' {
263301 Context ' When the system is in the desired state' {
264302 Context ' When Test-TargetResource runs script without issue' {
265303 BeforeAll {
304+ Mock - CommandName Test-Path - MockWith { return $true }
266305 Mock - CommandName Invoke-SqlScript
267306 }
268307
@@ -279,6 +318,7 @@ Describe 'SqlScript\Test-TargetResource' {
279318
280319 Context ' When Test-TargetResource runs script without issue with timeout' {
281320 BeforeAll {
321+ Mock - CommandName Test-Path - MockWith { return $true }
282322 Mock - CommandName Invoke-SqlScript
283323 }
284324
@@ -299,6 +339,7 @@ Describe 'SqlScript\Test-TargetResource' {
299339 Context ' When the system is not in the desired state' {
300340 Context ' When Invoke-SqlScript returns an SQL error code from the script that was ran' {
301341 BeforeAll {
342+ Mock - CommandName Test-Path - MockWith { return $true }
302343 Mock - CommandName Invoke-SqlScript - MockWith {
303344 return 1
304345 }
@@ -319,6 +360,7 @@ Describe 'SqlScript\Test-TargetResource' {
319360
320361 Context ' When Test-TargetResource throws the exception SqlPowerShellSqlExecutionException when running the script in the TestFilePath parameter' {
321362 BeforeAll {
363+ Mock - CommandName Test-Path - MockWith { return $true }
322364 Mock - CommandName Invoke-SqlScript - MockWith {
323365 throw New-Object - TypeName Microsoft.SqlServer.Management.PowerShell.SqlPowerShellSqlExecutionException
324366 }
@@ -337,6 +379,7 @@ Describe 'SqlScript\Test-TargetResource' {
337379
338380 Context ' When Test-TargetResource throws an unexpected error when running the script in the TestFilePath parameter' {
339381 BeforeAll {
382+ Mock - CommandName Test-Path - MockWith { return $true }
340383 Mock - CommandName Invoke-SqlScript - MockWith {
341384 throw ' Failed to run SQL Script'
342385 }
@@ -353,4 +396,20 @@ Describe 'SqlScript\Test-TargetResource' {
353396 }
354397 }
355398 }
399+
400+ Context ' When the TestFilePath file is missing' {
401+ BeforeAll {
402+ Mock - CommandName Test-Path - MockWith { return $false }
403+ }
404+
405+ It ' Should return false' {
406+ InModuleScope - ScriptBlock {
407+ Set-StrictMode - Version 1.0
408+
409+ $result = Test-TargetResource @mockTestTargetResourceParameters
410+
411+ $result | Should - BeFalse
412+ }
413+ }
414+ }
356415}
0 commit comments