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)) {
            NewItem $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)) {
        $startid = ((Get-AppKeyValue -KeyName 'idRanges') | Select-Object -First 1).from
        $endid = ((Get-AppKeyValue -KeyName 'idRanges') | Select-Object -Last 1).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