tests/functions/utility/Select-PSFPropertyValue.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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
Describe "Select-PSFPropertyValue Unit Tests" -Tag "Unit" { BeforeAll { # Place here all things needed to prepare for the tests $object = [pscustomobject]@{ Length = 42 Name = "Foo" FullName = "Foo.Bar.Com" Empty = "" Null = $null Zero = 0 } } AfterAll { # Here is where all the cleanup tasks go } #region Signature Test Describe "Ensuring unchanged command signature" { It "should have the expected parameter sets" { (Get-Command Select-PSFPropertyValue).ParameterSets.Name | Should -Be 'Default', 'Fallback', 'Select', 'Join', 'Format' } It 'Should have the expected parameter Property' { $parameter = (Get-Command Select-PSFPropertyValue).Parameters['Property'] $parameter.Name | Should -Be 'Property' $parameter.ParameterType.ToString() | Should -Be System.String[] $parameter.IsDynamic | Should -Be $False $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 0 $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False } It 'Should have the expected parameter Fallback' { $parameter = (Get-Command Select-PSFPropertyValue).Parameters['Fallback'] $parameter.Name | Should -Be 'Fallback' $parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter $parameter.IsDynamic | Should -Be $False $parameter.ParameterSets.Keys | Should -Be 'Fallback' $parameter.ParameterSets.Keys | Should -Contain 'Fallback' $parameter.ParameterSets['Fallback'].IsMandatory | Should -Be $False $parameter.ParameterSets['Fallback'].Position | Should -Be -2147483648 $parameter.ParameterSets['Fallback'].ValueFromPipeline | Should -Be $False $parameter.ParameterSets['Fallback'].ValueFromPipelineByPropertyName | Should -Be $False $parameter.ParameterSets['Fallback'].ValueFromRemainingArguments | Should -Be $False } It 'Should have the expected parameter Select' { $parameter = (Get-Command Select-PSFPropertyValue).Parameters['Select'] $parameter.Name | Should -Be 'Select' $parameter.ParameterType.ToString() | Should -Be System.String $parameter.IsDynamic | Should -Be $False $parameter.ParameterSets.Keys | Should -Be 'Select' $parameter.ParameterSets.Keys | Should -Contain 'Select' $parameter.ParameterSets['Select'].IsMandatory | Should -Be $False $parameter.ParameterSets['Select'].Position | Should -Be -2147483648 $parameter.ParameterSets['Select'].ValueFromPipeline | Should -Be $False $parameter.ParameterSets['Select'].ValueFromPipelineByPropertyName | Should -Be $False $parameter.ParameterSets['Select'].ValueFromRemainingArguments | Should -Be $False } It 'Should have the expected parameter JoinBy' { $parameter = (Get-Command Select-PSFPropertyValue).Parameters['JoinBy'] $parameter.Name | Should -Be 'JoinBy' $parameter.ParameterType.ToString() | Should -Be System.String $parameter.IsDynamic | Should -Be $False $parameter.ParameterSets.Keys | Should -Be 'Join' $parameter.ParameterSets.Keys | Should -Contain 'Join' $parameter.ParameterSets['Join'].IsMandatory | Should -Be $False $parameter.ParameterSets['Join'].Position | Should -Be -2147483648 $parameter.ParameterSets['Join'].ValueFromPipeline | Should -Be $False $parameter.ParameterSets['Join'].ValueFromPipelineByPropertyName | Should -Be $False $parameter.ParameterSets['Join'].ValueFromRemainingArguments | Should -Be $False } It 'Should have the expected parameter FormatWith' { $parameter = (Get-Command Select-PSFPropertyValue).Parameters['FormatWith'] $parameter.Name | Should -Be 'FormatWith' $parameter.ParameterType.ToString() | Should -Be System.String $parameter.IsDynamic | Should -Be $False $parameter.ParameterSets.Keys | Should -Be 'Format' $parameter.ParameterSets.Keys | Should -Contain 'Format' $parameter.ParameterSets['Format'].IsMandatory | Should -Be $False $parameter.ParameterSets['Format'].Position | Should -Be -2147483648 $parameter.ParameterSets['Format'].ValueFromPipeline | Should -Be $False $parameter.ParameterSets['Format'].ValueFromPipelineByPropertyName | Should -Be $False $parameter.ParameterSets['Format'].ValueFromRemainingArguments | Should -Be $False } It 'Should have the expected parameter InputObject' { $parameter = (Get-Command Select-PSFPropertyValue).Parameters['InputObject'] $parameter.Name | Should -Be 'InputObject' $parameter.ParameterType.ToString() | Should -Be System.Object $parameter.IsDynamic | Should -Be $False $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $False $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be -2147483648 $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $True $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False } } #endregion Signature Test Describe "Testing parameterset Default" { It "Should select a single property correctly" { $object | Select-PSFPropertyValue -Property 'Length' | Should -Be 42 } It "Should select multiple properties correctly" { $object | Select-PSFPropertyValue -Property 'Length', 'Name' | Should -Be 42, 'Foo' } } Describe "Testing parameterset Fallback" { It "Testing Fallback: All exist, nothing special" { $object | Select-PSFPropertyValue -Property 'Length', 'Name' -Fallback | Should -Be 42 } It "Testing Fallback: Null and filled" { $object | Select-PSFPropertyValue -Property 'Null', 'Name' -Fallback | Should -Be 'Foo' } It "Testing Fallback: Zero and filled" { $object | Select-PSFPropertyValue -Property 'Zero', 'Name' -Fallback | Should -Be 0 } It "Testing Fallback: Empty string and filled" { $object | Select-PSFPropertyValue -Property 'Empty', 'Name' -Fallback | Should -Be 'Foo' } } Describe "Testing parameterset Select" { It "Should select the largest property value" { $object | Select-PSFPropertyValue -Property Name, FullName, Length -Select Largest | Should -Be 'Foo.Bar.Com' } It "Should select the lowest property value" { $object | Select-PSFPropertyValue -Property Name, FullName, Length -Select Lowest| Should -Be 42 } } Describe "Testing parameterset Join" { It "Should correctly join selected properties" { $object | Select-PSFPropertyValue 'Name', 'Length' -JoinBy "|" | Should -Be 'Foo|42' } } Describe "Testing parameterset Format" { It "Should insert values into the specified format" { $object | Select-PSFPropertyValue 'Name', 'Length', 'FullName' -FormatWith '{0} | {2} | {1:D3}' | Should -Be 'Foo | Foo.Bar.Com | 042' } } } |