Skip to content

Commit

Permalink
Fixed Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikCharlebois committed Sep 19, 2024
1 parent 232aee0 commit 84e8d2b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
8 changes: 8 additions & 0 deletions Modules/Microsoft365DSC/Modules/M365DSCReport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,14 @@ function Get-M365DSCCIMInstanceKey
{
$primaryKey = 'Dmn'
}
elseif ($CIMInstance.ContainsKey('EmergencyDialString'))
{
$primaryKey = 'EmergencyDialString'
}
else
{
$primaryKey = $CIMInstance.Keys[0]
}

return $primaryKey
}
Expand Down
45 changes: 33 additions & 12 deletions Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,24 @@ function Compare-PSCustomObjectArrays

foreach ($currentEntry in $currentValues)
{
$KeyProperty = Get-M365DSCCIMInstanceKey -CIMInstance $currentEntry
if ($currentEntry.GetType().Name -eq 'PSCustomObject')
{
$fixedEntry = @{}
$currentEntry.psobject.properties | Foreach { $fixedEntry[$_.Name] = $_.Value }
}
else
{
$fixedEntry = $currentEntry
}
$KeyProperty = Get-M365DSCCIMInstanceKey -CIMInstance $fixedEntry

$EquivalentEntryInDesired = $DesiredValues | Where-Object -FilterScript { $_.$KeyProperty -eq $currentEntry.$KeyProperty }
$EquivalentEntryInDesired = $DesiredValues | Where-Object -FilterScript { $_.$KeyProperty -eq $fixedEntry.$KeyProperty }
if ($null -eq $EquivalentEntryInDesired)
{
$result = @{
Property = $currentEntry
Property = $fixedEntry
PropertyName = $KeyProperty
Desired = $currentEntry.$KeyProperty
Desired = $fixedEntry.$KeyProperty
Current = $null
}
$DriftedProperties += $result
Expand All @@ -517,23 +526,23 @@ function Compare-PSCustomObjectArrays
{
$propertyName = $property.Name

if ((-not [System.String]::IsNullOrEmpty($currentEntry.$PropertyName) -and -not [System.String]::IsNullOrEmpty($EquivalentEntryInDesired.$PropertyName)) -and `
$currentEntry.$PropertyName -ne $EquivalentEntryInDesired.$PropertyName)
if ((-not [System.String]::IsNullOrEmpty($fixedEntry.$PropertyName) -and -not [System.String]::IsNullOrEmpty($EquivalentEntryInDesired.$PropertyName)) -and `
$fixedEntry.$PropertyName -ne $EquivalentEntryInDesired.$PropertyName)
{
$drift = $true
if ($currentEntry.$PropertyName.GetType().Name -eq 'String' -and $currentEntry.$PropertyName.Contains('$OrganizationName'))
if ($fixedEntry.$PropertyName.GetType().Name -eq 'String' -and $fixedEntry.$PropertyName.Contains('$OrganizationName'))
{
if ($currentEntry.$PropertyName.Split('@')[0] -eq $EquivalentEntryInDesired.$PropertyName.Split('@')[0])
if ($fixedEntry.$PropertyName.Split('@')[0] -eq $EquivalentEntryInDesired.$PropertyName.Split('@')[0])
{
$drift = $false
}
}
if ($drift)
{
$result = @{
Property = $currentEntry
Property = $fixedEntry
PropertyName = $PropertyName
Desired = $currentEntry.$PropertyName
Desired = $fixedEntry.$PropertyName
Current = $EquivalentEntryInDesired.$PropertyName
}
$DriftedProperties += $result
Expand Down Expand Up @@ -747,8 +756,20 @@ function Test-M365DSCParameterState
}
$AllDesiredValuesAsArray += [PSCustomObject]$currentEntry
}
$arrayCompare = Compare-PSCustomObjectArrays -CurrentValues $CurrentValues.$fieldName `
-DesiredValues $AllDesiredValuesAsArray
try
{
$arrayCompare = $null
if ($CurrentValues.$fieldName.GetType().Name -ne 'CimInstance' -and `
$CurrentValues.$fieldName.GetType().Name -ne 'CimInstance[]')
{
$arrayCompare = Compare-PSCustomObjectArrays -CurrentValues $CurrentValues.$fieldName `
-DesiredValues $AllDesiredValuesAsArray
}
}
catch
{
Write-Verbose -Message $_
}

if ($null -ne $arrayCompare)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
Mock -CommandName Get-PnPUserProfileProperty -MockWith {
return @{
AccountName = 'john.smith@contoso.com'
UserProfileProperties = @{'MyOldKey' = 'MyValue' }
UserProfileProperties = @(
@{
MyOldKey = 'MyValue'
}
)
}
}
}
Expand Down

0 comments on commit 84e8d2b

Please sign in to comment.