Functions/Assertions/BeIn.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
function PesterBeIn($ActualValue, $ExpectedValue, [switch] $Negate, [string] $Because)
{
    [bool] $succeeded = $ExpectedValue -contains $ActualValue
    if ($Negate) { $succeeded = -not $succeeded }

    if (-not $succeeded)
    {
        if ($Negate)
        {
            return New-Object psobject -Property @{
                Succeeded      = $false
                FailureMessage = "Expected collection [$($ExpectedValue -join ',')] to not contain {$ActualValue},$(Format-Because $Because) but it was found."
            }
        }
        else
        {
            return New-Object psobject -Property @{
                Succeeded      = $false
                FailureMessage = "Expected collection [$($ExpectedValue -join ',')] to contain {$ActualValue},$(Format-Because $Because) but it was not found."
            }
        }
    }

    return New-Object psobject -Property @{
        Succeeded      = $true
    }
}

Add-AssertionOperator -Name BeIn `
                      -Test $function:PesterBeIn


function PesterBeInFailureMessage() { }
function NotPesterBeInFailureMessage() { }