From 758a28b5ffff6874c0a65b8bc039c99412d04cd1 Mon Sep 17 00:00:00 2001 From: Fabien Tschanz Date: Wed, 9 Oct 2024 17:26:07 +0200 Subject: [PATCH] Fix test cases --- .../MSFT_IntuneMobileAppsMacOSLobApp.psm1 | 16 ++++--- ...5DSC.IntuneMobileAppsMacOSLobApp.Tests.ps1 | 43 ++++++++++++++++++- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneMobileAppsMacOSLobApp/MSFT_IntuneMobileAppsMacOSLobApp.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneMobileAppsMacOSLobApp/MSFT_IntuneMobileAppsMacOSLobApp.psm1 index c6699b0e1b..f0e7cd245e 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneMobileAppsMacOSLobApp/MSFT_IntuneMobileAppsMacOSLobApp.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_IntuneMobileAppsMacOSLobApp/MSFT_IntuneMobileAppsMacOSLobApp.psm1 @@ -165,6 +165,7 @@ function Get-TargetResource $instance = Get-MgBetaDeviceAppManagementMobileApp -MobileAppId $instance.Id ` -ExpandProperty "categories" ` -ErrorAction SilentlyContinue + $Id = $instance.Id } } @@ -204,10 +205,13 @@ function Get-TargetResource } $complexMinimumSupportedOperatingSystem = @{} - $instance.AdditionalProperties.minimumSupportedOperatingSystem.GetEnumerator() | Foreach-Object { - if ($_.Value) # Values are either true or false. Only export the true value. - { - $complexMinimumSupportedOperatingSystem.Add($_.Key, $_.Value) + if ($null -ne $instance.AdditionalProperties.minimumSupportedOperatingSystem) + { + $instance.AdditionalProperties.minimumSupportedOperatingSystem.GetEnumerator() | Foreach-Object { + if ($_.Value) # Values are either true or false. Only export the true value. + { + $complexMinimumSupportedOperatingSystem.Add($_.Key, $_.Value) + } } } @@ -480,7 +484,9 @@ function Set-TargetResource $UpdateParameters.Add('@odata.type', '#microsoft.graph.macOSLobApp') Update-MgBetaDeviceAppManagementMobileApp -MobileAppId $currentInstance.Id -BodyParameter $UpdateParameters - $delta = Compare-Object -ReferenceObject $currentInstance.Categories.DisplayName -DifferenceObject $Categories.DisplayName -PassThru + [array]$referenceObject = if ($null -ne $currentInstance.Categories.DisplayName) { $currentInstance.Categories.DisplayName } else { ,@() } + [array]$differenceObject = if ($null -ne $Categories.DisplayName) { $Categories.DisplayName } else { ,@() } + $delta = Compare-Object -ReferenceObject $referenceObject -DifferenceObject $differenceObject -PassThru foreach ($diff in $delta) { if ($diff.SideIndicator -eq '=>') diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneMobileAppsMacOSLobApp.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneMobileAppsMacOSLobApp.Tests.ps1 index 45eea18922..abfda47b65 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneMobileAppsMacOSLobApp.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneMobileAppsMacOSLobApp.Tests.ps1 @@ -31,6 +31,12 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Confirm-M365DSCDependencies -MockWith { } + Mock -CommandName Get-PSSession -MockWith { + } + + Mock -CommandName Remove-PSSession -MockWith { + } + Mock -CommandName New-M365DSCConnection -MockWith { return "Credentials" } @@ -59,11 +65,16 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { BeforeAll { $testParams = @{ Id = "8d027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller" InformationUrl = "" IsFeatured = $False + MinimumSupportedOperatingSystem = [CimInstance]( + New-CimInstance -ClassName MSFT_DeviceManagementMinimumOperatingSystem -Property @{ + v11_0 = $true + } -ClientOnly) Notes = "" Owner = "" PrivacyInformationUrl = "" @@ -94,18 +105,22 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { BeforeAll { $testParams = @{ Id = "ad027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller" InformationUrl = "" IsFeatured = $False + MinimumSupportedOperatingSystem = [CimInstance]( + New-CimInstance -ClassName MSFT_DeviceManagementMinimumOperatingSystem -Property @{ + v11_0 = $true + } -ClientOnly) Notes = "" Owner = "" PrivacyInformationUrl = "" Publisher = "Contoso" RoleScopeTagIds = @() IgnoreVersionDetection = $True - Ensure = 'Absent' Credential = $Credential } @@ -113,6 +128,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { return @{ Id = "ad027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller" @@ -127,6 +143,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { IgnoreVersionDetection = $True AdditionalProperties = @{ '@odata.type' = '#microsoft.graph.macOSLobApp' + minimumSupportedOperatingSystem = @{ + v11_0 = $true + } } Ensure = 'Present' } @@ -153,11 +172,16 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { BeforeAll { $testParams = @{ Id = "8d027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller" InformationUrl = "" IsFeatured = $False + MinimumSupportedOperatingSystem = [CimInstance]( + New-CimInstance -ClassName MSFT_DeviceManagementMinimumOperatingSystem -Property @{ + v11_0 = $true + } -ClientOnly) Notes = "" Owner = "" PrivacyInformationUrl = "" @@ -170,6 +194,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { return @{ Id = "8d027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller" @@ -183,6 +208,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { RoleScopeTagIds = @() AdditionalProperties = @{ '@odata.type' = '#microsoft.graph.macOSLobApp' + minimumSupportedOperatingSystem = @{ + v11_0 = $true + } } } } @@ -200,11 +228,16 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { BeforeAll { $testParams = @{ Id = "8d027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller" InformationUrl = "" IsFeatured = $False + MinimumSupportedOperatingSystem = [CimInstance]( + New-CimInstance -ClassName MSFT_DeviceManagementMinimumOperatingSystem -Property @{ + v11_0 = $true + } -ClientOnly) Notes = "" Owner = "" PrivacyInformationUrl = "" @@ -217,6 +250,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { return @{ Id = "8d027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller drift" @@ -229,6 +263,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { PublishingState = "published" AdditionalProperties = @{ '@odata.type' = '#microsoft.graph.macOSLobApp' + minimumSupportedOperatingSystem = @{ + v11_0 = $true + } } } } @@ -260,6 +297,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { Mock -CommandName Get-MgBetaDeviceAppManagementMobileApp -MockWith { return @{ Id = "8d027f94-0682-431e-97c1-827d1879fa79" + Categories = @() Description = "TeamsForBusinessInstaller" Developer = "Contoso" DisplayName = "TeamsForBusinessInstaller drift" @@ -273,6 +311,9 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture { RoleScopeTagIds = @() AdditionalProperties = @{ '@odata.type' = '#microsoft.graph.macOSLobApp' + minimumSupportedOperatingSystem = @{ + v11_0 = $true + } } } }