Testing/Invoke-BCTests.ps1

function Invoke-BCTests
{
    Param(
        [Parameter(Mandatory=$false)]
        [string]$ResultPath = '',
        [Parameter(Mandatory=$false)]
        [string]$ContainerName,
        # Name of test suite to run
        [Parameter(Mandatory=$false)]
        [string]
        $TestSuite = 'DEFAULT',
        # Number of test codeunit to run
        [Parameter(Mandatory=$false)]
        [string]
        $TestCodeunit ='*',
        # Name of test method to run
        [Parameter(Mandatory=$false)]
        [string]
        $TestMethod = '*',
        [Parameter(Mandatory=$false)]
        [PSCredential]$Credential = (New-CredentialFromEnvironmentJson),
        [Parameter(Mandatory=$false)]
        [switch]$DoNotPrepTestSuite
    )

    if ($ResultPath -ne '') {
        if (!(Test-Path $ResultPath)) {
            New-Item $ResultPath -ItemType Directory
        }
    }

    if ($ContainerName -eq '') {
        $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name')
    }

    Write-Host -ForegroundColor Green "Run tests in container $ContainerName, suite $TestSuite, codeunit $TestCodeunit, method $TestMethod"

    if (!($DoNotPrepTestSuite.IsPresent)) {
        [version]$platform = Get-AppKeyValue -KeyName "platform"
        if ($platform.Major -gt 13) {
            $startid = ((Get-AppKeyValue -KeyName 'idRanges') | Select-Object -First 1).from
            $endid = ((Get-AppKeyValue -KeyName 'idRanges') | Select-Object -Last 1).to
        } 
        else {
            $startid = (Get-AppKeyValue -KeyName 'idRange').from
            $endid = (Get-AppKeyValue -KeyName 'idRange').to
        }

        Get-TestCodeunitsInContainer -ContainerName $ContainerName -TestSuite $TestSuite -Credential $Credential -StartId $startid -EndId $endid
    }

    Write-Host 'Executing tests in client'

    Run-TestsInNavContainer -containerName $ContainerName -credential $Credential -XUnitResultFileName "C:\ProgramData\NavContainerHelper\Extensions\$ContainerName\my\Results.xml" -detailed -testSuite $TestSuite -testCodeunit $TestCodeunit -testFunction $TestMethod -returnTrueIfAllPassed -AzureDevOps error 

    if ($ResultPath -ne '') {
        Write-Host "Copying results to publishing folder ($ResultPath)"
        Copy-Item "C:\ProgramData\NavContainerHelper\Extensions\$ContainerName\my\Results.xml" $ResultPath -Force
    }
}

Export-ModuleMember -Function Invoke-BCTests