Containers/Import-Testing.ps1
<#
.Synopsis Imports test functions into the container .Description Imports the standard test functions into the container .Parameter ContainerName Name of the container. Can be provided in the settings.json .Parameter Credential Based on the version of BC/NAV, it will contain the credentials or the SQL credentials .Parameter includeTestLibrariesOnly Add the switch if you want to only include the test libraries and not the standard tests .Example Import-Testing #> function Import-Testing { Param( [Parameter(Mandatory=$false)] [string] $ContainerName, [Parameter(Mandatory=$false)] [pscredential] $Credential, [Parameter(Mandatory=$false)] [switch] $includeLibrariesOnly ) if ($null -eq $ContainerName -or $ContainerName -eq "") { $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name') } if ($null -eq $Credential) { $NewCredential = Get-CredentialFromEnvironmentJson if ($NewCredential -eq $false) { $Password = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000f2d5880bd296784999333fc74a891a790000000002000000000003660000c0000000100000002dae255385f71a81ca6e8d5c2392e5490000000004800000a000000010000000c15ad9c418f9627a05e21ffb6eb1e50718000000560ac5bfcf7dde12fb6163ada5d091e2b95ed310e51b2a6e140000007748a4b148b1dc44363831d82c6671abeb9316b9" | ConvertTo-SecureString $Credential = [PSCredential]::new('admin', $Password) } else { $Credential = $NewCredential $Password = ((Get-EnvironmentKeyValue -KeyName "password") | ConvertTo-SecureString) } } else { $Password = $Credential.Password } [version]$platform = Get-AppKeyValue -KeyName 'platform' if ($platform.Major -eq 11) { Disable-SymbolLoading -ContainerName $ContainerName Start-Sleep -Seconds 5 } $startParameters = @{} if ($platform.Major -le 14) { $startParameters.Add('sqlCredential', [PSCredential]::new('sa', $Password)) } else { $startParameters.Add('credential', $Credential) $startParameters.Add('doNotUseRuntimePackages', $true) } if ($platform.Major -eq 11) { $startParameters.Add('doNotUpdateSymbols', $true) } if ($includeLibrariesOnly.IsPresent) { $startParameters.Add('includeTestLibrariesOnly', $true) } else { $startParameters.Add('includeTestLibrariesOnly', $false) } $locale = Get-EnvironmentKeyValue -KeyName "locale" if ($locale -ne "") { if ($locale -eq 'na') { $locale = 'US' } $startParameters.Add('testToolkitCountry', $locale) } Import-TestToolkitToNavContainer -containerName $ContainerName -ImportAction Overwrite @startParameters if ($platform.Major -le 11) { Write-Output "Synchronizing Objects" $session = Get-NavContainerSession -containerName $ContainerName Invoke-Command -ScriptBlock { Sync-NAVTenant -Mode ForceSync -ServerInstance NAV -CommitPerTable -Force } -Session $session Remove-NavContainerSession -containerName $ContainerName } if ($platform.Major -eq 11) { Enable-SymbolLoading -ContainerName $ContainerName Start-Sleep -Seconds 500 Compile-ObjectsInNavContainer -containerName $ContainerName -filter "version list=*Test*" -sqlCredential ([PSCredential]::new('sa', $Password)) -SynchronizeSchemaChanges Force Start-Sleep -Seconds 500 } } Export-ModuleMember Import-Testing |