diff --git a/test/module/Entra/Common-Parameter.Tests.ps1 b/test/module/Entra/Common-Parameter.Tests.ps1 index 81bacce45..dc936f855 100644 --- a/test/module/Entra/Common-Parameter.Tests.ps1 +++ b/test/module/Entra/Common-Parameter.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ BeforeAll{ if($null -eq (Get-Module -Name Microsoft.Graph.Entra)){ Import-Module Microsoft.Graph.Entra diff --git a/test/module/Entra/Get-EntraCustomSecurityAttributeDefinition.Tests.ps1 b/test/module/Entra/Get-EntraCustomSecurityAttributeDefinition.Tests.ps1 index 90a2eb538..b856ec7c1 100644 --- a/test/module/Entra/Get-EntraCustomSecurityAttributeDefinition.Tests.ps1 +++ b/test/module/Entra/Get-EntraCustomSecurityAttributeDefinition.Tests.ps1 @@ -52,12 +52,26 @@ Describe "Get-EntraCustomSecurityAttributeDefinition" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraCustomSecurityAttributeDefinition" - - Get-EntraCustomSecurityAttributeDefinition -Id Engineering_Project | Out-Null + $result = Get-EntraCustomSecurityAttributeDefinition -Id 'Engineering_Project' + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraCustomSecurityAttributeDefinition" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraCustomSecurityAttributeDefinition -Id 'Engineering_Project' -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/Get-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 b/test/module/Entra/Get-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 index a8733f696..7ecdc8b5d 100644 --- a/test/module/Entra/Get-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 +++ b/test/module/Entra/Get-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 @@ -60,12 +60,26 @@ Describe "Get-EntraCustomSecurityAttributeDefinitionAllowedValue" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraCustomSecurityAttributeDefinitionAllowedValue" - - Get-EntraCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId 'Engineering_Project' | Out-Null + $result = Get-EntraCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId 'Engineering_Project' -Id 'Apline' + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraCustomSecurityAttributeDefinitionAllowedValue" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId 'Engineering_Project' -Id 'Apline' -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/Get-EntraFeatureRolloutPolicy.Tests.ps1 b/test/module/Entra/Get-EntraFeatureRolloutPolicy.Tests.ps1 index 3e32794a2..d5d69a1f1 100644 --- a/test/module/Entra/Get-EntraFeatureRolloutPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraFeatureRolloutPolicy.Tests.ps1 @@ -79,5 +79,18 @@ Describe "Get-EntraFeatureRolloutPolicy" { $true } } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraFeatureRolloutPolicy -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/Get-EntraObjectSetting.Tests.ps1 b/test/module/Entra/Get-EntraObjectSetting.Tests.ps1 index 7df610940..0d691f06f 100644 --- a/test/module/Entra/Get-EntraObjectSetting.Tests.ps1 +++ b/test/module/Entra/Get-EntraObjectSetting.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ BeforeAll { if ((Get-Module -Name Microsoft.Graph.Entra) -eq $null) { Import-Module Microsoft.Graph.Entra @@ -56,7 +59,9 @@ Describe "Get-EntraObjectSetting" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraObjectSetting" - Get-EntraObjectSetting -TargetType "Groups" -TargetObjectId "bbbbbbbb-1111-2222-3333-cccccccccccc" | Out-Null + $result = Get-EntraObjectSetting -TargetType "Groups" -TargetObjectId "bbbbbbbb-1111-2222-3333-cccccccccccc" + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraObjectSetting" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true diff --git a/test/module/Entra/Get-EntraPolicy.Tests.ps1 b/test/module/Entra/Get-EntraPolicy.Tests.ps1 index 336976479..f517c9e1e 100644 --- a/test/module/Entra/Get-EntraPolicy.Tests.ps1 +++ b/test/module/Entra/Get-EntraPolicy.Tests.ps1 @@ -84,13 +84,26 @@ Describe "Get-EntraPolicy" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraPolicy" - $result = Get-EntraPolicy -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraPolicy" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true - } + } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraPolicy -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 index be1b10fe7..569c885a7 100644 --- a/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignedTo.Tests.ps1 @@ -72,13 +72,27 @@ Describe "Get-EntraServicePrincipalAppRoleAssignedTo" { } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalAppRoleAssignedTo" - $result = Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalAppRoleAssignedTo" + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraServicePrincipalAppRoleAssignedTo -ObjectId "4d8fcb23-adc7-4d47-9328-2420eb1075ef" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 index c98ddabfb..b635bf71a 100644 --- a/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalAppRoleAssignment.Tests.ps1 @@ -73,13 +73,27 @@ Describe "Get-EntraServiceAppRoleAssigned" { } It "Should contain 'User-Agent' header" { - Mock -CommandName Get-MgServicePrincipalAppRoleAssignedTo -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalAppRoleAssignment" - $result = Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue - } + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraServicePrincipalAppRoleAssignment" + Should -Invoke -CommandName Get-MgServicePrincipalAppRoleAssignedTo -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraServicePrincipalAppRoleAssignment -ObjectId "021510b7-e753-40aa-b668-29753295ca34" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServicePrincipalKeyCredential.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalKeyCredential.Tests.ps1 index 5467edb61..5fb2b7aa0 100644 --- a/test/module/Entra/Get-EntraServicePrincipalKeyCredential.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalKeyCredential.Tests.ps1 @@ -68,6 +68,19 @@ Describe "Get-EntraServicePrincipalKeyCredential" { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraServicePrincipalKeyCredential -ObjectId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Get-EntraServicePrincipalPasswordCredential.Tests.ps1 b/test/module/Entra/Get-EntraServicePrincipalPasswordCredential.Tests.ps1 index e75179543..8a99ec828 100644 --- a/test/module/Entra/Get-EntraServicePrincipalPasswordCredential.Tests.ps1 +++ b/test/module/Entra/Get-EntraServicePrincipalPasswordCredential.Tests.ps1 @@ -71,5 +71,18 @@ Describe "Get-EntraServicePrincipalPasswordCredential" { $true } } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Get-EntraServicePrincipalPasswordCredential -ObjectId "00aa00aa-bb11-cc22-dd33-44ee44ee44ee" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/New-EntraCustomSecurityAttributeDefinition.Tests.ps1 b/test/module/Entra/New-EntraCustomSecurityAttributeDefinition.Tests.ps1 index 918929976..1a251f549 100644 --- a/test/module/Entra/New-EntraCustomSecurityAttributeDefinition.Tests.ps1 +++ b/test/module/Entra/New-EntraCustomSecurityAttributeDefinition.Tests.ps1 @@ -1,3 +1,6 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +# ------------------------------------------------------------------------------ BeforeAll { if ((Get-Module -Name Microsoft.Graph.Entra) -eq $null) { Import-Module Microsoft.Graph.Entra @@ -75,17 +78,16 @@ Describe "New-EntraCustomSecurityAttributeDefinition" { It "Should fail when usePreDefinedValuesOnly is invalid" { { New-EntraCustomSecurityAttributeDefinition -attributeSet "Engineering" -description "Active projects for user" -isCollection $true -isSearchable $true -name "Project1234" -status "Available" -type "String" -usePreDefinedValuesOnly "" } | Should -Throw "Cannot process argument transformation on parameter 'usePreDefinedValuesOnly'*" } - - It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraCustomSecurityAttributeDefinition" - - New-EntraCustomSecurityAttributeDefinition -attributeSet "Engineering" -description "Active projects for user" -isCollection $true -isSearchable $true -name "Project1234" -status "Available" -type "String" -usePreDefinedValuesOnly $true | Out-Null + $result = New-EntraCustomSecurityAttributeDefinition -attributeSet "Engineering" -description "Active projects for user" -isCollection $true -isSearchable $true -name "Project1234" -status "Available" -type "String" -usePreDefinedValuesOnly $true + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraCustomSecurityAttributeDefinition" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } It "Should execute successfully without throwing an error " { # Disable confirmation prompts $originalDebugPreference = $DebugPreference diff --git a/test/module/Entra/New-EntraFeatureRolloutPolicy.Tests.ps1 b/test/module/Entra/New-EntraFeatureRolloutPolicy.Tests.ps1 index e768319bd..6166f6361 100644 --- a/test/module/Entra/New-EntraFeatureRolloutPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraFeatureRolloutPolicy.Tests.ps1 @@ -60,12 +60,26 @@ Describe "New-EntraFeatureRolloutPolicy" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraFeatureRolloutPolicy" - - New-EntraFeatureRolloutPolicy -Feature 'PasswordHashSync' -DisplayName 'FeatureRolloutPolicy1' -Description 'FeatureRolloutPolicy1' -IsEnabled $false | Out-Null + $result = New-EntraFeatureRolloutPolicy -Feature 'PasswordHashSync' -DisplayName 'FeatureRolloutPolicy1' -Description 'FeatureRolloutPolicy1' -IsEnabled $false + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraFeatureRolloutPolicy" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { New-EntraFeatureRolloutPolicy -Feature 'PasswordHashSync' -DisplayName 'FeatureRolloutPolicy1' -Description 'FeatureRolloutPolicy1' -IsEnabled $false -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/New-EntraOauth2PermissionGrant.Tests.ps1 b/test/module/Entra/New-EntraOauth2PermissionGrant.Tests.ps1 index 856260fd6..d8027dca4 100644 --- a/test/module/Entra/New-EntraOauth2PermissionGrant.Tests.ps1 +++ b/test/module/Entra/New-EntraOauth2PermissionGrant.Tests.ps1 @@ -55,12 +55,26 @@ Describe "New-EntraOauth2PermissionGrant" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraOauth2PermissionGrant" - - New-EntraOauth2PermissionGrant -ClientId "bbbbbbbb-1111-2222-3333-cccccccccccc" -ConsentType "AllPrincipals" -ResourceId "bbbbbbbb-1111-2222-3333-rrrrrrrrrrrr" | Out-Null + $result = New-EntraOauth2PermissionGrant -ClientId "bbbbbbbb-1111-2222-3333-cccccccccccc" -ConsentType "AllPrincipals" -ResourceId "bbbbbbbb-1111-2222-3333-rrrrrrrrrrrr" -Scope "DelegatedPermissionGrant.ReadWrite.All" + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraOauth2PermissionGrant" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { New-EntraOauth2PermissionGrant -ClientId "bbbbbbbb-1111-2222-3333-cccccccccccc" -ConsentType "AllPrincipals" -ResourceId "bbbbbbbb-1111-2222-3333-rrrrrrrrrrrr" -Scope "DelegatedPermissionGrant.ReadWrite.All" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } } } } \ No newline at end of file diff --git a/test/module/Entra/New-EntraPolicy.Tests.ps1 b/test/module/Entra/New-EntraPolicy.Tests.ps1 index 35ea2f029..4a917c455 100644 --- a/test/module/Entra/New-EntraPolicy.Tests.ps1 +++ b/test/module/Entra/New-EntraPolicy.Tests.ps1 @@ -49,13 +49,26 @@ Describe "New-EntraPolicy" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraPolicy" - - New-EntraPolicy -Definition @('{ "definition": [ "{\"ClaimsMappingPolicy\":{\"Version\":1,\"IncludeBasicClaimSet\":\"true\",\"ClaimsSchema\":[{\"Source\":\"user\",\"ID\":\"userPrincipalName\",\"SAMLClaimType\":\"http://xyz.xmlsoap.org/ws/2005/05/pqr/claims/name\",\"JwtClaimType\":\"xyz\"},{\"Source\":\"user\",\"ID\":\"displayName\",\"SAMLClaimType\":\"http://xxx.yyy.com/identity/claims/displayname\",\"JwtClaimType\":\"ppp\"}]}}" ], "displayName": "test Claims Issuance Policy", "isOrganizationDefault": false }') -DisplayName "Claimstest" -Type "claimsMappingPolicies" -IsOrganizationDefault $false -AlternativeIdentifier "1f587daa-d6fc-433f-88ee-ccccccccc111" | Out-Null - + $result = New-EntraPolicy -Definition @('{ "definition": [ "{\"ClaimsMappingPolicy\":{\"Version\":1,\"IncludeBasicClaimSet\":\"true\",\"ClaimsSchema\":[{\"Source\":\"user\",\"ID\":\"userPrincipalName\",\"SAMLClaimType\":\"http://xyz.xmlsoap.org/ws/2005/05/pqr/claims/name\",\"JwtClaimType\":\"xyz\"},{\"Source\":\"user\",\"ID\":\"displayName\",\"SAMLClaimType\":\"http://xxx.yyy.com/identity/claims/displayname\",\"JwtClaimType\":\"ppp\"}]}}" ], "displayName": "test Claims Issuance Policy", "isOrganizationDefault": false }') -DisplayName "Claimstest" -Type "claimsMappingPolicies" -IsOrganizationDefault $false -AlternativeIdentifier "1f587daa-d6fc-433f-88ee-ccccccccc111" + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion New-EntraPolicy" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true - } - } + } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { New-EntraPolicy -Definition @('{ "definition": [ "{\"ClaimsMappingPolicy\":{\"Version\":1,\"IncludeBasicClaimSet\":\"true\",\"ClaimsSchema\":[{\"Source\":\"user\",\"ID\":\"userPrincipalName\",\"SAMLClaimType\":\"http://xyz.xmlsoap.org/ws/2005/05/pqr/claims/name\",\"JwtClaimType\":\"xyz\"},{\"Source\":\"user\",\"ID\":\"displayName\",\"SAMLClaimType\":\"http://xxx.yyy.com/identity/claims/displayname\",\"JwtClaimType\":\"ppp\"}]}}" ], "displayName": "test Claims Issuance Policy", "isOrganizationDefault": false }') -DisplayName "Claimstest" -Type "claimsMappingPolicies" -IsOrganizationDefault $false -AlternativeIdentifier "1f587daa-d6fc-433f-88ee-ccccccccc111" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/New-EntraServicePrincipalPasswordCredential.Tests.ps1 b/test/module/Entra/New-EntraServicePrincipalPasswordCredential.Tests.ps1 index 6808aa657..d0410dd5c 100644 --- a/test/module/Entra/New-EntraServicePrincipalPasswordCredential.Tests.ps1 +++ b/test/module/Entra/New-EntraServicePrincipalPasswordCredential.Tests.ps1 @@ -72,5 +72,18 @@ Describe "New-EntraServicePrincipalPasswordCredential"{ $true } } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { New-EntraServicePrincipalPasswordCredential -ObjectID "bbbbbbbb-1111-2222-3333-cccccccccccc" -StartDate "2024-09-16T14:14:14Z" -EndDate "2024-12-16T13:14:14Z" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraFeatureRolloutPolicy.Tests.ps1 b/test/module/Entra/Remove-EntraFeatureRolloutPolicy.Tests.ps1 index 852773965..83d7c9fae 100644 --- a/test/module/Entra/Remove-EntraFeatureRolloutPolicy.Tests.ps1 +++ b/test/module/Entra/Remove-EntraFeatureRolloutPolicy.Tests.ps1 @@ -27,12 +27,26 @@ Describe "Remove-EntraFeatureRolloutPolicy" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraFeatureRolloutPolicy" - - Remove-EntraFeatureRolloutPolicy -Id bbbbbbbb-1111-2222-3333-cccccccccccc | Out-Null + $result = Remove-EntraFeatureRolloutPolicy -Id bbbbbbbb-1111-2222-3333-cccccccccccc + $result | Should -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraFeatureRolloutPolicy" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Remove-EntraFeatureRolloutPolicy -Id bbbbbbbb-1111-2222-3333-cccccccccccc -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 b/test/module/Entra/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 index 4d7c6d9ec..6fd9ea2c4 100644 --- a/test/module/Entra/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 +++ b/test/module/Entra/Remove-EntraFeatureRolloutPolicyDirectoryObject.Tests.ps1 @@ -33,12 +33,26 @@ Describe "Remove-EntraFeatureRolloutPolicyDirectoryObject" { } It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraFeatureRolloutPolicyDirectoryObject" - - Remove-EntraFeatureRolloutPolicyDirectoryObject -Id bbbbbbbb-1111-2222-3333-cccccccccccc -ObjectId bbbbbbbb-1111-2222-3333-aaaaaaaaaaaa | Out-Null + $result = Remove-EntraFeatureRolloutPolicyDirectoryObject -Id bbbbbbbb-1111-2222-3333-cccccccccccc -ObjectId bbbbbbbb-1111-2222-3333-aaaaaaaaaaaa + $result | Should -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraFeatureRolloutPolicyDirectoryObject" Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } - } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Remove-EntraFeatureRolloutPolicyDirectoryObject -Id bbbbbbbb-1111-2222-3333-cccccccccccc -ObjectId bbbbbbbb-1111-2222-3333-aaaaaaaaaaaa -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/Remove-EntraPolicy.Tests.ps1 b/test/module/Entra/Remove-EntraPolicy.Tests.ps1 index 0944e1550..8d24936fa 100644 --- a/test/module/Entra/Remove-EntraPolicy.Tests.ps1 +++ b/test/module/Entra/Remove-EntraPolicy.Tests.ps1 @@ -35,5 +35,28 @@ Describe "Test for Remove-EntraPolicy" { It "Should fail when invalid parameter is passed" { { Remove-EntraPolicy -xyz } | Should -Throw "A parameter cannot be found that matches parameter name 'xyz'*" } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraPolicy" + $result = Remove-EntraPolicy -Id bbbbbbbb-1111-1111-1111-cccccccccccc + $result | Should -Not -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraPolicy" + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Remove-EntraPolicy -Id bbbbbbbb-1111-1111-1111-cccccccccccc -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } diff --git a/test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 b/test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 index 640044344..fb6c7a59d 100644 --- a/test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServicePrincipalAppRoleAssignment.Tests.ps1 @@ -38,12 +38,27 @@ Describe "Remove-EntraServicePrincipalAppRoleAssignment" { } It "Should contain 'User-Agent' header" { - Mock -CommandName Remove-MgServicePrincipalAppRoleAssignment -MockWith {$args} -ModuleName Microsoft.Graph.Entra - $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServicePrincipalAppRoleAssignment" - $result = Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" - $params = Get-Parameters -data $result - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + $result = Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" + $result | Should -BeNullOrEmpty + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Remove-EntraServicePrincipalAppRoleAssignment" + Should -Invoke -CommandName Remove-MgServicePrincipalAppRoleAssignment -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } } + It "Should execute successfully without throwing an error " { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Remove-EntraServicePrincipalAppRoleAssignment -ObjectId "cc7fcc82-ac1b-4785-af47-2ca3b7052886" -AppRoleAssignmentId "gsx_zBushUevRyyjtwUohm_RMYjcGsJIjXwKOVMr3ww" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Remove-EntraServicePrincipalPasswordCredential.Tests.ps1 b/test/module/Entra/Remove-EntraServicePrincipalPasswordCredential.Tests.ps1 index 58d7fd4ec..9a8017d64 100644 --- a/test/module/Entra/Remove-EntraServicePrincipalPasswordCredential.Tests.ps1 +++ b/test/module/Entra/Remove-EntraServicePrincipalPasswordCredential.Tests.ps1 @@ -49,5 +49,18 @@ Describe "Remove-EntraServicePrincipalPasswordCredential" { $true } } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Remove-EntraServicePrincipalPasswordCredential -ObjectID "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -KeyId "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } \ No newline at end of file diff --git a/test/module/Entra/Set-EntraAttributeSet.Tests.ps1 b/test/module/Entra/Set-EntraAttributeSet.Tests.ps1 index 49eb858d7..7f2376f68 100644 --- a/test/module/Entra/Set-EntraAttributeSet.Tests.ps1 +++ b/test/module/Entra/Set-EntraAttributeSet.Tests.ps1 @@ -34,11 +34,28 @@ Describe "Set-EntraAttributeSet" { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraAttributeSet" - Set-EntraAttributeSet -Id "NewCustomAttributeSet" -Description "CustomAttributeSet" -MaxAttributesPerSet 125 | Out-Null + $result = Set-EntraAttributeSet -Id "NewCustomAttributeSet" -Description "CustomAttributeSet" -MaxAttributesPerSet 125 + $result | Should -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraAttributeSet" + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } + } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Set-EntraAttributeSet -Id "NewCustomAttributeSet" -Description "CustomAttributeSet" -MaxAttributesPerSet 125 -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } } } } \ No newline at end of file diff --git a/test/module/Entra/Set-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 b/test/module/Entra/Set-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 index 507bd8c94..15d45787b 100644 --- a/test/module/Entra/Set-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 +++ b/test/module/Entra/Set-EntraCustomSecurityAttributeDefinitionAllowedValue.Tests.ps1 @@ -37,12 +37,17 @@ Describe "Test for Set-EntraCustomSecurityAttributeDefinitionAllowedValue" { } It "Should contain 'User-Agent' header" { - Mock -CommandName Invoke-GraphRequest -MockWith {$args} -ModuleName Microsoft.Graph.Entra $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraCustomSecurityAttributeDefinitionAllowedValue" + $result = Set-EntraCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId "Engineering_Project" -Id "Alpine" -IsActive $true - $params = Get-Parameters -data $result - $a= $params | ConvertTo-json | ConvertFrom-Json - $a.headers.'User-Agent' | Should -Be $userAgentHeaderValue + $result | Should -BeNullOrEmpty + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraCustomSecurityAttributeDefinitionAllowedValue" + + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } } It "Should execute successfully without throwing an error " { # Disable confirmation prompts diff --git a/test/module/Entra/Set-EntraFeatureRolloutPolicy.Tests.ps1 b/test/module/Entra/Set-EntraFeatureRolloutPolicy.Tests.ps1 index 90550ee95..4b4227ba8 100644 --- a/test/module/Entra/Set-EntraFeatureRolloutPolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraFeatureRolloutPolicy.Tests.ps1 @@ -43,11 +43,27 @@ Describe "Set-EntraFeatureRolloutPolicy" { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraFeatureRolloutPolicy" - Set-EntraFeatureRolloutPolicy -Id 7e22e9df-abf0-4ee2-bcf8-fd7b62eff2f5 -DisplayName 'Feature-Rollout-Policytest' -Description 'Feature-Rollout-test' -IsEnabled $false | Out-Null + Set-EntraFeatureRolloutPolicy -Id 7e22e9df-abf0-4ee2-bcf8-fd7b62eff2f5 -DisplayName 'Feature-Rollout-Policytest' -Description 'Feature-Rollout-test' -IsEnabled $false + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraFeatureRolloutPolicy" + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { $Headers.'User-Agent' | Should -Be $userAgentHeaderValue $true } + } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Set-EntraFeatureRolloutPolicy -Id 7e22e9df-abf0-4ee2-bcf8-fd7b62eff2f5 -DisplayName 'Feature-Rollout-Policytest' -Description 'Feature-Rollout-test' -IsEnabled $false -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } } } } diff --git a/test/module/Entra/Set-EntraPartnerInformation.Tests.ps1 b/test/module/Entra/Set-EntraPartnerInformation.Tests.ps1 index dbb898fd0..bec424fa8 100644 --- a/test/module/Entra/Set-EntraPartnerInformation.Tests.ps1 +++ b/test/module/Entra/Set-EntraPartnerInformation.Tests.ps1 @@ -62,10 +62,27 @@ Describe "Set-EntraPartnerInformation" { It "Should contain 'User-Agent' header" { $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPartnerInformation" - $result = Set-EntraPartnerInformation -PartnerSupportUrl "http://www.test1.com" - - $params = Get-Parameters -data $result.value.Parameters - $params.Headers["User-Agent"] | Should -Be $userAgentHeaderValue + Set-EntraPartnerInformation -PartnerSupportUrl "http://www.test1.com" -PartnerCommerceUrl "http://www.test1.com" -PartnerHelpUrl "http://www.test1.com" -PartnerSupportEmails "contoso@example.com" -PartnerSupportTelephones "2342" -TenantId b73cc049-a025-4441-ba3a-8826d9a68ecc + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPartnerInformation" + + Should -Invoke -CommandName Invoke-MgGraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Set-EntraPartnerInformation -PartnerSupportUrl "http://www.test1.com" -PartnerCommerceUrl "http://www.test1.com" -PartnerHelpUrl "http://www.test1.com" -PartnerSupportEmails "contoso@example.com" -PartnerSupportTelephones "2342" -TenantId b73cc049-a025-4441-ba3a-8826d9a68ecc -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } + } } } diff --git a/test/module/Entra/Set-EntraPolicy.Tests.ps1 b/test/module/Entra/Set-EntraPolicy.Tests.ps1 index 93ed200ac..e12da4f47 100644 --- a/test/module/Entra/Set-EntraPolicy.Tests.ps1 +++ b/test/module/Entra/Set-EntraPolicy.Tests.ps1 @@ -45,14 +45,42 @@ Describe "Test for Set-EntraPolicy" { { Set-EntraPolicy -xyz } | Should -Throw "A parameter cannot be found that matches parameter name 'xyz'*" } - It "Should contain 'User-Agent' header" { - Mock -CommandName Invoke-GraphRequest -MockWith {$args} -ModuleName Microsoft.Graph.Entra $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPolicy" - $result = Set-EntraPolicy -Id "Engineering_Project" -type "HomeRealmDiscoveryPolicy" - $params = Get-Parameters -data $result - $a= $params | ConvertTo-json | ConvertFrom-Json - $a.headers.'User-Agent' | Should -Be $userAgentHeaderValue + + Set-EntraPolicy -Id "Engineering_Project" -type "HomeRealmDiscoveryPolicy" + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPolicy" + + Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + It "Should contain 'User-Agent' header" { + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPartnerInformation" + + Set-EntraPartnerInformation -PartnerSupportUrl "http://www.test1.com" -PartnerCommerceUrl "http://www.test1.com" -PartnerHelpUrl "http://www.test1.com" -PartnerSupportEmails "contoso@example.com" -PartnerSupportTelephones "2342" -TenantId b73cc049-a025-4441-ba3a-8826d9a68ecc + + $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Set-EntraPartnerInformation" + + Should -Invoke -CommandName Invoke-MgGraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 -ParameterFilter { + $Headers.'User-Agent' | Should -Be $userAgentHeaderValue + $true + } + } + It "Should execute successfully without throwing an error" { + # Disable confirmation prompts + $originalDebugPreference = $DebugPreference + $DebugPreference = 'Continue' + + try { + # Act & Assert: Ensure the function doesn't throw an exception + { Set-EntraPolicy -Id "bbbbbbbb-1111-2222-3333-cccccccccccc" -Debug } | Should -Not -Throw + } finally { + # Restore original confirmation preference + $DebugPreference = $originalDebugPreference + } } }