src/String/Assert-StringNotEqual.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
function Get-StringNotEqualDefaultFailureMessage ([String]$Expected, $Actual) 
{
    "Expected the strings to be different but they were the same '$Expected'."
}

function Assert-StringNotEqual 
{
    param (
        [Parameter(Position=1, ValueFromPipeline=$true)]
        $Actual, 
        [Parameter(Position=0)]
        [String]$Expected,
        [String]$CustomMessage,
        [switch]$CaseSensitive,
        [switch]$IgnoreWhitespace
    )

    if (Test-StringEqual -Expected $Expected -Actual $Actual -CaseSensitive:$CaseSensitive -IgnoreWhitespace:$IgnoreWhiteSpace) 
    {
        if (-not $CustomMessage)
        {
            $formattedMessage = Get-StringNotEqualDefaultFailureMessage -Expected $Expected -Actual $Actual
        }
        else 
        {
            $formattedMessage = Get-CustomFailureMessage -Expected $Expected -Actual $Actual -CustomMessage $CustomMessage
        }

        throw [Assertions.AssertionException]$formattedMessage
    }
}