-
Notifications
You must be signed in to change notification settings - Fork 38
updated mock test cases #1105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
updated mock test cases #1105
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0b04b18
updated mock test cases
snehalkotwal 984fd8a
update
snehalkotwal da7c00d
updated test cases
snehalkotwal 38a8b4c
pull
v-akarke fa3d2bc
fixed UT
v-akarke b02a411
conflct
snehalkotwal 0bb6b3e
updated
snehalkotwal f8e562e
conflict
snehalkotwal ecfdde4
update
snehalkotwal e0b4682
added json convert and depth
v-uansari 982aac3
updated mock test cases
snehalkotwal 5a7aef9
update
snehalkotwal 49c1d5b
updated test cases
snehalkotwal dad2430
fixed UT
v-akarke e383969
updated
snehalkotwal eb91260
update
snehalkotwal 269f460
added json convert and depth
v-uansari 3ba6095
Merge branch 'main' of https://github.com/microsoftgraph/entra-powers…
v-uansari daf509b
Merge branch 'mock-test-cases-23' of https://github.com/microsoftgrap…
v-uansari 70f737e
added additional property
v-uansari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/module/Entra/Get-EntraApplicationKeyCredential.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # ------------------------------------------------------------------------------ | ||
| # 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 | ||
| } | ||
| Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force | ||
|
|
||
| $scriptblock = { | ||
| @{ | ||
| "KeyCredentials" = @( | ||
| @{ | ||
| "CustomKeyIdentifier" = "" | ||
| "EndDate" = "10/23/2024 11:36:56 AM" | ||
| "KeyId" = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" | ||
| "StartDate" = "11/22/2023 11:35:16 AM" | ||
| "Type" = "Symmetric" | ||
| "Usage" = "Sign" | ||
| "Value" = "" | ||
| "Parameters" = $args | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Mock -CommandName Get-MgApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra | ||
| } | ||
|
|
||
| Describe "Get-EntraApplicationKeyCredential" { | ||
| Context "Test for Get-EntraApplicationKeyCredential" { | ||
| It "Should not return empty" { | ||
| $result = Get-EntraApplicationKeyCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| $result | Should -Not -BeNullOrEmpty | ||
| Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Should fail when ObjectId is empty" { | ||
| { Get-EntraApplicationKeyCredential -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." | ||
| } | ||
| It "Should contain 'User-Agent' header" { | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationKeyCredential" | ||
| $result = Get-EntraApplicationKeyCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationKeyCredential" | ||
| Should -Invoke -CommandName Get-MgApplication -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-EntraApplicationKeyCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw | ||
| } finally { | ||
| # Restore original confirmation preference | ||
| $DebugPreference = $originalDebugPreference | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # ------------------------------------------------------------------------------ | ||
| # 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 | ||
| } | ||
| Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force | ||
|
|
||
| $mockResponse = { | ||
| return @{ | ||
| value = @( | ||
| @{ | ||
| Id = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| ageGroup = $null | ||
| onPremisesLastSyncDateTime = $null | ||
| creationType = $null | ||
| preferredLanguage = $null | ||
| mail = "admin@contonso.com" | ||
| securityIdentifier = "S-1-12-1-1093396945-1080104032-2731339150-364051459" | ||
| consentProvidedForMinor = $null | ||
| onPremisesUserPrincipalName = $null | ||
| Parameters = $args | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Mock -CommandName Invoke-GraphRequest -MockWith $mockResponse -ModuleName Microsoft.Graph.Entra | ||
| } | ||
|
|
||
| Describe "Get-EntraApplicationOwner"{ | ||
| Context "Test for Get-EntraApplicationOwner"{ | ||
| It "Should return application owner" { | ||
| $result = Get-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| Write-Host $result | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.Id | should -Be @('aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb') | ||
|
|
||
| Should -Invoke -CommandName Invoke-GraphRequest -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Should fail when ObjectId is empty" { | ||
| { Get-EntraApplicationOwner -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId' because it is an empty string." | ||
| } | ||
| It "Should fail when ObjectId is null" { | ||
| { Get-EntraApplicationOwner -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" | ||
| } | ||
| It "Should fail when All has an argument" { | ||
| { Get-EntraApplicationOwner -All $true } | Should -Throw "A positional parameter cannot be found that accepts argument 'True'.*" | ||
| } | ||
| It "Should fail when Top is empty" { | ||
| { Get-EntraApplicationOwner -Top } | Should -Throw "Missing an argument for parameter 'Top'*" | ||
| } | ||
| It "Should fail when Top is invalid" { | ||
| { Get-EntraApplicationOwner -Top XY } | Should -Throw "Cannot process argument transformation on parameter 'Top'*" | ||
| } | ||
| It "Property parameter should work" { | ||
| $result = Get-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property Id | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.Id | Should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| } | ||
| It "Should contain 'User-Agent' header" { | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationOwner" | ||
| $result = Get-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationOwner" | ||
| 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-EntraApplicationOwner -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw | ||
| } finally { | ||
| # Restore original confirmation preference | ||
| $DebugPreference = $originalDebugPreference | ||
| } | ||
| } | ||
| } | ||
| } |
79 changes: 79 additions & 0 deletions
79
test/module/Entra/Get-EntraApplicationPasswordCredential.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| BeforeAll { | ||
| if((Get-Module -Name Microsoft.Graph.Entra) -eq $null){ | ||
| Import-Module Microsoft.Graph.Entra | ||
| } | ||
| Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force | ||
|
|
||
| $scriptblock = { | ||
| @{ | ||
| "PasswordCredentials" = @( | ||
| @{ | ||
| "CustomKeyIdentifier" = {116, 101, 115, 116} | ||
| "DisplayName" = "Test" | ||
| "EndDateTime" = "10/23/2024 11:36:56 AM" | ||
| "KeyId" = "aaaaaaaa-0b0b-1c1c-2d2d-333333333333" | ||
| "StartDateTime" = "11/22/2023 11:35:16 AM" | ||
| "Hint" = "123" | ||
| "SecretText" = "" | ||
| "Parameters" = $args | ||
| } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Mock -CommandName Get-MgApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra | ||
| } | ||
|
|
||
| Describe "Get-EntraApplicationPasswordCredential" { | ||
| Context "Test for Get-EntraApplicationPasswordCredential" { | ||
| It "Should not return empty" { | ||
| $result = Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| $result | Should -Not -BeNullOrEmpty | ||
| Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Should fail when ObjectId is empty" { | ||
| { Get-EntraApplicationPasswordCredential -ObjectId "" } | Should -Throw "Cannot bind argument to parameter 'ObjectId'*" | ||
| } | ||
| It "Should fail when ObjectId is null" { | ||
| { Get-EntraApplicationPasswordCredential -ObjectId } | Should -Throw "Missing an argument for parameter 'ObjectId'*" | ||
| } | ||
| It "Should fail when invalid parameter is passed" { | ||
| { Get-EntraApplicationPasswordCredential -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'*" | ||
| } | ||
| It "Property parameter should work" { | ||
| $result = Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property DisplayName | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.DisplayName | Should -Be "Test" | ||
|
|
||
| Should -Invoke -CommandName Get-MgApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
|
|
||
| It "Should fail when Property is empty" { | ||
| { Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Property } | Should -Throw "Missing an argument for parameter 'Property'*" | ||
| } | ||
|
|
||
| It "Should contain 'User-Agent' header" { | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationPasswordCredential" | ||
| $result = Get-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraApplicationPasswordCredential" | ||
| Should -Invoke -CommandName Get-MgApplication -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-EntraApplicationPasswordCredential -ObjectId "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" -Debug } | Should -Not -Throw | ||
| } finally { | ||
| # Restore original confirmation preference | ||
| $DebugPreference = $originalDebugPreference | ||
| } | ||
| } | ||
| } | ||
| } | ||
131 changes: 131 additions & 0 deletions
131
test/module/Entra/Get-EntraDeletedApplication.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # ------------------------------------------------------------------------------ | ||
| # 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 | ||
| } | ||
| Import-Module (Join-Path $psscriptroot "..\Common-Functions.ps1") -Force | ||
|
|
||
| $scriptblock = { | ||
| return @( | ||
| [PSCustomObject]@{ | ||
| "AddIns" = {} | ||
| "AppRoles" = {} | ||
| "GroupMembershipClaims" = {} | ||
| "IdentifierUris" = {} | ||
| "Info" = @{ | ||
| LogoUrl=""; | ||
| } | ||
| "IsDeviceOnlyAuthSupported" = $null | ||
| "KeyCredentials" = {} | ||
| "OptionalClaims" = {} | ||
| "ParentalControlSettings" = @{ | ||
| CountriesBlockedForMinors=@{}; | ||
| LegalAgeGroupRule="Allow"; | ||
| } | ||
| "PasswordCredentials" = {} | ||
| "Api" = @{ | ||
| KnownClientApplications=@{}; | ||
| PreAuthorizedApplications=@{}; | ||
| } | ||
| "PublicClient" = @{ | ||
| RedirectUris=@{}; | ||
| } | ||
| "PublisherDomain" = "contoso.com" | ||
| "Web" = @{ | ||
| HomePageUrl=""; | ||
| LogoutUrl=""; | ||
| RedirectUris=@{}; | ||
| Oauth2AllowImplicitFlow="" | ||
| } | ||
| "RequiredResourceAccess" = $null | ||
| "DisplayName" = "Mock-test-App" | ||
| "Id" = "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| "Logo" = $null | ||
| "Parameters" = $args | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| Mock -CommandName Get-MgDirectoryDeletedItemAsApplication -MockWith $scriptblock -ModuleName Microsoft.Graph.Entra | ||
| } | ||
|
|
||
| Describe "Get-EntraDeletedApplication" { | ||
v-uansari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Context "Test for Get-EntraDeletedApplication" { | ||
| It "Should return all applications" { | ||
| $result = Get-EntraDeletedApplication | ConvertTo-Json -Depth 10 | ConvertFrom-Json | ||
| $result | Should -Not -BeNullOrEmpty | ||
| Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Should fail when All is empty" { | ||
| { Get-EntraDeletedApplication -All $true} | Should -Throw "A positional parameter cannot be found that accepts argument 'True'.*" | ||
| } | ||
| It "Should fail when invalid parameter is passed" { | ||
| { Get-EntraDeletedApplication -DisplayName "abc" } | Should -Throw "A parameter cannot be found that matches parameter name 'DisplayName'*" | ||
| } | ||
| It "Should return specific application by searchstring" { | ||
| $result = Get-EntraDeletedApplication -SearchString 'Mock-test-App' | ConvertTo-Json -Depth 10 | ConvertFrom-Json | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.DisplayName | should -Be 'Mock-test-App' | ||
|
|
||
| Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Should return specific application by filter" { | ||
| $result = Get-EntraDeletedApplication -Filter "DisplayName -eq 'Mock-test-App'" | ConvertTo-Json -Depth 10 | ConvertFrom-Json | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.DisplayName | should -Be 'Mock-test-App' | ||
|
|
||
| Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Should return top application" { | ||
| $result = Get-EntraDeletedApplication -Top 1 | ConvertTo-Json -Depth 10 | ConvertFrom-Json | ||
| $result | Should -Not -BeNullOrEmpty | ||
|
|
||
| Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
| It "Result should Contain ObjectId" { | ||
| $result = Get-EntraDeletedApplication -Filter "DisplayName -eq 'Mock-test-App'" | ConvertTo-Json -Depth 10 | ConvertFrom-Json | ||
| $result.ObjectId | should -Be "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" | ||
| } | ||
| It "Should contain Filter in parameters when passed SearchString to it" { | ||
| $result = Get-EntraDeletedApplication -SearchString 'Mock-test-App' | ConvertTo-Json -Depth 10| ConvertFrom-Json | ||
| $params = Get-Parameters -data $result.Parameters | ||
| $params.Filter | Should -Match "Mock-test-App" | ||
| } | ||
| It "Property parameter should work" { | ||
| $result = Get-EntraDeletedApplication -Property "DisplayName" | ConvertTo-Json | ConvertFrom-Json | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $result.DisplayName | Should -Be "Mock-test-App" | ||
|
|
||
| Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -ModuleName Microsoft.Graph.Entra -Times 1 | ||
| } | ||
|
|
||
| It "Should fail when Property is empty" { | ||
| { Get-EntraDeletedApplication -Property } | Should -Throw "Missing an argument for parameter 'Property'*" | ||
| } | ||
| It "Should contain 'User-Agent' header" { | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedApplication" | ||
| $result = Get-EntraDeletedApplication -Filter "DisplayName -eq 'Mock-test-App'" | ConvertTo-Json -Depth 10 | ConvertFrom-Json | ||
| $result | Should -Not -BeNullOrEmpty | ||
| $userAgentHeaderValue = "PowerShell/$psVersion EntraPowershell/$entraVersion Get-EntraDeletedApplication" | ||
| Should -Invoke -CommandName Get-MgDirectoryDeletedItemAsApplication -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-EntraDeletedApplication -Debug } | Should -Not -Throw | ||
| } finally { | ||
| # Restore original confirmation preference | ||
| $DebugPreference = $originalDebugPreference | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.