@@ -467,7 +467,7 @@ $($script:testAddedName)=$($script:testText)
467467
468468 # region Function Test-TargetResource
469469 Describe ' MSFT_KeyValuePairFile\Test-TargetResource' {
470- Context ' File exists and does not containing matching key but it should' {
470+ Context ' File exists and does not contain matching key but it should' {
471471 # verifiable (should be called) mocks
472472 Mock `
473473 - CommandName Assert-ParametersValid `
@@ -505,6 +505,43 @@ $($script:testAddedName)=$($script:testText)
505505 }
506506 }
507507
508+ Context ' File exists and does not contain matching key but should not' {
509+ # verifiable (should be called) mocks
510+ Mock `
511+ - CommandName Assert-ParametersValid `
512+ - ModuleName ' MSFT_KeyValuePairFile' `
513+ - Verifiable
514+
515+ Mock `
516+ - CommandName Get-Content `
517+ - ParameterFilter { $path -eq $script :testTextFile } `
518+ - MockWith { $script :testFileContent } `
519+ - Verifiable
520+
521+ It ' Should not throw an exception' {
522+ { $script :result = Test-TargetResource `
523+ - Path $script :testTextFile `
524+ - Name $script :testName.ToUpper () `
525+ - Ensure ' Absent' `
526+ - Verbose
527+ } | Should Not Throw
528+ }
529+
530+ It ' Should return true' {
531+ $script :result | Should Be $true
532+ }
533+
534+ It ' Should call the expected mocks' {
535+ Assert-VerifiableMocks
536+ Assert-MockCalled - CommandName Assert-ParametersValid - Exactly 1
537+
538+ Assert-MockCalled `
539+ - CommandName Get-Content `
540+ - ParameterFilter { $path -eq $script :testTextFile } `
541+ - Exactly 1
542+ }
543+ }
544+
508545 Context ' File exists and contains matching key that should exist and values match' {
509546 # verifiable (should be called) mocks
510547 Mock `
@@ -543,6 +580,123 @@ $($script:testAddedName)=$($script:testText)
543580 }
544581 }
545582
583+ Context ' File exists and contains matching key that should exist and values do not match secret text' {
584+ # verifiable (should be called) mocks
585+ Mock `
586+ - CommandName Assert-ParametersValid `
587+ - ModuleName ' MSFT_KeyValuePairFile' `
588+ - Verifiable
589+
590+ Mock `
591+ - CommandName Get-Content `
592+ - ParameterFilter { $path -eq $script :testTextFile } `
593+ - MockWith { $script :testFileContent } `
594+ - Verifiable
595+
596+ It ' Should not throw an exception' {
597+ { $script :result = Test-TargetResource `
598+ - Path $script :testTextFile `
599+ - Name $script :testName `
600+ - Ensure ' Present' `
601+ - Type ' Secret' `
602+ - Secret $script :testSecretCredential `
603+ - Verbose
604+ } | Should Not Throw
605+ }
606+
607+ It ' Should return false' {
608+ $script :result | Should Be $false
609+ }
610+
611+ It ' Should call the expected mocks' {
612+ Assert-VerifiableMocks
613+ Assert-MockCalled - CommandName Assert-ParametersValid - Exactly 1
614+
615+ Assert-MockCalled `
616+ - CommandName Get-Content `
617+ - ParameterFilter { $path -eq $script :testTextFile } `
618+ - Exactly 1
619+ }
620+ }
621+
622+ Context ' File exists and contains matching key that should exist and values match secret text' {
623+ # verifiable (should be called) mocks
624+ Mock `
625+ - CommandName Assert-ParametersValid `
626+ - ModuleName ' MSFT_KeyValuePairFile' `
627+ - Verifiable
628+
629+ Mock `
630+ - CommandName Get-Content `
631+ - ParameterFilter { $path -eq $script :testTextFile } `
632+ - MockWith { $script :testFileExpectedSecretContent } `
633+ - Verifiable
634+
635+ It ' Should not throw an exception' {
636+ { $script :result = Test-TargetResource `
637+ - Path $script :testTextFile `
638+ - Name $script :testName `
639+ - Ensure ' Present' `
640+ - Type ' Secret' `
641+ - Secret $script :testSecretCredential `
642+ - Verbose
643+ } | Should Not Throw
644+ }
645+
646+ It ' Should return true' {
647+ $script :result | Should Be $true
648+ }
649+
650+ It ' Should call the expected mocks' {
651+ Assert-VerifiableMocks
652+ Assert-MockCalled - CommandName Assert-ParametersValid - Exactly 1
653+
654+ Assert-MockCalled `
655+ - CommandName Get-Content `
656+ - ParameterFilter { $path -eq $script :testTextFile } `
657+ - Exactly 1
658+ }
659+ }
660+
661+ Context ' File exists and contains key with different case that should exist and values match and IgnoreNameCase is True' {
662+ # verifiable (should be called) mocks
663+ Mock `
664+ - CommandName Assert-ParametersValid `
665+ - ModuleName ' MSFT_KeyValuePairFile' `
666+ - Verifiable
667+
668+ Mock `
669+ - CommandName Get-Content `
670+ - ParameterFilter { $path -eq $script :testTextFile } `
671+ - MockWith { $script :testFileExpectedTextContent } `
672+ - Verifiable
673+
674+ It ' Should not throw an exception' {
675+ { $script :result = Test-TargetResource `
676+ - Path $script :testTextFile `
677+ - Name $script :testName.ToUpper () `
678+ - Ensure ' Present' `
679+ - Text $script :testText `
680+ - IgnoreNameCase:$true `
681+ - Verbose
682+ } | Should Not Throw
683+ }
684+
685+ It ' Should return true' {
686+ $script :result | Should Be $true
687+ }
688+
689+ It ' Should call the expected mocks' {
690+ Assert-VerifiableMocks
691+ Assert-MockCalled - CommandName Assert-ParametersValid - Exactly 1
692+
693+ Assert-MockCalled `
694+ - CommandName Get-Content `
695+ - ParameterFilter { $path -eq $script :testTextFile } `
696+ - Exactly 1
697+ }
698+ }
699+
546700 Context ' File exists and contains matching key that should exist and values match but are different case and IgnoreValueCase is False' {
547701 # verifiable (should be called) mocks
548702 Mock `
0 commit comments