Functions/Get-EmailAddressUsername.Tests.ps1

describe "BitTitan.Runbooks.Common/Get-EmailAddressUsername" -Tag "module", "unit" {

    # Import the function to test
    . "$($PSScriptRoot)\Get-EmailAddressUsername.ps1"

    it -TestCases @(
        @{
            emailAddress    = "ValidEmail@domain.com"
            username        = "ValidEmail"
        },
        @{
            emailAddress    = "valid.email@domain.com"
            username        = "valid.email"
        },
        @{
            emailAddress    = "valid-email@domain.com"
            username        = "valid-email"
        }
    ) "extracts the username '<username>' from the valid email address '<emailAddress>'" {
        param ($emailAddress, $username)
        Get-EmailAddressUsername $emailAddress | Should Be $username
    }

    it -TestCases @(
        @{ emailAddress = "invalidEmail.com" },
        @{ emailAddress = "invalidEmail." },
        @{ emailAddress = "invalidEmail.c" }
    ) "returns an empty string from the invalid email address '<emailAddress>'" {
        param ($emailAddress)
        Get-EmailAddressUsername $emailAddress | Should Be ""
    }
}