|
9 | 9 | .PARAMETER Actual
|
10 | 10 | A collection of items.
|
11 | 11 |
|
| 12 | + .PARAMETER Count |
| 13 | + Checks if the collection has the expected number of items. |
| 14 | +
|
12 | 15 | .PARAMETER Because
|
13 | 16 | The reason why the input should be the expected value.
|
14 | 17 |
|
|
41 | 44 | param (
|
42 | 45 | [Parameter(Position = 1, ValueFromPipeline = $true)]
|
43 | 46 | $Actual,
|
44 |
| - [Parameter(Position = 0, Mandatory)] |
| 47 | + [Parameter(Position = 0, Mandatory, ParameterSetName = 'Expected')] |
45 | 48 | $Expected,
|
46 |
| - [String]$Because |
| 49 | + [String]$Because, |
| 50 | + [Parameter(ParameterSetName = 'Count')] |
| 51 | + [int] $Count |
47 | 52 | )
|
48 | 53 |
|
49 | 54 | $collectedInput = Collect-Input -ParameterInput $Actual -PipelineInput $local:Input -IsPipelineInput $MyInvocation.ExpectingInput
|
50 | 55 | $Actual = $collectedInput.Actual
|
51 | 56 |
|
52 |
| - if (-not (Is-Collection -Value $Expected)) { |
53 |
| - $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected <expectedType> <expected> is not a collection." |
| 57 | + if (-not (Is-Collection -Value $Actual)) { |
| 58 | + $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Actual <actualType> <actual> is not a collection." |
54 | 59 | throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true)
|
55 | 60 | }
|
56 | 61 |
|
57 |
| - if (-not (Is-Collection -Value $Actual)) { |
58 |
| - $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Actual <actualType> <actual> is not a collection." |
| 62 | + if ($PSCmdlet.ParameterSetName -eq 'Count') { |
| 63 | + if ($Count -ne $Actual.Count) { |
| 64 | + $Message = Get-AssertionMessage -Expected $Count -Actual $Actual -Because $Because -Data @{ actualCount = $Actual.Count } -DefaultMessage "Expected <expected> items in <actualType> <actual>,<because> but it has <actualCount> items." |
| 65 | + throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true) |
| 66 | + } |
| 67 | + return |
| 68 | + } |
| 69 | + |
| 70 | + if (-not (Is-Collection -Value $Expected)) { |
| 71 | + $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected <expectedType> <expected> is not a collection." |
59 | 72 | throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true)
|
60 | 73 | }
|
61 | 74 |
|
62 | 75 | if (-not (Is-CollectionSize -Expected $Expected -Actual $Actual)) {
|
63 |
| - $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected <expectedType> <expected> to be present in <actualType> <actual>, but they don't have the same number of items." |
| 76 | + $Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected <expectedType> <expected> to be present in <actualType> <actual>,<because> but they don't have the same number of items." |
64 | 77 | throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true)
|
65 | 78 | }
|
66 | 79 |
|
|
0 commit comments