Tests/NewCredentialFromEnvironmentJson.Tests.ps1

Describe "New-CredentialFromEnvionmentJson" {
    function New-SampleEnvironmentJson {
        Param(
            # path to create file in
            [Parameter(Mandatory=$true)]
            [string]
            $Path
        )

        Set-Content -Path (Join-Path $Path 'environment.json') -Value '{"user": "testuser", "password": "testpassword"}'
    }

    Context "Environment.json file exists" {
        New-SampleEnvironmentJson -Path $TestDrive
        It "should create a PSCredential object" {
            $Credential = New-CredentialFromEnvironmentJson -SourcePath $TestDrive
            $Credential.UserName | should be 'testuser'
        }        
    }

    Context "Environment.json does not exist" {
        It "Should return false" {
            New-CredentialFromEnvironmentJson -SourcePath $TestDrive | should be $false
        }
    }
}