Tests/Environment/Get-EnvironmentVariable.Tests.ps1

BeforeAll {

    Set-StrictMode -Version "Latest"

    . "$PSScriptRoot\..\..\Source\Environment\Get-EnvironmentVariable.ps1"

}

Describe "Get-EnvironmentVariable" {

    It "Returns the value of an existing Process-scoped variable" {

        [Environment]::SetEnvironmentVariable("ToolboxTestVariable", "ToolboxTestValue", "Process")

        $result = Get-EnvironmentVariable -Name "ToolboxTestVariable" -Scope "Process"

        $result | Should -Be "ToolboxTestValue"

        [Environment]::SetEnvironmentVariable("ToolboxTestVariable", $null, "Process")

    }

    It "Returns null for a variable that doesn't exist" {

        $result = Get-EnvironmentVariable -Name "ToolboxNonExistentVariable" -Scope "Process"

        $result | Should -BeNullOrEmpty

    }

    It "Accepts the variable name from the pipeline" {

        [Environment]::SetEnvironmentVariable("ToolboxTestVariable", "ToolboxTestValue", "Process")

        $result = "ToolboxTestVariable" | Get-EnvironmentVariable -Scope "Process"

        $result | Should -Be "ToolboxTestValue"

        [Environment]::SetEnvironmentVariable("ToolboxTestVariable", $null, "Process")

    }

}