-
Notifications
You must be signed in to change notification settings - Fork 147
/
MSFT_xWebAppPoolDefaults.Integration.Tests.ps1
115 lines (86 loc) · 3.63 KB
/
MSFT_xWebAppPoolDefaults.Integration.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#requires -Version 4.0
$script:DSCModuleName = 'xWebAdministration'
$script:DSCResourceName = 'MSFT_xWebAppPoolDefaults'
#region HEADER
# Integration Test Template Version: 1.1.0
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
}
Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
$TestEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceName `
-TestType Integration
#endregion
# Test Setup
if ((Get-Service -Name 'W3SVC').Status -ne 'Running')
{
Start-Service -Name 'W3SVC'
}
$tempBackupName = "$($script:DSCResourceName)_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
# Using try/finally to always cleanup even if something awful happens.
try
{
# Create configuration backup
Backup-WebConfiguration -Name $tempBackupName | Out-Null
#region Integration Tests
$ConfigFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:DSCResourceName).config.ps1"
. $ConfigFile
Describe "$($script:DSCResourceName)_Integration" {
#region Default Tests
It 'Should be able to compile and apply without throwing' {
{
Invoke-Expression -Command (
'{0}_Config -OutputPath $TestDrive -ConfigurationData $ConfigData -ErrorAction Stop' -f
$script:DSCResourceName
)
Start-DscConfiguration -Path $TestDrive -ComputerName localhost -Force -Wait -Verbose
} | Should Not Throw
}
It 'Should be able to call Get-DscConfiguration without throwing' {
{
Get-DscConfiguration -Verbose -ErrorAction Stop
} | Should Not Throw
}
#endregion
It 'Should have set the resource and all the parameters should match' {
$currentConfiguration = Get-DscConfiguration
foreach ($parameter in $TestParameters.GetEnumerator())
{
Write-Verbose -Message "The $($parameter.Name) property should be set."
if ($parameter.Name -eq 'Credential')
{
$appPoolDefaults = Get-WebConfiguration -Filter '/system.applicationHost/applicationPools/applicationPoolDefaults'
$appPoolDefaults.processModel.userName |
Should Be $TestParameters['Credential'].UserName
$appPoolDefaults.processModel.password |
Should Be $TestParameters['Credential'].GetNetworkCredential().Password
}
elseif ($parameter.Name -eq 'ApplyTo')
{
# ignored.
}
else
{
$currentConfiguration."$($parameter.Name)" |
Should Be $TestParameters[$parameter.Name]
}
}
}
It 'Actual configuration should match the desired configuration' {
Test-DscConfiguration -Verbose | Should Be $true
}
}
#endregion
}
finally
{
#region FOOTER
Restore-WebConfiguration -Name $tempBackupName
Remove-WebConfigurationBackup -Name $tempBackupName
Restore-TestEnvironment -TestEnvironment $TestEnvironment
#endregion
}