3636 $script :testSecret = ' TestSecret'
3737 $script :testSearch = " Setting\.Two='(.)*'"
3838 $script :testSearchNoFind = " Setting.NotExist='(.)*'"
39+ $script :testTextReplaceNoFind = " Setting.NotExist='$ ( $script :testText ) '"
3940 $script :testTextReplace = " Setting.Two='$ ( $script :testText ) '"
4041 $script :testSecretReplace = " Setting.Two='$ ( $script :testSecret ) '"
4142 $script :testSecureSecretReplace = ConvertTo-SecureString - String $script :testSecretReplace - AsPlainText - Force
@@ -57,6 +58,16 @@ Setting.Two='$($script:testText)'
5758Setting.Two='$ ( $script :testText ) '
5859Setting3.Test=Value4
5960
61+ "@
62+
63+ $script :testFileExpectedTextContentNewKey = @"
64+ Setting1=Value1
65+ Setting.Two='Value2'
66+ Setting.Two='Value3'
67+ Setting.Two='$ ( $script :testText ) '
68+ Setting3.Test=Value4
69+ Setting.NotExist='$ ( $script :testText ) '
70+
6071"@
6172
6273 $script :testFileExpectedSecretContent = @"
@@ -206,6 +217,55 @@ Setting3.Test=Value4
206217 }
207218 }
208219
220+ Context ' File exists and search text can not be found' {
221+ # verifiable (should be called) mocks
222+ Mock `
223+ - CommandName Assert-ParametersValid `
224+ - ModuleName ' DSR_ReplaceText' `
225+ - Verifiable
226+
227+ Mock `
228+ - CommandName Get-Content `
229+ - ParameterFilter { $path -eq $script :testTextFile } `
230+ - MockWith { $script :testFileContent } `
231+ - Verifiable
232+
233+ Mock `
234+ - CommandName Set-Content `
235+ - ParameterFilter {
236+ ($path -eq $script :testTextFile ) -and `
237+ ($value -eq $script :testFileExpectedTextContentNewKey )
238+ } `
239+ - Verifiable
240+
241+ It ' Should not throw an exception' {
242+ { $script :result = Set-TargetResource `
243+ - Path $script :testTextFile `
244+ - Search $script :testSearchNoFind `
245+ - Text $script :testTextReplaceNoFind `
246+ - Verbose
247+ } | Should -Not - Throw
248+ }
249+
250+ It ' Should call the expected mocks' {
251+ Assert-VerifiableMock
252+ Assert-MockCalled - CommandName Assert-ParametersValid - Exactly 1
253+
254+ Assert-MockCalled `
255+ - CommandName Get-Content `
256+ - ParameterFilter { $path -eq $script :testTextFile } `
257+ - Exactly 1
258+
259+ Assert-MockCalled `
260+ - CommandName Set-Content `
261+ - ParameterFilter {
262+ ($path -eq $script :testTextFile ) -and `
263+ ($value -eq $script :testFileExpectedTextContentNewKey )
264+ } `
265+ - Exactly 1
266+ }
267+ }
268+
209269 Context ' File exists and search secret can be found' {
210270 # verifiable (should be called) mocks
211271 Mock `
0 commit comments