Tests/Toolbox/Test-ToolboxDataLocation.Tests.ps1

BeforeAll {

    Set-StrictMode -Version "Latest"

    . "$PSScriptRoot\..\..\Source\Environment\Get-EnvironmentVariable.ps1"
    . "$PSScriptRoot\..\..\Source\Toolbox\Get-ToolboxDataLocation.ps1"
    . "$PSScriptRoot\..\..\Source\Toolbox\Test-ToolboxDataLocation.ps1"

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")]
    $originalValue = [Environment]::GetEnvironmentVariable("ToolboxData", "User")

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "")]
    $testPath = Join-Path -Path $env:Temp -ChildPath "ToolboxDataTest_$(New-Guid)"

}

AfterAll {

    [Environment]::SetEnvironmentVariable("ToolboxData", $originalValue, "User")

    if (Test-Path -Path $testPath) {

        Remove-Item -Path $testPath -Recurse -Force

    }

}

Describe "Test-ToolboxDataLocation" {

    It "Returns false when the resolved location doesn't exist" {

        [Environment]::SetEnvironmentVariable("ToolboxData", $testPath, "User")

        $result = Test-ToolboxDataLocation

        $result | Should -BeFalse

    }

    It "Returns true when the resolved location exists" {

        New-Item -Path $testPath -ItemType "Directory" -Force | Out-Null

        [Environment]::SetEnvironmentVariable("ToolboxData", $testPath, "User")

        $result = Test-ToolboxDataLocation

        $result | Should -BeTrue

    }

}