|
| 1 | +$Global:DSCModuleName = 'xComputerManagement' |
| 2 | +$Global:DSCResourceName = 'MSFT_xScheduledTask' |
| 3 | + |
| 4 | +#region HEADER |
| 5 | +# Unit Test Template Version: 1.1.0 |
| 6 | +[String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) |
| 7 | +if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` |
| 8 | + (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) |
| 9 | +{ |
| 10 | + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) |
| 11 | +} |
| 12 | + |
| 13 | +Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force |
| 14 | +$TestEnvironment = Initialize-TestEnvironment ` |
| 15 | + -DSCModuleName $Global:DSCModuleName ` |
| 16 | + -DSCResourceName $Global:DSCResourceName ` |
| 17 | + -TestType Integration |
| 18 | + |
| 19 | +# Begin Testing |
| 20 | +try |
| 21 | +{ |
| 22 | + #region Pester Tests |
| 23 | + Describe $Global:DSCResourceName { |
| 24 | + |
| 25 | + Context "No scheduled task exists, but it should" { |
| 26 | + CurrentConfig = "xScheduledTask_Add" |
| 27 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 28 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 29 | + |
| 30 | + It "should compile a MOF file without error" { |
| 31 | + { |
| 32 | + . $CurrentConfig -OutputPath $ConfigDir |
| 33 | + } | Should Not Throw |
| 34 | + } |
| 35 | + |
| 36 | + It "should apply the MOF correctly" { |
| 37 | + { |
| 38 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 39 | + } | Should Not Throw |
| 40 | + } |
| 41 | + |
| 42 | + It "should return a compliant state after being applied" { |
| 43 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + Context "A scheduled task with minutes based repetition exists, but has the wrong settings" { |
| 48 | + CurrentConfig = "xScheduledTask_Edit1" |
| 49 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 50 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 51 | + |
| 52 | + It "should compile a MOF file without error" { |
| 53 | + { |
| 54 | + . $CurrentConfig -OutputPath $ConfigDir |
| 55 | + } | Should Not Throw |
| 56 | + } |
| 57 | + |
| 58 | + It "should apply the MOF correctly" { |
| 59 | + { |
| 60 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 61 | + } | Should Not Throw |
| 62 | + } |
| 63 | + |
| 64 | + It "should return a compliant state after being applied" { |
| 65 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + Context "A scheduled task with hourly based repetition exists, but has the wrong settings" { |
| 70 | + CurrentConfig = "xScheduledTask_Edit2" |
| 71 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 72 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 73 | + |
| 74 | + It "should compile a MOF file without error" { |
| 75 | + { |
| 76 | + . $CurrentConfig -OutputPath $ConfigDir |
| 77 | + } | Should Not Throw |
| 78 | + } |
| 79 | + |
| 80 | + It "should apply the MOF correctly" { |
| 81 | + { |
| 82 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 83 | + } | Should Not Throw |
| 84 | + } |
| 85 | + |
| 86 | + It "should return a compliant state after being applied" { |
| 87 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + Context "A scheduled task with daily based repetition exists, but has the wrong settings" { |
| 92 | + CurrentConfig = "xScheduledTask_Edit3" |
| 93 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 94 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 95 | + |
| 96 | + It "should compile a MOF file without error" { |
| 97 | + { |
| 98 | + . $CurrentConfig -OutputPath $ConfigDir |
| 99 | + } | Should Not Throw |
| 100 | + } |
| 101 | + |
| 102 | + It "should apply the MOF correctly" { |
| 103 | + { |
| 104 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 105 | + } | Should Not Throw |
| 106 | + } |
| 107 | + |
| 108 | + It "should return a compliant state after being applied" { |
| 109 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + Context "A scheduled task exists and is configured with the wrong working directory" { |
| 114 | + CurrentConfig = "xScheduledTask_Edit4" |
| 115 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 116 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 117 | + |
| 118 | + It "should compile a MOF file without error" { |
| 119 | + { |
| 120 | + . $CurrentConfig -OutputPath $ConfigDir |
| 121 | + } | Should Not Throw |
| 122 | + } |
| 123 | + |
| 124 | + It "should apply the MOF correctly" { |
| 125 | + { |
| 126 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 127 | + } | Should Not Throw |
| 128 | + } |
| 129 | + |
| 130 | + It "should return a compliant state after being applied" { |
| 131 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + Context "A scheduled task exists and is configured with the wrong executable arguments" { |
| 136 | + CurrentConfig = "xScheduledTask_Edit5" |
| 137 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 138 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 139 | + |
| 140 | + It "should compile a MOF file without error" { |
| 141 | + { |
| 142 | + . $CurrentConfig -OutputPath $ConfigDir |
| 143 | + } | Should Not Throw |
| 144 | + } |
| 145 | + |
| 146 | + It "should apply the MOF correctly" { |
| 147 | + { |
| 148 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 149 | + } | Should Not Throw |
| 150 | + } |
| 151 | + |
| 152 | + It "should return a compliant state after being applied" { |
| 153 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + Context "A scheduled task exists, but it shouldn't" { |
| 158 | + CurrentConfig = "xScheduledTask_Remove" |
| 159 | + $ConfigDir = (Join-Path $TestEnvironment.WorkingFolder $CurrentConfig) |
| 160 | + $ConfigMof = (Join-Path $ConfigDir "localhost.mof") |
| 161 | + |
| 162 | + It "should compile a MOF file without error" { |
| 163 | + { |
| 164 | + . $CurrentConfig -OutputPath $ConfigDir |
| 165 | + } | Should Not Throw |
| 166 | + } |
| 167 | + |
| 168 | + It "should apply the MOF correctly" { |
| 169 | + { |
| 170 | + Start-DscConfiguration -Path $ConfigDir -Wait -Verbose -Force |
| 171 | + } | Should Not Throw |
| 172 | + } |
| 173 | + |
| 174 | + It "should return a compliant state after being applied" { |
| 175 | + (Test-DscConfiguration -ReferenceConfiguration $ConfigMof).InDesiredState | Should be $true |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + #endregion |
| 180 | +} |
| 181 | +finally |
| 182 | +{ |
| 183 | + #region FOOTER |
| 184 | + Restore-TestEnvironment -TestEnvironment $TestEnvironment |
| 185 | + #endregion |
| 186 | +} |
0 commit comments