functions/_GetDotNetTestParamsForVsTest.ps1

# <copyright file="_GetDotNetTestParamsForVsTest.ps1" company="Endjin Limited">
# Copyright (c) Endjin Limited. All rights reserved.
# </copyright>

<#
    .SYNOPSIS
    Generates the command-line arguments required for using 'dotnet test' with VSTest.
 
    .DESCRIPTION
    Generates the command-line arguments required for using 'dotnet test' with VSTest.
    Directly consumes script-scoped variables expected to be available via the 'RunTestsWithDotNetCoverage'
    InvokeBuild task ($script:SolutionToBuild, $script:DotNetTestLoggers, $script:DotNetTestResultsDir,
    $script:_fileLoggerProps).
 
    When $script:DotNetTestResultsDir is set, '--results-directory' is emitted so all test projects write
    their results there; when it is empty, no '--results-directory' is passed and each project uses its own
    'TestResults' folder (the VSTest default). The 'trx' logger's 'LogFilePrefix' already yields a distinct
    filename per project, so no filename translation is required here.
 
    .EXAMPLE
    $testParams = _GetDotNetTestParamsForVsTest
#>

function _GetDotNetTestParamsForVsTest {
    [CmdletBinding()]
    param ()

    $dotnetTestArgs = @(
        $script:SolutionToBuild
    )

    $script:DotNetTestLoggers |
        Where-Object { $_ } |
        ForEach-Object {
            $dotnetTestArgs += @("--logger", $_)
        }

    # Derive the path to the bundled logger assemblies
    $moduleDir = Split-Path -Parent (Split-Path -Parent $PSCommandPath)
    $binDir = Join-Path $moduleDir "bin"
    Write-Verbose "LoggersBinDir: $binDir" -Verbose

    $dotnetTestArgs += "--test-adapter-path", $binDir

    if ($script:DotNetTestResultsDir) {
        $dotnetTestArgs += "--results-directory", $script:DotNetTestResultsDir
    }

    $dotnetTestArgs += ($script:_fileLoggerProps ? $script:_fileLoggerProps : "/fl")

    return $dotnetTestArgs
}