Tests/Get-LaunchKeyValue.Tests.ps1

Describe Get-LaunchKeyValue {
    function New-LaunchJson {
        Param(
            # path to create the sample file in
            [Parameter(Mandatory=$true)]
            [string]
            $Path
        )

        New-Item (Join-Path $Path '.vscode') -ItemType Directory
        Set-Content -Path (Join-Path (Join-Path $Path '.vscode') 'launch.json') -Value '{"version": "0.2.0", "configurations": [{"type": "al", "name": "zero"},{"type": "al", "name": "one", "serverInstance": "Instance1"},{"type": "al", "name": "two", "serverInstance": "Instance2"}]}'
    }

    Context 'Sample launch json file exists' {
        New-LaunchJson -Path $TestDrive
        It 'Returns the requested key from the first configuration which has that key' {
            Get-LaunchKeyValue -Path $TestDrive -KeyName 'serverInstance' | should be 'Instance1'
        }

        It 'Returns the requested key from the specified configuration' {
            Get-LaunchKeyValue -Path $TestDrive -KeyName 'serverInstance' -ConfigurationName 'two' | should be 'Instance2'
        }

        It 'Returns the requested key from the specified configuration, even if the key does''t exist' {
            Get-LaunchKeyValue -Path $TestDrive -KeyName 'serverInstance' -ConfigurationName 'zero' | should be ''
        }
    }
}