private/TestName.tests.ps1.txt
Describe '%TESTSUITENAME%' {
# Load the JSON config files $testConfig = @() $dataPath = Join-Path -Path $PSScriptRoot -ChildPath "Data/*.json" Get-ChildItem -Path $dataPath | ForEach-Object { $configObject = Get-Content -Raw -Path $_.FullName | ConvertFrom-Json $ht = @{ TestCase = $_.Name.Split(".")[0] } $configObject.PSObject.Properties | ForEach-Object { $ht.Add($_.Name, $_.Value) } $configPath = Join-Path -Path $PSScriptRoot -ChildPath "../../Config/config.json" $HRAppConfig = Get-Content -Raw -Path $configPath | ConvertFrom-Json $ht.Add("SynchronizationTemplateId", $HRAppConfig.SynchronizationTemplateId) $ht.Add("HRApplicationDisplayName", $HRAppConfig.HRApplicationDisplayName) $ht.Add("ServicePrincipalId", $HRAppConfig.ServicePrincipalId) $ht.Add("TestSuiteName", $HRAppConfig.TestSuiteName) $testConfig += $ht } # For each test structure: test Parsing, Evaluation and Expected result It "HR.<TestSuiteName>.<TargetAttributeName>.<TestCase>: '<Description>'" -Tag HR,"%TESTSUITENAME%.%TESTNAME%" -ForEach $testConfig { $propertiesHT = @() foreach ($attr in $InputAttributes.PSObject.Properties) { $propertiesHT += @{ key = $attr.Name; value = $attr.Value } } $params = @{ expression = $Expression targetAttributeDefinition = $null testInputObject = @{ definition = $null properties = $propertiesHT } } $retval = Invoke-MgParseServicePrincipalSynchronizationTemplateSchemaExpression -ServicePrincipalId $ServicePrincipalId -BodyParameter $params -SynchronizationTemplateId $SynchronizationTemplateId # Maester integration check if (Get-Module Maester -ListAvailable) { $success = $retval.ParsingSucceeded -and $retval.EvaluationSucceeded -and ($retval.EvaluationResult -eq $ExpectedResult) $testResult = "" if ($success) { $testResult = @" Parsing and evaluation succeed. Evaluated result matched expected result. Expression: ~~~ $Expression ~~~ InputParams: ~~~json $((($InputAttributes.PSObject.Properties | ForEach-Object { $_ | Select-Object -Property @{n='attribute';e={$_.Name}},@{n='value';e={$_.Value}} }) | Format-Table -AutoSize | Out-String).Trim()) ~~~ ExpectedResult: ~~~ $ExpectedResult ~~~ "@ } if (-not $retval.ParsingSucceeded) { $testResult += @" Parsing of the expression failed. Expression: ~~~ $Expression ~~~ Error: ~~~json $($retval.error | ConvertTo-Json) ~~~ "@ } if (-not $retval.EvaluationSucceeded) { $testResult += @" Expression: ~~~ $Expression ~~~ InputParams: ~~~json $((($InputAttributes.PSObject.Properties | ForEach-Object { $_ | Select-Object -Property @{n='attribute';e={$_.Name}},@{n='value';e={$_.Value}} }) | Format-Table -AutoSize | Out-String).Trim()) ~~~ Error: ~~~json $($retval.Error | ConvertTo-Json) ~~~ "@ } if (($retval.ParsingSucceeded -and $retval.EvaluationSucceeded -and ($retval.EvaluationResult -ne $ExpectedResult))) { $testResult += @" Evaluated did not match expected result. Expression: ~~~ $Expression ~~~ InputParams: ~~~json $((($InputAttributes.PSObject.Properties | ForEach-Object { $_ | Select-Object -Property @{n='attribute';e={$_.Name}},@{n='value';e={$_.Value}} }) | Format-Table -AutoSize | Out-String).Trim()) ~~~ ExpectedResult: ~~~ $ExpectedResult ~~~ EvaluationResult: ~~~ $($retval.EvaluationResult) ~~~ "@ } if ([string]::IsNullOrEmpty($testResult)) { $testResult += @" Evaluated did not match expected result. Expression: ~~~ $Expression ~~~ InputParams: ~~~json $((($InputAttributes.PSObject.Properties | ForEach-Object { $_ | Select-Object -Property @{n='attribute';e={$_.Name}},@{n='value';e={$_.Value}} }) | Format-Table -AutoSize | Out-String).Trim()) ~~~ ExpectedResult: ~~~ $ExpectedResult ~~~ EvaluationResult: ~~~ $($retval.EvaluationResult) ~~~ "@ } Add-MtTestResultDetail -Result $testResult -Description "$Description" } $retval.ParsingSucceeded | Should -BeTrue -Because "PARSING must succeed to determine EvaluationResult." -ErrorAction "Continue" $retval.EvaluationSucceeded | Should -BeTrue -Because "EVALUATION must succeed to determine EvaluationResult." -ErrorAction "Continue" if ($retval.ParsingSucceeded -and $retval.EvaluationSucceeded) { $retval.EvaluationResult | Should -Be $ExpectedResult -ErrorAction "Continue" } } } |