|
1 | 1 | [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")] |
2 | 2 | param () |
3 | 3 |
|
4 | | -$script:DSCModuleName = 'FileContentDsc' |
5 | | -$script:DSCResourceName = 'DSC_KeyValuePairFile' |
| 4 | +$script:dscModuleName = 'FileContentDsc' |
| 5 | +$script:dscResourceName = 'DSC_KeyValuePairFile' |
6 | 6 |
|
7 | | -Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global |
| 7 | +function Invoke-TestSetup |
| 8 | +{ |
| 9 | + try |
| 10 | + { |
| 11 | + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' |
| 12 | + } |
| 13 | + catch [System.IO.FileNotFoundException] |
| 14 | + { |
| 15 | + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' |
| 16 | + } |
| 17 | + |
| 18 | + $script:testEnvironment = Initialize-TestEnvironment ` |
| 19 | + -DSCModuleName $script:dscModuleName ` |
| 20 | + -DSCResourceName $script:dscResourceName ` |
| 21 | + -ResourceType 'Mof' ` |
| 22 | + -TestType 'Unit' |
| 23 | + |
| 24 | + Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') |
| 25 | +} |
8 | 26 |
|
9 | | -#region HEADER |
10 | | -# Unit Test Template Version: 1.1.0 |
11 | | -[System.String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) |
12 | | -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` |
13 | | - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) |
| 27 | +function Invoke-TestCleanup |
14 | 28 | { |
15 | | - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) |
| 29 | + Restore-TestEnvironment -TestEnvironment $script:testEnvironment |
16 | 30 | } |
17 | 31 |
|
18 | | -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force |
19 | | -$TestEnvironment = Initialize-TestEnvironment ` |
20 | | - -DSCModuleName $script:DSCModuleName ` |
21 | | - -DSCResourceName $script:DSCResourceName ` |
22 | | - -TestType Unit |
23 | | -#endregion HEADER |
| 32 | +Invoke-TestSetup |
24 | 33 |
|
25 | 34 | # Begin Testing |
26 | 35 | try |
27 | 36 | { |
28 | | - <# |
29 | | - The InModuleScope command allows you to perform white-box unit testing on the internal |
30 | | - (non-exported) code of a Script Module. |
31 | | - #> |
32 | | - InModuleScope 'DSC_KeyValuePairFile' { |
| 37 | + InModuleScope $script:dscResourceName { |
33 | 38 | $script:testTextFile = 'TestFile.txt' |
34 | 39 | $script:testName = 'Setting.Two' |
35 | 40 | $script:testNameNotFound = 'Setting.NotFound' |
@@ -1375,7 +1380,5 @@ $($script:testAddedName)=$($script:testText) |
1375 | 1380 | } |
1376 | 1381 | finally |
1377 | 1382 | { |
1378 | | - #region FOOTER |
1379 | | - Restore-TestEnvironment -TestEnvironment $TestEnvironment |
1380 | | - #endregion |
| 1383 | + Invoke-TestCleanup |
1381 | 1384 | } |
0 commit comments