Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion test/Find-Member.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ Describe 'Find-Member cmdlet tests' {
}

It 'filters passed members' {
$source = [type] | Find-Member
$source = [powershell] | Find-Member -Force
$results = $source | Find-Member -Static

$results | ShouldAll { $_ -in $source }
$results.Count | Should -Not -Be $source.Count
}
}

It 'gets all members with no input' {
$results = Find-Member
$results.Count | Should -BeGreaterThan 10000
}

It 'matches nonpublic members with Force' {
$result = $ExecutionContext.SessionState | Find-Member -Force

# A nonpublic member is present
$result | ShouldAny { $_.Name -eq 'Internal' -and 'Property' -eq $_.MemberType }

# A public member is still present
$result | ShouldAny { $_.Name -eq 'Module' -and 'Property' -eq $_.MemberType }
}

It 'matches with FilterScript' {
$result = [powershell] |
Find-Member -FilterScript { $_.Name -eq 'Create' -and $_.GetParameters().Count -eq 0 }
Expand Down Expand Up @@ -58,6 +73,31 @@ Describe 'Find-Member cmdlet tests' {
ShouldAny { $_.Name -eq 'Create' }
}

It 'return type matches constructors' {
[System.Collections.Generic.List[string]] |
Find-Member -ReturnType System.Collections.Generic.List[string] |
ShouldAny { 'Constructor' -eq $_.MemberType }
}

It 'unwraps target types with elements' {
$result = [System.Management.Automation.Language.Parser] |
Find-Member -ParameterType System.Management.Automation.Language.Token

$result | ShouldAny {
($parameters = $_.GetParameters()) -and
$parameters[1].ParameterType.IsByRef -and
$parameters[1].ParameterType.GetElementType().IsArray
}
}

It 'return type matches fields' {
$contextType = Find-Type ExecutionContext -Namespace *Automation -Force
$result = $ExecutionContext | Find-Member -ReturnType $contextType -Force

$result.MemberType | Should -Be Field
$result.FieldType | Should -Be $contextType
}

It 'filters to virtual members' {
$results = [runspace] | Find-Member -Virtual

Expand Down Expand Up @@ -89,4 +129,15 @@ Describe 'Find-Member cmdlet tests' {
$results | ShouldAll { $_.Name -ne 'AddScript' }
$results | ShouldAny { $_.Name -eq 'Create' }
}

It 'gets members for passed objects only once per type' {
$powershells = [powershell]::Create(), [powershell]::Create()
try {
$result = $powershells | Find-Member
} finally {
$powershells.ForEach('Dispose')
}

$result.Where{ $_.Name -eq 'Create' }.Count | Should -Be 3
}
}
16 changes: 16 additions & 0 deletions test/Find-Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ Describe 'Find-Type tests' {
It 'matches by namespace' {
Find-Type -Namespace System.Timers | ShouldAll { $_.Namespace -eq 'System.Timers' }
}
It 'matches by full name' {
Find-Type -FullName System.Management.Automation.ProxyCommand |
Should -Be ([System.Management.Automation.ProxyCommand])
}
It 'matches by name with regex' {
Find-Type "Runspace(Factory|ConnectionInfo)" -RegularExpression |
Should -Be ([runspacefactory], [System.Management.Automation.Runspaces.RunspaceConnectionInfo])
}
It 'matches by namespace with regex' {
Find-Type MethodAttributes -Namespace 'System\.(?!Reflection).+' -RegularExpression |
Should -Be ([System.Management.Automation.Language.MethodAttributes])
}
It 'matches by full name with regex' {
Find-Type -FullName 'System\.(?!Threading)\w+\.Timer$' -RegularExpression |
Should -Be ([System.Timers.Timer])
}
It 'matches by base class' {
$results = Find-Type -InheritsType System.Management.Automation.Language.Ast

Expand Down
5 changes: 5 additions & 0 deletions test/Get-Parameter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ Describe 'Get-Parameter tests' {

$results | ShouldAny { $_.Name -eq 'asyncResult' }
}

It 'returns nothing without input' {
Get-Parameter | Should -BeNullOrEmpty
$null | Get-Parameter | Should -BeNullOrEmpty
}
}