From 0b666b23dfd47a8edf8aaae397d4904efe910b43 Mon Sep 17 00:00:00 2001 From: The Dumb Date: Tue, 26 Mar 2024 08:33:51 +0100 Subject: [PATCH] #3441: Add support for "TestCodeunitRangeFilter" field --- AppHandling/Get-TestsFromNavContainer.ps1 | 14 ++++++++++-- AppHandling/PsTestFunctions.ps1 | 28 +++++++++++++++++++++++ AppHandling/Run-TestsInNavContainer.ps1 | 9 ++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/AppHandling/Get-TestsFromNavContainer.ps1 b/AppHandling/Get-TestsFromNavContainer.ps1 index d1b9c0f2d..0952f0102 100644 --- a/AppHandling/Get-TestsFromNavContainer.ps1 +++ b/AppHandling/Get-TestsFromNavContainer.ps1 @@ -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 @@ -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)] @@ -171,7 +180,7 @@ try { } } -argumentList "01:00:00" - $result = Invoke-ScriptInBcContainer -containerName $containerName { 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 { 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)) { @@ -227,6 +236,7 @@ try { Get-Tests -clientContext $clientContext ` -TestSuite $testSuite ` -TestCodeunit $testCodeunit ` + -testCodeunitRange $testCodeunitRange ` -ExtensionId $extensionId ` -DisabledTests $disabledtests ` -testPage $testPage ` @@ -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. diff --git a/AppHandling/PsTestFunctions.ps1 b/AppHandling/PsTestFunctions.ps1 index f7aab73ba..8b6e806fc 100644 --- a/AppHandling/PsTestFunctions.ps1 +++ b/AppHandling/PsTestFunctions.ps1 @@ -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 = "*") { $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, @@ -304,6 +326,7 @@ function Get-Tests { [int] $testPage = 130409, [string] $testSuite = "DEFAULT", [string] $testCodeunit = "*", + [string] $testCodeunitRange, [string] $extensionId = "", [string] $testRunnerCodeunitId = "", [array] $disabledtests = @(), @@ -343,8 +366,11 @@ function Get-Tests { $suiteControl = $clientContext.GetControlByName($form, "CurrentSuiteName") $clientContext.SaveValue($suiteControl, $testSuite) + Write-Host ">>$testPage" + Write-Host ">>$testCodeunitRange" 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')) @@ -492,6 +518,7 @@ function Run-Tests { [int] $testPage = 130409, [string] $testSuite = "DEFAULT", [string] $testCodeunit = "*", + [string] $testCodeunitRange, [string] $testGroup = "*", [string] $testFunction = "*", [string] $extensionId = "", @@ -558,6 +585,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')) diff --git a/AppHandling/Run-TestsInNavContainer.ps1 b/AppHandling/Run-TestsInNavContainer.ps1 index c26eb27b4..3a840d340 100644 --- a/AppHandling/Run-TestsInNavContainer.ps1 +++ b/AppHandling/Run-TestsInNavContainer.ps1 @@ -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 @@ -330,6 +337,7 @@ try { -TestSuite $testSuite ` -TestGroup $testGroup ` -TestCodeunit $testCodeunit ` + -TestCodeunitRange $testCodeunitRange ` -TestFunction $testFunction ` -ExtensionId $extensionId ` -TestRunnerCodeunitId $testRunnerCodeunitId ` @@ -452,6 +460,7 @@ try { -TestSuite $testSuite ` -TestGroup $testGroup ` -TestCodeunit $testCodeunit ` + -TestCodeunitRange $testCodeunitRange ` -TestFunction $testFunction ` -ExtensionId $extensionId ` -TestRunnerCodeunitId $testRunnerCodeunitId `