Skip to content

Commit

Permalink
Add -IncludeAppSetting switch to all relevant cmdlets
Browse files Browse the repository at this point in the history
  • Loading branch information
muratiakos committed Jul 15, 2016
1 parent 891e483 commit 36585ac
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@
## 1.5.2 (Feb 28, 2016)
- Refactor Pester tests and Fixtures
- Reorganize functions into subfolders

## 1.6.0 (Jul 15, 2016)
- Enable remote executions with resolving RunspaceIds without specifying -Session parameter
- Add password-masking to Test-PSConnectionString
- Test-PsWebConfig now support -IncludeAppsettings parameters
- Better detailed -Verbose info from all cmdlets
28 changes: 19 additions & 9 deletions Functions/PSUri/Get-PSUri.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
.PARAMETER ConfigXml
Mandatory - Pipeline input for Configuration XML
.PARAMETER IncludeAppSettings
Optional - Switch to include http/s URIs from appsettings
.EXAMPLE
Get-PSWebConfig -Path 'C:\inetpub\wwwroot\myapp' | Get-PSUri
Expand All @@ -19,19 +21,27 @@ function Get-PSUri {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true,ValueFromPipeLine=$true)]
[psobject[]]$ConfigXml
[psobject[]]$ConfigXml,
[switch]$IncludeAppSettings
)

process {
# Return all service endpoint addresses
Write-Verbose "Executing Get-PSUri"

Write-Verbose "Looking for service-endpoint addresses..."
Get-PSEndpoint -ConfigXml $configXml

# Return any URL from appSettings as an Address
Get-PSAppSetting -ConfigXml $configXml |
Where-Object value -imatch '^http[s]*:' |
Add-Member -MemberType AliasProperty -Name name -Value key -Force -PassThru |
Add-Member -MemberType AliasProperty -Name address -Value value -Force -PassThru |
Add-Member -MemberType AliasProperty -Name Uri -Value value -Force -PassThru |
Set_Type -TypeName 'PSWebConfig.Uri'
if (-Not $IncludeAppSettings) {
Write-Verbose "Appsettings are not included in URI processing."
return
} else {
Write-Verbose "Looking for any http URLs from appSettings..."
Get-PSAppSetting -ConfigXml $configXml |
Where-Object value -imatch '^http[s]*:' |
Add-Member -MemberType AliasProperty -Name name -Value key -Force -PassThru |
Add-Member -MemberType AliasProperty -Name address -Value value -Force -PassThru |
Add-Member -MemberType AliasProperty -Name Uri -Value value -Force -PassThru |
Set_Type -TypeName 'PSWebConfig.Uri'
}
}
}
23 changes: 17 additions & 6 deletions Functions/PSWebConfig/Test-PSWebConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
Tests all URI and ConnectionStrings from web or application configuration.
.DESCRIPTION
The cmdlet fetches all ConnectionString and URIs for a configuration file
and executes a test against them on a local or remote machine.
The cmdlet fetches all ConnectionString and service endpoint URIs
from a configuration xml and executes a test against them on a
local or remote machine.
If -IncludeAppSettings switch is defined, it will include any URI or
ConnectionStrings to the tests.
.PARAMETER InputObject
Mandatory - Parameter to pass a PSWebConfig object
.PARAMETER Session
Optional - PSSession to execute configuration test
.PARAMETER IncludeAppSettings
Optional - Switch to include URIs and ConnectionStrings from appSettings
sections
.EXAMPLE
Get-PSWebConfig -Path 'c:\intepub\wwwroot\testapp\' | Test-PSWebConfig
Expand All @@ -25,13 +33,16 @@ function Test-PSWebConfig {
[Parameter(ValueFromPipeLine=$true)]
[psobject[]]$ConfigXml,

[switch]$IncludeAppSettings,
[System.Management.Automation.Runspaces.PSSession]$Session
)
process {
Get-PSEndpoint -ConfigXml $ConfigXml |
Test-PSUri -Session $Session
Write-Verbose "Executing Test-PSWebConfig"

Get-PSUri -ConfigXml $ConfigXml -IncludeAppSettings:$IncludeAppSettings |
Test-PSUri -Session $Session

Get-PSConnectionString -ConfigXml $ConfigXml |
Test-PSConnectionString -Session $Session
Get-PSConnectionString -ConfigXml $ConfigXml -IncludeAppSettings:$IncludeAppSettings |
Test-PSConnectionString -Session $Session
}
}
18 changes: 16 additions & 2 deletions Tests/PSUri/Get-PSUri.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ $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
$addresses = $config | Get-PSUri -Verbose:$isVerbose -IncludeAppsettings
$endpoints = (Get-PSEndpoint -ConfigXml $config -Verbose:$isVerbose)

It 'should return all addresses' {
It 'should return all addresses with -IncludeAppsettings' {
$addresses | Should Not BeNullOrEmpty
$addresses.Count | Should Be (2+2) # appSetting + endpoints
$addresses | Foreach-Object {
Expand All @@ -20,5 +21,18 @@ Describe 'Get-PSUri' {
$_.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
}
}
}

0 comments on commit 36585ac

Please sign in to comment.