1- BeforeAll {
2- $loadEnvPath = Join-Path $PSScriptRoot ' loadEnv.ps1'
3- if (-Not (Test-Path - Path $loadEnvPath )) {
4- $loadEnvPath = Join-Path $PSScriptRoot ' ..\loadEnv.ps1'
5- }
6- . ($loadEnvPath )
7- $ModuleName = " Microsoft.Graph.Authentication"
8- $ModulePath = Join-Path $PSScriptRoot " ..\artifacts\$ModuleName .psd1"
9- Import-Module $ModulePath - Force
10- $PSDefaultParameterValues = @ {" Connect-MgGraph:TenantId" = ${env: TENANTIDENTIFIER} ; " Connect-MgGraph:ClientId" = ${env: CLIENTIDENTIFIER} ; " Connect-MgGraph:CertificateThumbprint" = ${env: CERTIFICATETHUMBPRINT} }
11- }
12- Describe ' Invoke-MgGraphRequest Collection Results' {
13- BeforeAll {
14- Connect-MgGraph
15- }
16- It ' ShouldReturnPsObject' {
17- Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.Management.Automation.PSObject ]
18- }
19-
20- It ' ShouldReturnHashTable' {
21- $hashTable = Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.Collections.Hashtable ]
22- }
23-
24- It ' ShouldReturnJsonString' {
25- $jsonString = Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.String ]
26- }
27-
28- It ' ShouldReturnHttpResponseMessage' {
29- $httpResponseMessage = Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
30- }
31-
32- It ' ShouldReturnPsObjectBeta' {
33- $psObject = Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.Management.Automation.PSObject ]
34- }
35-
36- It ' ShouldReturnHashTableBeta' {
37- $hashTable = Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.Collections.Hashtable ]
38- }
39-
40- It ' ShouldReturnJsonStringBeta' {
41- $jsonString = Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.String ]
42- }
43-
44- It ' ShouldReturnHttpResponseMessageBeta' {
45- $httpResponseMessage = Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
46- }
47- }
48- Describe ' Invoke-MgGraphRequest Single Entity' {
49- BeforeAll {
50- Connect-MgGraph
51- }
52- It ' ShouldReturnPsObject' {
53- $psObject = Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Management.Automation.PSObject ]
54- }
55-
56- It ' ShouldReturnHashTable' {
57- Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Collections.Hashtable ]
58- }
59-
60- It ' ShouldReturnJsonString' {
61- Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.String ]
62- }
63-
64- It ' ShouldReturnHttpResponseMessage' {
65- Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
66- }
67-
68- It ' ShouldReturnPsObjectBeta' {
69- Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Management.Automation.PSObject ]
70- }
71-
72- It ' ShouldReturnHashTableBeta' {
73- Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Collections.Hashtable ]
74- }
75-
76- It ' ShouldReturnJsonStringBeta' {
77- Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.String ]
78- }
79-
80- It ' ShouldReturnHttpResponseMessageBeta' {
81- Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
82- }
83- }
84-
85- Describe ' Invoke-MgGraphRequest Non-Json Responses' {
86- BeforeAll {
87- Connect-MgGraph
88- }
89- It ' Should Throw when -OutputFilePath is not Specified and Request Returns a Non-Json Response' {
90- { Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" } | Should - Throw
91- }
92- It ' Should Not Throw when -OutputFilePath is Specified' {
93- { Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" - OutputFilePath ./ data .csv } | Should -Not - Throw
94- }
95- It ' Should Not Throw when -InferOutputFilePath is Specified' {
96- { Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" - InferOutputFileName } | Should -Not - Throw
97- }
1+ Describe ' Invoke-MgGraphRequest Command' - Skip {
2+ BeforeAll {
3+ $loadEnvPath = Join-Path $PSScriptRoot ' loadEnv.ps1'
4+ if (-Not (Test-Path - Path $loadEnvPath )) {
5+ $loadEnvPath = Join-Path $PSScriptRoot ' ..\loadEnv.ps1'
6+ }
7+ . ($loadEnvPath )
8+ $ModuleName = " Microsoft.Graph.Authentication"
9+ $ModulePath = Join-Path $PSScriptRoot " ..\artifacts\$ModuleName .psd1"
10+ Import-Module $ModulePath - Force
11+ $PSDefaultParameterValues = @ {" Connect-MgGraph:TenantId" = ${env: TENANTIDENTIFIER} ; " Connect-MgGraph:ClientId" = ${env: CLIENTIDENTIFIER} ; " Connect-MgGraph:CertificateThumbprint" = ${env: CERTIFICATETHUMBPRINT} }
12+ Connect-MgGraph
13+ }
14+ Context ' Collection Results' {
15+ It ' ShouldReturnPsObject' {
16+ Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.Management.Automation.PSObject ]
17+ }
18+
19+ It ' ShouldReturnHashTable' {
20+ Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.Collections.Hashtable ]
21+ }
22+
23+ It ' ShouldReturnJsonString' {
24+ Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.String ]
25+ }
26+
27+ It ' ShouldReturnHttpResponseMessage' {
28+ Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/v1.0/users" | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
29+ }
30+
31+ It ' ShouldReturnPsObjectBeta' {
32+ Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.Management.Automation.PSObject ]
33+ }
34+
35+ It ' ShouldReturnHashTableBeta' {
36+ Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.Collections.Hashtable ]
37+ }
38+
39+ It ' ShouldReturnJsonStringBeta' {
40+ Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.String ]
41+ }
42+
43+ It ' ShouldReturnHttpResponseMessageBeta' {
44+ Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/beta/users" | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
45+ }
46+ }
47+ Context ' Single Entity' {
48+ It ' ShouldReturnPsObject' {
49+ Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Management.Automation.PSObject ]
50+ }
51+
52+ It ' ShouldReturnHashTable' {
53+ Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Collections.Hashtable ]
54+ }
55+
56+ It ' ShouldReturnJsonString' {
57+ Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.String ]
58+ }
59+
60+ It ' ShouldReturnHttpResponseMessage' {
61+ Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/v1.0/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
62+ }
63+
64+ It ' ShouldReturnPsObjectBeta' {
65+ Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Management.Automation.PSObject ]
66+ }
67+
68+ It ' ShouldReturnHashTableBeta' {
69+ Invoke-MgGraphRequest - OutputType Hashtable - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Collections.Hashtable ]
70+ }
71+
72+ It ' ShouldReturnJsonStringBeta' {
73+ Invoke-MgGraphRequest - OutputType Json - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.String ]
74+ }
75+
76+ It ' ShouldReturnHttpResponseMessageBeta' {
77+ Invoke-MgGraphRequest - OutputType HttpResponseMessage - Uri " https://graph.microsoft.com/beta/users/${env: DEFAULTUSERID} " | Should - BeOfType [System.Net.Http.HttpResponseMessage ]
78+ }
79+ }
80+
81+ Context ' Non-Json Responses' {
82+ It ' Should Throw when -OutputFilePath is not Specified and Request Returns a Non-Json Response' {
83+ { Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" } | Should - Throw
84+ }
85+ It ' Should Not Throw when -OutputFilePath is Specified' {
86+ { Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" - OutputFilePath ./ data .csv } | Should -Not - Throw
87+ }
88+ It ' Should Not Throw when -InferOutputFilePath is Specified' {
89+ { Invoke-MgGraphRequest - OutputType PSObject - Uri " https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" - InferOutputFileName } | Should -Not - Throw
90+ }
91+ }
92+
93+ AfterAll {
94+ Disconnect-MgGraph
95+ }
9896}
0 commit comments