Testing/Get-TestCodeunitsInContainer.ps1

function Get-TestCodeunitsInContainer {
    param (
        # Container to load test codeunits into
        [Parameter(Mandatory=$false)]
        [string]
        $ContainerName = (Get-ContainerFromLaunchJson),
        # Credentials to use to connect to web service
        [Parameter(Mandatory=$false)]
        [System.Management.Automation.PSCredential]
        $Credential,
        # Name of the test suite to add the test codeunits to
        [Parameter(Mandatory=$false)]
        [string]
        $TestSuite = '',
        # Start of the range of objects to add
        [Parameter(Mandatory=$false)]
        [int]
        $StartId = ((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'idrange').from),
        # End of the range of objects to add
        [Parameter(Mandatory=$false)]
        [int]
        $EndId = ((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'idrange').to)
    )

    if ($null -eq $Credential) {
        $Password = ConvertTo-SecureString (Get-EnvironmentKeyValue -KeyName 'password') -AsPlainText -Force
        $Credential = New-Object System.Management.Automation.PSCredential((Get-EnvironmentKeyValue -KeyName 'user'), $Password)
    }

    if ($null -eq (Get-NavContainerAppInfo -containerName $ContainerName | Where-Object Name -eq 'Build Helper')) {
        $BuildHelperApp = Get-AppFromLastSuccessfulBuild -ProjectName 'TFS Tools' -RepositoryName BuildHelper
        Publish-NavContainerApp -containerName $ContainerName -appFile $BuildHelperApp.FullName -install -sync
    }

    $Companies = Get-CompanyInNavContainer $ContainerName | Where-Object {$_ -notlike 'WARNING*'}

    if ((Get-NavContainerCountry $ContainerName) -eq 'dk') { 
        $CompanyName = $Companies.Item(1).CompanyName
    }
    else {
        if ($null -eq $Companies.Count) {
            $CompanyName = $Companies.CompanyName
        }
        else {
            $CompanyName = $Companies.Item(0).CompanyName
        }
    }

    $Url = "http://{0}:7047/NAV/WS/{1}/Codeunit/AutomatedTestMgt" -f (Get-NavContainerIpAddress -containerName $ContainerName), $CompanyName
    Write-Host "Calling $Url to retrieve test codeunits"
    $AutomatedTestMgt = New-WebServiceProxy -Uri $Url -Credential $Credential
    $AutomatedTestMgt.GetTests($TestSuite,$StartId,$EndId)
}

Export-ModuleMember -Function Get-TestCodeunitsInContainer