Functions/Search-HashTable.Tests.ps1

describe "BitTitan.Runbooks.Common/Search-HashTable" -Tag "module", "unit" {

    # Import the function to test
    . "$($PSScriptRoot)\Search-HashTable.ps1"

    # Create hash table to search
    $hashTable = @{
        Key1 = "Value1"
        kEy2 = 2
        keY3 = $true
    }

    it "receives null with a non-existent key 'Key4' using case insensitive search" {
        $hashTable | Search-HashTable -Key "Key4" -CaseSensitive:$false | Should Be $null
    }

    it "receives null with a non-existent key 'Key4' using case sensitive search" {
        $hashTable | Search-HashTable -Key "Key4" -CaseSensitive:$true | Should Be $null
    }

    it -TestCases @(
        @{
            key             = "key1"
            value           = "Value1"
            caseSensitive   = $false
        },
        @{
            key             = "kEy1"
            value           = "Value1"
            caseSensitive   = $false
        },
        @{
            key             = "keY1"
            value           = "Value1"
            caseSensitive   = $false
        }
    ) "retrieves the value '<value>' with the case insensitive key '<key>' using case insensitive search" {
        param ($key, $value, $caseSensitive)
        $hashTable | Search-HashTable -Key $key -CaseSensitive:$caseSensitive | Should Be $value
    }

    it -TestCases @(
        @{
            key             = "Key1"
            value           = "Value1"
            caseSensitive   = $false
        },
        @{
            key             = "Key2"
            value           = 2
            caseSensitive   = $false
        },
        @{
            key             = "Key3"
            value           = $true
            caseSensitive   = $false
        }
    ) "retrieves the value '<value>' with the case sensitive key '<key>' using case insensitive search" {
        param ($key, $value, $caseSensitive)
        $hashTable | Search-HashTable -Key $key -CaseSensitive:$caseSensitive | Should Be $value
    }

    it -TestCases @(
        @{
            key             = "Key1"
            value           = "Value1"
            caseSensitive   = $true
        },
        @{
            key             = "kEy2"
            value           = 2
            caseSensitive   = $true
        },
        @{
            key             = "keY3"
            value           = $true
            caseSensitive   = $true
        }
    ) "retrieves the value '<value>' with the case sensitive key '<key>' using case sensitive search" {
        param ($key, $value, $caseSensitive)
        $hashTable | Search-HashTable -Key $key -CaseSensitive:$caseSensitive | Should Be $value
    }
}