Skip to content

Commit

Permalink
#3441: Add support for "TestCodeunitRangeFilter" field (#3492)
Browse files Browse the repository at this point in the history
#3441
Adds new parameter "testCodeunitRange" to `Get-TestFromBcContainer` and
`Run-TestsInBcContainer` that allows filling the test suite by using a
codeunit-filter and using the TestCodeunitRangeFilter field already
present on the command line test tool.

---------

Co-authored-by: The Dumb <[email protected]>
  • Loading branch information
hemisphera and Thomas-Torggler-EOS authored May 20, 2024
1 parent a4a1589 commit ebf71ec
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
14 changes: 12 additions & 2 deletions AppHandling/Get-TestsFromNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
Name of test suite to get. Default is DEFAULT.
.Parameter testCodeunit
Name or ID of test codeunit to get. Wildcards (? and *) are supported. Default is *.
This parameter will not populate the test suite with the specified codeunit. This is used as a filter on the tests that are already present
(or otherwise loaded) in the suite.
This is not to be confused with -testCodeunitRange.
.Parameter testCodeunitRange
A BC-compatible filter string to use for loading test codeunits (similar to -extensionId). This is not to be confused with -testCodeunit.
If you set this parameter to '*', all test codeunits will be loaded.
This might not work on all versions of BC and only works when using the command-line-testtool.
.Parameter testPage
ID of the test page to use. Default for 15.x containers is 130455. Default for 14.x containers and earlier is 130409.
.Parameter culture
Expand Down Expand Up @@ -56,6 +63,8 @@ function Get-TestsFromBcContainer {
[string] $testSuite = "DEFAULT",
[Parameter(Mandatory=$false)]
[string] $testCodeunit = "*",
[Parameter(Mandatory=$false)]
[string] $testCodeunitRange = "",
[string] $extensionId = "",
[array] $disabledTests = @(),
[Parameter(Mandatory=$false)]
Expand Down Expand Up @@ -171,7 +180,7 @@ try {
}
} -argumentList "01:00:00"

$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testCodeunit, [string] $PsTestFunctionsPath, [string] $ClientContextPath, $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests)
$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testCodeunit, [string] $testCodeunitRange, [string] $PsTestFunctionsPath, [string] $ClientContextPath, $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests)

$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
if (!(Test-Path $newtonSoftDllPath)) {
Expand Down Expand Up @@ -227,6 +236,7 @@ try {
Get-Tests -clientContext $clientContext `
-TestSuite $testSuite `
-TestCodeunit $testCodeunit `
-testCodeunitRange $testCodeunitRange `
-ExtensionId $extensionId `
-DisabledTests $disabledtests `
-testPage $testPage `
Expand All @@ -249,7 +259,7 @@ try {
}
}

} -argumentList $tenant, $companyName, $profile, $credential, $accessToken, $testSuite, $testCodeunit, (Get-BCContainerPath -containerName $containerName -path $PsTestFunctionsPath), (Get-BCContainerPath -containerName $containerName -path $ClientContextPath), $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests
} -argumentList $tenant, $companyName, $profile, $credential, $accessToken, $testSuite, $testCodeunit, $testCodeunitRange, (Get-BCContainerPath -containerName $containerName -path $PsTestFunctionsPath), (Get-BCContainerPath -containerName $containerName -path $ClientContextPath), $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests

# When Invoke-ScriptInContainer is running as non-administrator - Write-Host (like license warnings) are send to the output
# If the output is an array - grab the last item.
Expand Down
26 changes: 26 additions & 0 deletions AppHandling/PsTestFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ function Set-ExtensionId
$ClientContext.SaveValue($extensionIdControl, $ExtensionId)
}

function Set-TestCodeunitRange
(
[string] $testCodeunitRange,
[ClientContext] $ClientContext,
[switch] $debugMode,
$Form
) {
Write-Host "Setting test codeunit range '$testCodeunitRange'"
if (!$testCodeunitRange) { return }
if ($testCodeunitRange -eq "*") { $testCodeunitRange = "0.." }

if ($debugMode) {
Write-Host "Setting test codeunit range '$testCodeunitRange'"
}
$testCodeunitRangeControl = $ClientContext.GetControlByName($Form, "TestCodeunitRangeFilter")
if ($null -eq $testCodeunitRangeControl) {
if ($debugMode) { Write-Host "Test codeunit range control not found on test page" }
return
}
$ClientContext.SaveValue($testCodeunitRangeControl, $testCodeunitRange)
}

function Set-TestRunnerCodeunitId
(
[string] $testRunnerCodeunitId,
Expand Down Expand Up @@ -304,6 +326,7 @@ function Get-Tests {
[int] $testPage = 130409,
[string] $testSuite = "DEFAULT",
[string] $testCodeunit = "*",
[string] $testCodeunitRange = "",
[string] $extensionId = "",
[string] $testRunnerCodeunitId = "",
[array] $disabledtests = @(),
Expand Down Expand Up @@ -345,6 +368,7 @@ function Get-Tests {

if ($testPage -eq 130455) {
Set-ExtensionId -ExtensionId $extensionId -Form $form -ClientContext $clientContext -debugMode:$debugMode
Set-TestCodeunitRange -testCodeunitRange $testCodeunitRange -Form $form -ClientContext $clientContext -debugMode:$debugMode
Set-TestRunnerCodeunitId -TestRunnerCodeunitId $testRunnerCodeunitId -Form $form -ClientContext $clientContext -debugMode:$debugMode
Set-RunFalseOnDisabledTests -DisabledTests $DisabledTests -Form $form -ClientContext $clientContext -debugMode:$debugMode
$clientContext.InvokeAction($clientContext.GetActionByName($form, 'ClearTestResults'))
Expand Down Expand Up @@ -492,6 +516,7 @@ function Run-Tests {
[int] $testPage = 130409,
[string] $testSuite = "DEFAULT",
[string] $testCodeunit = "*",
[string] $testCodeunitRange = "",
[string] $testGroup = "*",
[string] $testFunction = "*",
[string] $extensionId = "",
Expand Down Expand Up @@ -558,6 +583,7 @@ function Run-Tests {

if ($testPage -eq 130455) {
Set-ExtensionId -ExtensionId $extensionId -Form $form -ClientContext $clientContext -debugMode:$debugMode
Set-TestCodeunitRange -testCodeunitRange $testCodeunitRange -Form $form -ClientContext $clientContext -debugMode:$debugMode
Set-TestRunnerCodeunitId -TestRunnerCodeunitId $testRunnerCodeunitId -Form $form -ClientContext $clientContext -debugMode:$debugMode
Set-RunFalseOnDisabledTests -DisabledTests $DisabledTests -Form $form -ClientContext $clientContext -debugMode:$debugMode
$clientContext.InvokeAction($clientContext.GetActionByName($form, 'ClearTestResults'))
Expand Down
15 changes: 13 additions & 2 deletions AppHandling/Run-TestsInNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
Only supported in 14.x containers or older. Name of test group to run. Wildcards (? and *) are supported. Default is *.
.Parameter testCodeunit
Name or ID of test codeunit to run. Wildcards (? and *) are supported. Default is *.
This parameter will not populate the test suite with the specified codeunit. This is used as a filter on the tests that are already present
(or otherwise loaded) in the suite.
This is not to be confused with -testCodeunitRange.
.Parameter testCodeunitRange
A BC-compatible filter string to use for loading test codeunits (similar to -extensionId). This is not to be confused with -testCodeunit.
If you set this parameter to '*', all test codeunits will be loaded.
This might not work on all versions of BC and only works when using the command-line-testtool.
.Parameter testFunction
Name of test function to run. Wildcards (? and *) are supported. Default is *.
.Parameter ExtensionId
Expand Down Expand Up @@ -99,6 +106,8 @@ function Run-TestsInBcContainer {
[Parameter(Mandatory=$false)]
[string] $testCodeunit = "*",
[Parameter(Mandatory=$false)]
[string] $testCodeunitRange = "",
[Parameter(Mandatory=$false)]
[string] $testFunction = "*",
[string] $extensionId = "",
[string] $testRunnerCodeunitId = "",
Expand Down Expand Up @@ -330,6 +339,7 @@ try {
-TestSuite $testSuite `
-TestGroup $testGroup `
-TestCodeunit $testCodeunit `
-TestCodeunitRange $testCodeunitRange `
-TestFunction $testFunction `
-ExtensionId $extensionId `
-TestRunnerCodeunitId $testRunnerCodeunitId `
Expand Down Expand Up @@ -374,7 +384,7 @@ try {
}
}

$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testGroup, [string] $testCodeunit, [string] $testFunction, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [string] $XUnitResultFileName, [bool] $AppendToXUnitResultFile, [string] $JUnitResultFileName, [bool] $AppendToJUnitResultFile, [bool] $ReRun, [string] $AzureDevOps, [string] $GitHubActions, [bool] $detailed, [timespan] $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests)
$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testGroup, [string] $testCodeunit, [string] $testCodeunitRange, [string] $testFunction, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [string] $XUnitResultFileName, [bool] $AppendToXUnitResultFile, [string] $JUnitResultFileName, [bool] $AppendToJUnitResultFile, [bool] $ReRun, [string] $AzureDevOps, [string] $GitHubActions, [bool] $detailed, [timespan] $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests)

$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
if (!(Test-Path $newtonSoftDllPath)) {
Expand Down Expand Up @@ -452,6 +462,7 @@ try {
-TestSuite $testSuite `
-TestGroup $testGroup `
-TestCodeunit $testCodeunit `
-TestCodeunitRange $testCodeunitRange `
-TestFunction $testFunction `
-ExtensionId $extensionId `
-TestRunnerCodeunitId $testRunnerCodeunitId `
Expand Down Expand Up @@ -480,7 +491,7 @@ try {
}
}

} -argumentList $tenant, $companyName, $profile, $credential, $accessToken, $testSuite, $testGroup, $testCodeunit, $testFunction, (Get-BcContainerPath -containerName $containerName -Path $PsTestFunctionsPath), (Get-BCContainerPath -containerName $containerName -path $ClientContextPath), $containerXUnitResultFileName, $AppendToXUnitResultFile, $containerJUnitResultFileName, $AppendToJUnitResultFile, $ReRun, $AzureDevOps, $GitHubActions, $detailed, $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests.IsPresent
} -argumentList $tenant, $companyName, $profile, $credential, $accessToken, $testSuite, $testGroup, $testCodeunit, $testCodeunitRange, $testFunction, (Get-BcContainerPath -containerName $containerName -Path $PsTestFunctionsPath), (Get-BCContainerPath -containerName $containerName -path $ClientContextPath), $containerXUnitResultFileName, $AppendToXUnitResultFile, $containerJUnitResultFileName, $AppendToJUnitResultFile, $ReRun, $AzureDevOps, $GitHubActions, $detailed, $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests.IsPresent
}
if ($result -is [array]) {
0..($result.Count-2) | % { Write-Host $result[$_] }
Expand Down
1 change: 1 addition & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Use altool from prerelease AL Language extension
Display disk free inside container on error
Create AppInfo cache on creating a new compiler folder
Add support for using `TestCodeunitRangeFilter` field in `Run-TestsInBcContainer` and `Get-TestsFromBcContainer`

6.0.17
Issue 3518 If WinRm is not running on the host, a container couldn't be created
Expand Down

0 comments on commit ebf71ec

Please sign in to comment.