diff --git a/ConfluencePS/Public/Get-WikiChildPage.ps1 b/ConfluencePS/Public/Get-WikiChildPage.ps1 index ee176ab..fe09d37 100644 --- a/ConfluencePS/Public/Get-WikiChildPage.ps1 +++ b/ConfluencePS/Public/Get-WikiChildPage.ps1 @@ -45,20 +45,13 @@ Position = 0, Mandatory = $true, ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, ParameterSetName = "byID" )] [ValidateRange(1, [int]::MaxValue)] [Alias('ID')] [int]$PageID, - # Find child pages by Page Object - [Parameter( - Mandatory = $true, - ValueFromPipeline = $true, - ParameterSetName = "byObject" - )] - [ConfluencePS.Page]$InputObject, - # Get all child pages recursively [switch]$Recurse, @@ -76,6 +69,12 @@ Write-Debug "ParameterSetName: $($PsCmdlet.ParameterSetName)" Write-Debug "PSBoundParameters: $($PSBoundParameters | Out-String)" + if (($_) -and -not($_ -is [ConfluencePS.Page] -or $_ -is [int])) { + $message = "The Object in the pipe is not a Page." + $exception = New-Object -TypeName System.ArgumentException -ArgumentList $message + Throw $exception + } + if ($PsCmdlet.ParameterSetName -eq "byObject") { $PageID = $InputObject.ID } diff --git a/Tests/ConfluencePS.Integration.Tests.ps1 b/Tests/ConfluencePS.Integration.Tests.ps1 index 21d6c3c..4755424 100644 --- a/Tests/ConfluencePS.Integration.Tests.ps1 +++ b/Tests/ConfluencePS.Integration.Tests.ps1 @@ -649,7 +649,25 @@ InModuleScope ConfluencePS { } } - Describe 'Remove-WikiLabel' { + Describe 'Get-WikiChildPage' { + # ARRANGE + + # ACT + $ChildPages = (Get-WikiSpace -SpaceKey PESTER).Homepage | Get-WikiChildPage + $DesendantPages = (Get-WikiSpace -SpaceKey PESTER).Homepage | Get-WikiChildPage -Recurse + + # ASSERT + It 'returns the correct amount of results' { + $ChildPages.Count | Should Be 2 + $DesendantPages.Count | Should Be 4 + } + It 'returns an object with specific properties' { + $ChildPages | Should BeOfType [ConfluencePS.Page] + $DesendantPages | Should BeOfType [ConfluencePS.Page] + } + } + +Describe 'Remove-WikiLabel' { # ARRANGE $Label1 = "pesterc" $Page1 = Get-WikiPage -Title 'Pester New Page Piped' -ErrorAction Stop