|
88 | 88 | $result.path | Should Be "/$($DSCConfig.AllNodes.WebVirtualDirectory)" |
89 | 89 | $result.physicalPath | Should Be $DSCConfig.AllNodes.PhysicalPath |
90 | 90 | } |
| 91 | + |
| 92 | + It 'Should create a WebVirtualDirectory with WebApplication = ''/''' -Test { |
| 93 | + |
| 94 | + configuration DSC_WebVirtualDirectory_WebApplicationSlash |
| 95 | + { |
| 96 | + Import-DscResource -ModuleName WebAdministrationDsc |
| 97 | + |
| 98 | + Node $AllNodes.NodeName |
| 99 | + { |
| 100 | + WebVirtualDirectory WebVirtualDirectory |
| 101 | + { |
| 102 | + Ensure = 'Present' |
| 103 | + Website = $Node.Website |
| 104 | + WebApplication = '/' |
| 105 | + Name = $Node.WebVirtualDirectory |
| 106 | + PhysicalPath = $Node.PhysicalPath |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + & "DSC_WebVirtualDirectory_WebApplicationSlash" ` |
| 112 | + -OutputPath $TestDrive ` |
| 113 | + -ConfigurationData $dscConfig |
| 114 | + |
| 115 | + Reset-DscLcm |
| 116 | + |
| 117 | + Start-DscConfiguration ` |
| 118 | + -Path $TestDrive ` |
| 119 | + -ComputerName localhost ` |
| 120 | + -Wait ` |
| 121 | + -Verbose ` |
| 122 | + -Force ` |
| 123 | + -ErrorAction Stop |
| 124 | + |
| 125 | + # Build results to test |
| 126 | + $result = Get-WebVirtualDirectory -Site $DSCConfig.AllNodes.Website ` |
| 127 | + -Application '/' ` |
| 128 | + -Name $DSCConfig.AllNodes.WebVirtualDirectory |
| 129 | + |
| 130 | + # Test virtual directory settings are correct |
| 131 | + $result | Should Not BeNullOrEmpty |
| 132 | + } |
91 | 133 | } |
92 | 134 |
|
93 | 135 | Describe "$($script:dscResourceName)_Absent" { |
@@ -142,6 +184,106 @@ try |
142 | 184 | # Test virtual directory is removed |
143 | 185 | $result | Should BeNullOrEmpty |
144 | 186 | } |
| 187 | + |
| 188 | + It 'Should remove a WebVirtualDirectory with WebApplication = ''''' -Test { |
| 189 | + |
| 190 | + <# |
| 191 | + Use different name since test data does not get cleaned up. |
| 192 | + Use of Name = $Node.WebVirtualDirectory may throw |
| 193 | + "Destination element already exists, please use "force" parameter to override" |
| 194 | + if test 'Should create a WebVirtualDirectory with WebApplication = "/"' have failed. |
| 195 | + If that test succeeded this tests setup step would find the resource already existing (and succeed). |
| 196 | + #> |
| 197 | + $virtualDirectoryName = "$($Node.WebVirtualDirectory)2" |
| 198 | + |
| 199 | + # Declare local configurations |
| 200 | + configuration DSC_WebVirtualDirectory_WebApplicationBlank_add |
| 201 | + { |
| 202 | + Import-DscResource -ModuleName WebAdministrationDsc |
| 203 | + |
| 204 | + Node $AllNodes.NodeName |
| 205 | + { |
| 206 | + WebVirtualDirectory WebVirtualDirectory |
| 207 | + { |
| 208 | + Ensure = 'Present' |
| 209 | + Website = $Node.Website |
| 210 | + WebApplication = '' |
| 211 | + Name = $virtualDirectoryName |
| 212 | + PhysicalPath = $Node.PhysicalPath |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + |
| 217 | + configuration DSC_WebVirtualDirectory_WebApplicationBlank_remove |
| 218 | + { |
| 219 | + Import-DscResource -ModuleName WebAdministrationDsc |
| 220 | + |
| 221 | + Node $AllNodes.NodeName |
| 222 | + { |
| 223 | + WebVirtualDirectory WebVirtualDirectory |
| 224 | + { |
| 225 | + Ensure = 'Absent' |
| 226 | + Website = $Node.Website |
| 227 | + WebApplication = '' |
| 228 | + Name = $virtualDirectoryName |
| 229 | + PhysicalPath = $Node.PhysicalPath |
| 230 | + } |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + # local helper |
| 235 | + function Get-WebApplicationBlankVirtualDirectory() |
| 236 | + { |
| 237 | + return Get-WebVirtualDirectory -Site $DSCConfig.AllNodes.Website ` |
| 238 | + -Application '' ` |
| 239 | + -Name $virtualDirectoryName |
| 240 | + } |
| 241 | + |
| 242 | + # Execute setup |
| 243 | + & "DSC_WebVirtualDirectory_WebApplicationBlank_add" ` |
| 244 | + -OutputPath $TestDrive ` |
| 245 | + -ConfigurationData $dscConfig |
| 246 | + |
| 247 | + Reset-DscLcm |
| 248 | + |
| 249 | + Start-DscConfiguration ` |
| 250 | + -Path $TestDrive ` |
| 251 | + -ComputerName localhost ` |
| 252 | + -Wait ` |
| 253 | + -Verbose ` |
| 254 | + -Force ` |
| 255 | + -ErrorAction Stop |
| 256 | + |
| 257 | + # Verify intermediate result |
| 258 | + $resultIntermediate = Get-WebApplicationBlankVirtualDirectory |
| 259 | + |
| 260 | + # Virtual directory have been created |
| 261 | + $resultIntermediate | Should Not BeNullOrEmpty |
| 262 | + |
| 263 | + # Execute Test operation |
| 264 | + & "DSC_WebVirtualDirectory_WebApplicationBlank_remove" ` |
| 265 | + -OutputPath $TestDrive ` |
| 266 | + -ConfigurationData $dscConfig |
| 267 | + |
| 268 | + <# |
| 269 | + Issue #366 |
| 270 | + Before change this statement throws exception |
| 271 | + "PowerShell Desired State Configuration does not support execution of commands in an interactive mode ..." |
| 272 | + #> |
| 273 | + Start-DscConfiguration ` |
| 274 | + -Path $TestDrive ` |
| 275 | + -ComputerName localhost ` |
| 276 | + -Wait ` |
| 277 | + -Verbose ` |
| 278 | + -Force ` |
| 279 | + -ErrorAction Stop |
| 280 | + |
| 281 | + # Build results to test |
| 282 | + $result = Get-WebApplicationBlankVirtualDirectory |
| 283 | + |
| 284 | + # Test virtual directory is removed |
| 285 | + $result | Should BeNullOrEmpty |
| 286 | + } |
145 | 287 | } |
146 | 288 |
|
147 | 289 | } |
|
0 commit comments