Tests/PSUri/Get-PSUri.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
. (Join-Path $PSScriptRoot '../Import-LocalModule.ps1')

$isVerbose=($VerbosePreference -eq 'Continue')

$webConfigFile = Join-Path $script:FixturePath 'web.config'

Describe 'Get-PSUri' {
    Context 'Local web.config' {
        $config = Get-PSWebConfig -Path $webConfigFile -Verbose:$isVerbose
        $addresses = $config | Get-PSUri -Verbose:$isVerbose -IncludeAppsettings
        $endpoints = (Get-PSEndpoint -ConfigXml $config -Verbose:$isVerbose)

        It 'should return all addresses with -IncludeAppsettings' {
            $addresses | Should Not BeNullOrEmpty
            $addresses.Count | Should Be (2+2) # appSetting + endpoints
            $addresses | Foreach-Object {
                $_.psobject.TypeNames -contains 'PSWebConfig.Uri' | Should Be $true
                $_.SectionPath | Should Match '^system.serviceModel/client/endpoint$|^appSettings$'
                $_.name | Should Not BeNullOrEmpty
                $_.address | Should Not BeNullOrEmpty
                $_.Uri | Should Match '^http[s]*:'
            }
        }

        It 'should contain all service endpoints' {
            $addresses | Should Not BeNullOrEmpty
            foreach ($e in $endpoints) {
                $addresses -contains $e | Should Be $true
            }
        }

        It 'should be the same as Get-PSEndpoint without -IncludeAppsettings' {
            $addressesWithouAppSettings = $config | Get-PSUri -Verbose:$isVerbose
            $addressesWithouAppSettings | Should Not BeNullOrEmpty
            $addressesWithouAppSettings | Should Be $endpoints
        }
    }
}