private/TestName.tests.ps1.txt
Describe '%TESTSUITENAME%' {
# load the json config files $testConfig=@() ls "$PSScriptRoot\Data\*.json" | foreach { $configObject = Get-Content -Raw $_.FullName | ConvertFrom-Json $ht=@{} $ht.Add("TestCase",$_.Name.Split(".")[0]) $configObject.psobject.properties | foreach {$ht.Add($_.Name,$_.Value)} $HRAppConfig=ls "$PSScriptRoot\..\..\Config\Config.json" | get-content -raw | 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>: When: '<Description>', it returns: '<ExpectedResult>'" -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 # TODO refactor the test for Maester integration # Add GraphObjects and GraphObjectType # And improve the testResult generation logic, make it a little more readable if (Get-Module Maester -ListAvailable) { $success = $retval.ParsingSucceeded -and $retval.EvaluationSucceeded -and ($retval.EvaluationResult -eq $ExpectedResult) $testResult="" if ($success) { $testResult="Parsing and evaulation succeed. Evaluated result matched expected result: '$ExpectedResult'" } if (-not $retval.ParsingSucceeded) { $testResult+=@" Parsing of the expression failed. > $Expression > Retval: ~~~json $($retval | ConvertTo-json) ~~~ "@ } if (-not $retval.EvaluationSucceeded) { $testResult+=@" Evaluation of the expression failed. > $Expression > Retval: ~~~json $($retval | ConvertTo-json) ~~~ "@ } if (($retval.ParsingSucceeded -and $retval.EvaluationSucceeded -and ($retval.EvaluationResult -ne $ExpectedResult))) { $testResult+="Evaluated did not matched expected result: '$ExpectedResult'. Evaluated value was: $($retval.EvaluationResult)" } if ([string]::IsNullOrEmpty($testResult)) { $testResult="Evaluated did not matched expected result: '$ExpectedResult'. Evaluated value was: $($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" } } } |