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)]
        [PSCredential]
        $Credential = (New-CredentialFromEnvironmentJson),
        # 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 = 0,
        # End of the range of objects to add
        [Parameter(Mandatory=$false)]
        [int[]]
        $EndId = 0
    )

    if (($StartId[0] -eq 0) -and ($EndId[0] -eq 0)) {
        if (Get-AppKeyValue -KeyName 'idrange') {
            $StartId[0] = (Get-AppKeyValue -KeyName 'idrange').from
            $EndId[0] = (Get-AppKeyValue -KeyName 'idrange').to
        }
        elseif (Get-AppKeyValue -KeyName 'idranges') {
            $FirstRange = $true
            foreach ($Range in (Get-AppKeyValue -KeyName 'idranges')) {
                if ($FirstRange) {
                    $StartId[0] = $Range.from
                    $EndId[0] = $Range.to
                    $FirstRange = $false
                }
                else {
                    $StartId += $Range.from
                    $EndId += $Range.to
                }
            }
        }
    }

    Install-BuildHelper -ContainerName $ContainerName
    $CompanyName = Get-ContainerCompanyToTest -ContainerName $ContainerName   
    $Url = "http://{0}:7047/{1}/WS/{2}/Codeunit/AutomatedTestMgt" -f (Get-NavContainerIpAddress -containerName $ContainerName), (Get-ContainerWebServerInstance $ContainerName), $CompanyName
    
    Write-Host "Calling $Url to retrieve test codeunits"
    $AutomatedTestMgt = New-WebServiceProxy -Uri $Url -Credential $Credential

    $i = 0
    foreach ($Start in $StartId) {
        $End = $EndId[$i]
        Write-Host "Fetching test codeunits from $Start to $End"
        $AutomatedTestMgt.GetTests($TestSuite,$Start,$End)
        $i += 1
    }
}

Export-ModuleMember -Function Get-TestCodeunitsInContainer