Private/Convert-TestResult.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# Emit an object which can be used in reporting
Function Convert-TestResult {
    param (
        [Parameter(Mandatory)]
        $result,

        [string]$ModuleName
    )

    foreach ($testResult in $result.TestResult) {
        $testError = $null
        if ($testResult.Result -eq 'Failed') {
            Write-Verbose -message 'Creating error object'
            $testError = New-OperationValidationFailure -Stacktrace $testResult.StackTrace -FailureMessage $testResult.FailureMessage
        }

        $TestName = '{0}:{1}:{2}' -f $testResult.Describe, $testResult.Context, $testResult.Name

        $newOVResultParams = @{
            Name      = $TestName
            FileName  = $result.path
            Result    = $testresult.result
            RawResult = $testResult
            Error     = $TestError
        }
        if (-not [string]::IsNullOrEmpty($ModuleName)) {
            $newOVResultParams.Module = $ModuleName
        }
        New-OperationValidationResult @newOVResultParams
    }
}