Testing/Get-TestCodeunitsInContainer.ps1

<#
.synopsis
    Gets a list of all test codeunits in a container
.description
    Gets a list of all test codeunits in a test suite in a container based on an option object range
.parameter ContainerName
    Container to be used. Can be provided in the settings.json
.parameter Credential
    NAV/BC credentials to access the container
.parameter TestSuite
    Optional test suite name to use to determine the test codeunits
.parameter StartId
    Optional filter for object ids to be included in the returned list
.parameter EndId
    Optional filter for object ids to be included in the returned list
.example
    Export-ObjectsToFolder -ContainerName test -Folder C:\temp -Credential (Get-Credential)
#>

function Get-TestCodeunitsInContainer {
    param (
        # Container to load test codeunits into
        [Parameter(Mandatory=$false)]
        [string]
        $ContainerName = "",
        # Credentials to use to connect to web service
        [Parameter(Mandatory=$false)]
        [PSCredential]
        $Credential = (Get-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=$true)]
        [int]
        $StartId,
        # End of the range of objects to add
        [Parameter(Mandatory=$true)]
        [int]
        $EndId
    )

    $CompanyName = Get-ContainerCompanyToTest -ContainerName $ContainerName

    [version]$BCFallPlatform = '15.0.0.0'
    [Version]$platform = [Version]::Parse((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'platform'))
    if ($platform -ge $BCFallPlatform){
        $Url = "http://{0}:7047/BC/WS/{1}/Codeunit/NavxAutomatedTestManagement?tenant=default" -f (Get-BcContainerIpAddress -containerName $ContainerName), $CompanyName
    } else{
        $Url = "http://{0}:7047/NAV/WS/{1}/Codeunit/NavxAutomatedTestManagement" -f (Get-BcContainerIpAddress -containerName $ContainerName), $CompanyName
    }

    Write-Output "Calling $Url to retrieve test codeunits"
    $AutomatedTestMgt = New-WebServiceProxy -Uri $Url -Credential $Credential
    $AutomatedTestMgt.ClearTestSuite($TestSuite)
    $AutomatedTestMgt.GetTests($TestSuite,$StartId,$EndId)
}