-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running unit tests in Business Central Online Sandbox environments #3754
Comments
Please remember to format your question like I have done. I assume that this is the problem: Is your clientId registered inside Business Central? |
Hi Freddty, Thanks for the reply. Sorry, but I'm not sure what you mean by "Please remember to format your question like I have done." The clientId is registered within my BC SAAS Sandbox as a Microsoft Entra Application The ClientId and Secret are registered in the Azure portal using App registrations with API permissions I can call l for example a list of installed extension using:
or publish app and test app, for example:
I presume this is the correct $clientId ? If I do not set $bcAuthContext.upn to a value I get this error message when starting Run-TestsInBCContainer: Here $bcAuthContext.upn is empty, -> New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "userName" is not valid. Change the value of the "userName" argument and run the operation again." |
Hi, Thanks I just found out howto format ;-) For environmentName I use the name of my sandbox (actually launch.json/environmentName, |
I am pretty sure that the upn trick is the problem here - you are setting the upn to an account, which doesn't match the access token you retrieve from the authentication. You could try to set the upn to $authContext.appId to see whether that works. |
I assume you mean $bcAuthContext.upn = $bcAuthContext.appId Connecting to https://msweuweuas4260-z26hbip.appservices.weu.businesscentral.dynamics.com/cs?tenant=msweua5608t88481773&tid Another question: if the scripts I presented are correct, do I have to set this field to a value manually? |
Freddy, I think I found that this does not work: $bcAuthContext = New-BcAuthContext -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
$UserName = $ClientId
$SecurePassword = ConvertTo-SecureString $ClientSecret -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($UserName, $SecurePassword)
Run-TestsInBCContainer `
-containerName $containerName `
-bcAuthContext $bcAuthContext `
-environment $environmentName `
-credential $credential `
-detailed `
-testSuite $TestSuiteName `
-testCodeunitRange '*' `
-AzureDevOps "error"
While this does seem to work: $UserName = "[email protected]"
$SecurePassword = ConvertTo-SecureString "MySandBoxPwd" -AsPlainText -Force
# Credential for running tests
$credential = New-Object System.Management.Automation.PSCredential ($UserName, $SecurePassword)
$bcauthContext = New-BcAuthContext -includeDeviceLogin // login with xyz@test.com, password MySandBoxPwd
Run-TestsInBCContainer `
-containerName $containerName `
-bcAuthContext $bcAuthContext `
-environment $environmentName `
-credential $credential `
-detailed `
-testSuite $TestSuiteName `
-testCodeunitRange '*' `
-AzureDevOps "error" So is my conclusion correct that $bcAuthContext and $credential must have the same SAAS Sandbox username/password? Also: Is the way I create the container (using AAD credentials) correct ? # List available artifact URLs
$artifactUrl = Get-BcArtifactUrl -type Sandbox -country "NL" -version "24.5.23489.23968" -select Closest
# Define the authentication method and service principal details
$auth = "AAD" # Use AAD for Azure Active Directory Authentication
$aadTenantId = "$TenantId"
$clientId = "$ClientId"
$clientSecret = "$ClientSecret"
$adminEmail = "[email protected]" # The Azure AD email for the admin user
New-BcContainer `
-accept_eula `
-containerName $ContainerName `
-artifactUrl $artifactUrl `
-auth $auth `
-filesOnly `
-updateHosts `
-authenticationEMail $adminEmail `
-additionalParameters @(
"--env AAD_TENANT_ID=$aadTenantId",
"--env AAD_CLIENT_ID=$clientId",
"--env AAD_CLIENT_SECRET=$clientSecret",
"--env AuthenticationEMail=$adminEmail"
) |
You don't really need the container when running towards an online sandbox. |
So you don't need a files only container at all ? If I try this: Run-TestsInBCContainer `
-bcAuthContext $bcAuthContext `
-environment $environmentName `
-credential $credential `
-detailed `
-testSuite $TestSuiteName `
-testCodeunitRange '*' `
-AzureDevOps "error" I get:
that looks like it is searching for a containerName ? Like when importing the test toolkit, a proxy container is needed to run the tests. A FilesOnly container will do. Output of the function should be something like: |
I think that has been fixed - update BcContainerHelper to the latest version and retry... Here are the things that has been fixed since 6.0.18:
|
Ok tried it, but What value do I give for -compilerFolder? if ($containerName) {
Write-Host "Using Container"
$customConfig = Get-BcContainerServerConfiguration -ContainerName $containerName
$navversion = Get-BcContainerNavversion -containerOrImageName $containerName
$version = [System.Version]($navversion.split('-')[0])
$PsTestToolFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\PsTestTool"
}
elseif ($compilerFolder) {
Write-Host "Using CompilerFolder"
$customConfig = $null
$symbolsFolder = Join-Path $compilerFolder "symbols" BcContainerHelper version 6.0.28 |
I'm trying to run unit tests from a Sandbox environment using BCHelper scripts / Run-TestsInBCContainer in
my DevOps pipeline.
I have a Sandbox in which I am able to publish my App and the correspronding TestApp.
The Sandbox contains the TestRunner and Test libraries. In the Sandbox I can run the unit tests manually.
Also I can make a connection with Sandbox with right BcAuthContext (ClientId and ClientSecret) and publish
the App and the corresponding TestApp (containing the unit tests)
I want to run all the unit tests using a powershell script that is called by DevOps pipeline
I have read https://community.dynamics.com/blogs/post/?postid=56456fac-3563-4d98-9e35-5d61c33e1457
Scripts used to create container and cause the issue
Full output of scripts
The text was updated successfully, but these errors were encountered: