From c702ce798489cc2648f4f14df996feab9b549e51 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Thu, 11 Feb 2021 13:25:17 -0800 Subject: [PATCH 1/3] Remove entity-id property from entities. --- src/readme.graph.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/readme.graph.md b/src/readme.graph.md index 1ae2ac3c1e4..5a94effff1e 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -499,20 +499,6 @@ directive: $ = $.replace(additionalPropertiesRegex, '$1$2 new $3'); } - let regexPattern = /^\s*public\s*partial\s*class\s*MicrosoftGraph(?.*):$/gm; - let regexArray; - while ((regexArray = regexPattern.exec($)) !== null) { - if (regexArray['groups'] != null) - { - let EntityName = regexArray['groups'].EntityName.trim(); - let newEntityId = EntityName + 'Id'; - let newEntityIdPropRegex = new RegExp("^\\s*public\\s*string\\s*"+newEntityId+"\\.*","gm"); - let existingIdPropRegex = /(^\s*)(public\s*string\s*Id\s.*)/gm; - if ((!$.match(newEntityIdPropRegex)) && $.match(existingIdPropRegex) && (newEntityId != "EntityId") && (newEntityId != "BaseItemId")) { - $ = $.replace(existingIdPropRegex, '$1$2\n\n$1partial void AfterToJson(ref Microsoft.Graph.PowerShell.Runtime.Json.JsonObject container, Microsoft.Graph.PowerShell.Runtime.SerializationMode serializationMode)\n$1{\n$1\tif (serializationMode == Microsoft.Graph.PowerShell.Runtime.SerializationMode.IncludeAll) {\n$1\t\tAddIf(null != this.Id ? (Microsoft.Graph.PowerShell.Runtime.Json.JsonNode)new Microsoft.Graph.PowerShell.Runtime.Json.JsonString(this.Id) : null, "'+ EntityName.toLowerCase() +'-id", container.Add);\n$1\t}\n$1}'); - } - } - } return $; } # Modify generated .cs cmdlets. From bf57ffb2d7dc15d455f1a55e9c033dfb1c0237e4 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Wed, 17 Feb 2021 15:38:31 -0800 Subject: [PATCH 2/3] Add tests for New-MgInvitation. --- .../Authentication/ErrorConstants.cs | 2 +- .../Identity.SignIns/test/env.json | 11 +++ .../Identity.SignIns/test/loadEnv.ps1 | 8 +- .../v1.0-beta/New-MgInvitation.Recording.json | 62 +++++++++++++ .../test/v1.0-beta/New-MgInvitation.Tests.ps1 | 90 +++++++++++++++---- .../test/v1.0/New-MgInvitation.Recording.json | 62 +++++++++++++ .../test/v1.0/New-MgInvitation.Tests.ps1 | 88 ++++++++++++++---- 7 files changed, 289 insertions(+), 34 deletions(-) create mode 100644 src/Identity.SignIns/Identity.SignIns/test/env.json create mode 100644 src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Recording.json create mode 100644 src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Recording.json diff --git a/src/Authentication/Authentication/ErrorConstants.cs b/src/Authentication/Authentication/ErrorConstants.cs index 783bc3e8cbf..cfe2b615694 100644 --- a/src/Authentication/Authentication/ErrorConstants.cs +++ b/src/Authentication/Authentication/ErrorConstants.cs @@ -38,7 +38,7 @@ internal static class Codes internal static class Message { internal const string InvalidJWT = "Invalid JWT access token."; - internal const string MissingAuthContext = "Authentication needed, call Connect-Graph."; + internal const string MissingAuthContext = "Authentication needed, call Connect-MgGraph."; internal const string NullOrEmptyParameter = "Parameter '{0}' cannot be null or empty."; internal const string MacKeyChainFailed = "{0} failed with result code {1}."; internal const string DeviceCodeTimeout = "Device code terminal timed-out after {0} seconds. Please try again."; diff --git a/src/Identity.SignIns/Identity.SignIns/test/env.json b/src/Identity.SignIns/Identity.SignIns/test/env.json new file mode 100644 index 00000000000..678a5572ae1 --- /dev/null +++ b/src/Identity.SignIns/Identity.SignIns/test/env.json @@ -0,0 +1,11 @@ +{ + "ClientId": "56db239f-b87c-4dc0-9d9b-2ec0318e4ad9", + "TenantId": "61fcf17f-000c-4ab8-a4dc-9e92405fc737", + "Users": [ + { + "Id": "85d17c69-6789-47c7-bf10-ad08ab4cd8da", + "DisplayName": "John Doe", + "Mail": "johndoe@testtenant.onmicrosoft.com" + } + ] +} \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/loadEnv.ps1 b/src/Identity.SignIns/Identity.SignIns/test/loadEnv.ps1 index c4ebf2e8310..80929a891b5 100644 --- a/src/Identity.SignIns/Identity.SignIns/test/loadEnv.ps1 +++ b/src/Identity.SignIns/Identity.SignIns/test/loadEnv.ps1 @@ -23,6 +23,10 @@ if (Test-Path -Path (Join-Path $PSScriptRoot $envFile)) { } $env = @{} if (Test-Path -Path $envFilePath) { - $env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json - $PSDefaultParameterValues=@{"*:SubscriptionId"=$env.SubscriptionId; "*:Tenant"=$env.Tenant} + # Load dummy configuration. + $env = Get-Content (Join-Path $PSScriptRoot $envFile) | ConvertFrom-Json -AsHashTable + [Microsoft.Graph.PowerShell.Authentication.GraphSession]::Instance.AuthContext = New-Object Microsoft.Graph.PowerShell.Authentication.AuthContext -Property @{ + ClientId = $env.ClientId + TenantId = $env.TenantId + } } \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Recording.json b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Recording.json new file mode 100644 index 00000000000..77b3b3d88e0 --- /dev/null +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Recording.json @@ -0,0 +1,62 @@ +{ + "New-MgInvitation+[NoContext]+ShouldCreateInvite+$POST+https://graph.microsoft.com/beta/invitations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/beta/invitations", + "Content": "{\r\n \"inviteRedirectUrl\": \"https://myapp.contoso.com\",\r\n \"invitedUserDisplayName\": \"John Doe\",\r\n \"invitedUserEmailAddress\": \"johndoe@testtenant.onmicrosoft.com\"\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "165" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Date": [ "Wed, 17 Feb 2021 23:05:50 GMT" ], + "Cache-Control": [ "no-store, must-revalidate, no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Location": [ "https://graph.microsoft.com/" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "7927b734-7f49-4704-8be9-2a802aeb76f8" ], + "client-request-id": [ "7927b734-7f49-4704-8be9-2a802aeb76f8" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00032E05\"}}" ], + "OData-Version": [ "4.0" ] + }, + "ContentHeaders": { + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#invitations/$entity\",\"id\":\"0c9899a1-2e79-4b05-8285-7df46eda1e75\",\"inviteRedeemUrl\":\"https://login.microsoftonline.com/redeem?rd=NotValid\",\"invitedUserDisplayName\":\"John Doe\",\"invitedUserType\":\"Guest\",\"invitedUserEmailAddress\":\"johndoe@testtenant.onmicrosoft.com\",\"sendInvitationMessage\":false,\"resetRedemption\":false,\"inviteRedirectUrl\":\"https://myapp.contoso.com/\",\"status\":\"PendingAcceptance\",\"invitedUserMessageInfo\":{\"messageLanguage\":null,\"customizedMessageBody\":null,\"ccRecipients\":[{\"emailAddress\":{\"name\":null,\"address\":null}}]},\"invitedUser\":{\"id\":\"ebb12722-9cb6-4c90-ab39-bf1bb658bae7\"}}" + } + }, + "New-MgInvitation+[NoContext]+ShouldThrowInvalidEmailError+$POST+https://graph.microsoft.com/beta/invitations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/beta/invitations", + "Content": "{\r\n \"invitedUser\": {\r\n \"id\": \"\",\r\n \"displayName\": \"John Doe\",\r\n \"mail\": \"johndoe@testtenant.onmicrosoft.com\",\r\n \"userPrincipalName\": \"johndoe@testtenant.onmicrosoft.com\"\r\n }\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "190" ] + } + }, + "Response": { + "StatusCode": 400, + "Headers": { + "Date": [ "Wed, 17 Feb 2021 23:05:50 GMT" ], + "Cache-Control": [ "no-store, must-revalidate, no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "e71de23d-cfb6-416a-b03e-416e493ba6ea" ], + "client-request-id": [ "e71de23d-cfb6-416a-b03e-416e493ba6ea" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00033720\"}}" ] + }, + "ContentHeaders": { + }, + "Content": "{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"Invalid Email Address\",\r\n \"innerError\": {\r\n \"request-id\": \"e71de23d-cfb6-416a-b03e-416e493ba6ea\",\r\n \"date\": \"2021-02-17T23:05:51\",\r\n \"client-request-id\": \"e71de23d-cfb6-416a-b03e-416e493ba6ea\"\r\n }\r\n }\r\n}" + } + } +} \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Tests.ps1 b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Tests.ps1 index d311337dc8b..da32b80221b 100644 --- a/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Tests.ps1 +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgInvitation.Tests.ps1 @@ -1,22 +1,80 @@ -$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' -if (-Not (Test-Path -Path $loadEnvPath)) { - $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' -} -. ($loadEnvPath) -$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json' -$currentPath = $PSScriptRoot -while(-not $mockingPath) { - $mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File - $currentPath = Split-Path -Path $currentPath -Parent +BeforeAll { + $loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' + if (-Not (Test-Path -Path $loadEnvPath)) { + $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' + } + . ($loadEnvPath) + # Set test mode to playback. + $TestMode = 'playback' + $TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json' + $currentPath = $PSScriptRoot + while(-not $mockingPath) { + $mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File + $currentPath = Split-Path -Path $currentPath -Parent + } + . ($mockingPath | Select-Object -First 1).FullName + # Switch to beta profile. + Select-MgProfile beta } -. ($mockingPath | Select-Object -First 1).FullName Describe 'New-MgInvitation' { - It 'CreateExpanded1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + BeforeAll { + $Mock.PushDescription('New-MgInvitation') + } + + Context 'CreateExpanded1' { + It 'ShouldCreateInvite' { + $Mock.PushScenario('ShouldCreateInvite') + $Params = @{ + InvitedUserDisplayName = $env.Users[0].DisplayName + InvitedUserEmailAddress = $env.Users[0].Mail + InviteRedirectUrl = 'https://myapp.contoso.com' + } + $Invitation = New-MgInvitation @Params + $Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation1' + $Invitation | Should -HaveCount 1 + $Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName + $Invitation.Status | Should -Be 'PendingAcceptance' + $Invitation.AdditionalProperties | Should -HaveCount 1 + } + + It 'ShouldThrowInvalidEmailError' { + $Mock.PushScenario('ShouldThrowInvalidEmailError') + $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{ + Id = $env.Users[0].UserId + DisplayName = $env.Users[0].DisplayName + Mail = $env.Users[0].Mail + UserPrincipalName = $env.Users[0].Mail + } + { New-MgInvitation -InvitedUser $MyUser -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_CreateExpanded1' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' + } } - It 'Create1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + Context 'Create1' { + It 'ShouldCreateInvite' { + $Mock.PushScenario('ShouldCreateInvite') + $Params = @{ + InvitedUserDisplayName = $env.Users[0].DisplayName + InvitedUserEmailAddress = $env.Users[0].Mail + InviteRedirectUrl = 'https://myapp.contoso.com' + } + $Invitation = New-MgInvitation -BodyParameter $Params + $Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation1' + $Invitation | Should -HaveCount 1 + $Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName + $Invitation.Status | Should -Be 'PendingAcceptance' + $Invitation.AdditionalProperties | Should -HaveCount 1 + } + + It 'ShouldThrowInvalidEmailError' { + $Mock.PushScenario('ShouldThrowInvalidEmailError') + $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{ + Id = $env.Users[0].UserId + DisplayName = $env.Users[0].DisplayName + Mail = $env.Users[0].Mail + UserPrincipalName = $env.Users[0].Mail + } + { New-MgInvitation -BodyParameter @{ InvitedUser = $MyUser } -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_Create1' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' + } } -} +} \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Recording.json b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Recording.json new file mode 100644 index 00000000000..68c125b78b4 --- /dev/null +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Recording.json @@ -0,0 +1,62 @@ +{ + "New-MgInvitation+[NoContext]+ShouldCreateInvite+$POST+https://graph.microsoft.com/v1.0/invitations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/v1.0/invitations", + "Content": "{\r\n \"inviteRedirectUrl\": \"https://myapp.contoso.com\",\r\n \"invitedUserDisplayName\": \"John Doe\",\r\n \"invitedUserEmailAddress\": \"johndoe@testtenant.onmicrosoft.com\"\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "165" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Date": [ "Wed, 17 Feb 2021 21:57:41 GMT" ], + "Cache-Control": [ "no-store, must-revalidate, no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Location": [ "https://graph.microsoft.com/" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "f4cd9413-56cc-4ab5-affa-e17d488a6eb2" ], + "client-request-id": [ "f4cd9413-56cc-4ab5-affa-e17d488a6eb2" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00032D50\"}}" ], + "OData-Version": [ "4.0" ] + }, + "ContentHeaders": { + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#invitations/$entity\",\"id\":\"0c9899a1-2e79-4b05-8285-7df46eda1e75\",\"inviteRedeemUrl\":\"https://login.microsoftonline.com/redeem?rd=NotValid\",\"invitedUserDisplayName\":\"John Doe\",\"invitedUserType\":\"Guest\",\"invitedUserEmailAddress\":\"johndoe@testtenant.onmicrosoft.com\",\"sendInvitationMessage\":false,\"inviteRedirectUrl\":\"https://myapp.contoso.com/\",\"status\":\"PendingAcceptance\",\"invitedUserMessageInfo\":{\"messageLanguage\":null,\"customizedMessageBody\":null,\"ccRecipients\":[{\"emailAddress\":{\"name\":null,\"address\":null}}]},\"invitedUser\":{\"id\":\"ebb12722-9cb6-4c90-ab39-bf1bb658bae7\"}}" + } + }, + "New-MgInvitation+[NoContext]+ShouldThrowInvalidEmailError+$POST+https://graph.microsoft.com/v1.0/invitations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/v1.0/invitations", + "Content": "{\r\n \"invitedUser\": {\r\n \"id\": \"\",\r\n \"displayName\": \"John Doe\",\r\n \"mail\": \"johndoe@testtenant.onmicrosoft.com\",\r\n \"userPrincipalName\": \"johndoe@testtenant.onmicrosoft.com\"\r\n }\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "190" ] + } + }, + "Response": { + "StatusCode": 400, + "Headers": { + "Date": [ "Wed, 17 Feb 2021 21:57:39 GMT" ], + "Cache-Control": [ "no-store, must-revalidate, no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "90b8bf35-b7d7-4278-8582-07ad4f34bce3" ], + "client-request-id": [ "90b8bf35-b7d7-4278-8582-07ad4f34bce3" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00032D57\"}}" ] + }, + "ContentHeaders": { + }, + "Content": "{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"Invalid Email Address\",\r\n \"innerError\": {\r\n \"request-id\": \"90b8bf35-b7d7-4278-8582-07ad4f34bce3\",\r\n \"date\": \"2021-02-17T21:57:39\",\r\n \"client-request-id\": \"90b8bf35-b7d7-4278-8582-07ad4f34bce3\"\r\n }\r\n }\r\n}" + } + } +} \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 index e96e1040ed2..93ec8e2a499 100644 --- a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 @@ -1,22 +1,80 @@ -$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' -if (-Not (Test-Path -Path $loadEnvPath)) { - $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' -} -. ($loadEnvPath) -$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json' -$currentPath = $PSScriptRoot -while(-not $mockingPath) { - $mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File - $currentPath = Split-Path -Path $currentPath -Parent +BeforeAll { + $loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' + if (-Not (Test-Path -Path $loadEnvPath)) { + $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' + } + . ($loadEnvPath) + # Set test mode to playback. + $TestMode = 'playback' + $TestRecordingFile = Join-Path $PSScriptRoot 'New-MgInvitation.Recording.json' + $currentPath = $PSScriptRoot + while (-not $mockingPath) { + $mockingPath = Get-ChildItem -Path $currentPath -Recurse -Include 'HttpPipelineMocking.ps1' -File + $currentPath = Split-Path -Path $currentPath -Parent + } + . ($mockingPath | Select-Object -First 1).FullName + + Select-MgProfile 'v1.0' } -. ($mockingPath | Select-Object -First 1).FullName Describe 'New-MgInvitation' { - It 'CreateExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + BeforeAll { + $Mock.PushDescription('New-MgInvitation') } - It 'Create' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + Context 'CreateExpanded' { + It 'ShouldCreateInvite' { + $Mock.PushScenario('ShouldCreateInvite') + $Params = @{ + InvitedUserDisplayName = $env.Users[0].DisplayName + InvitedUserEmailAddress = $env.Users[0].Mail + InviteRedirectUrl = 'https://myapp.contoso.com' + } + $Invitation = New-MgInvitation @Params + $Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation' + $Invitation | Should -HaveCount 1 + $Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName + $Invitation.Status | Should -Be 'PendingAcceptance' + $Invitation.AdditionalProperties | Should -HaveCount 1 + } + + It 'ShouldThrowInvalidEmailError' { + $Mock.PushScenario('ShouldThrowInvalidEmailError') + $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{ + Id = $env.Users[0].UserId + DisplayName = $env.Users[0].DisplayName + Mail = $env.Users[0].Mail + UserPrincipalName = $env.Users[0].Mail + } + { New-MgInvitation -InvitedUser $MyUser -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_CreateExpanded' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' + } + } + + Context 'Create' { + It 'ShouldCreateInvite' { + $Mock.PushScenario('ShouldCreateInvite') + $Params = @{ + InvitedUserDisplayName = $env.Users[0].DisplayName + InvitedUserEmailAddress = $env.Users[0].Mail + InviteRedirectUrl = 'https://myapp.contoso.com' + } + $Invitation = New-MgInvitation -BodyParameter $Params + $Invitation | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphInvitation' + $Invitation | Should -HaveCount 1 + $Invitation.InvitedUserDisplayName | Should -Be $env.Users[0].DisplayName + $Invitation.Status | Should -Be 'PendingAcceptance' + $Invitation.AdditionalProperties | Should -HaveCount 1 + } + + It 'ShouldThrowInvalidEmailError' { + $Mock.PushScenario('ShouldThrowInvalidEmailError') + $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{ + Id = $env.Users[0].UserId + DisplayName = $env.Users[0].DisplayName + Mail = $env.Users[0].Mail + UserPrincipalName = $env.Users[0].Mail + } + { New-MgInvitation -BodyParameter @{ InvitedUser = $MyUser } -ErrorAction Stop } | Should -Throw -ErrorId 'BadRequest,Microsoft.Graph.PowerShell.Cmdlets.NewMgInvitation_Create' -ExpectedMessage 'Invalid Email Address' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' + } } } From 727f15ba969092ee2ba4715db6a4e96fa5d795d8 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Wed, 17 Feb 2021 16:00:16 -0800 Subject: [PATCH 3/3] Set user type to MicrosoftGraphUser in v1.0. --- .../Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 index 93ec8e2a499..c30467a04f2 100644 --- a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgInvitation.Tests.ps1 @@ -40,7 +40,7 @@ Describe 'New-MgInvitation' { It 'ShouldThrowInvalidEmailError' { $Mock.PushScenario('ShouldThrowInvalidEmailError') - $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{ + $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser]@{ Id = $env.Users[0].UserId DisplayName = $env.Users[0].DisplayName Mail = $env.Users[0].Mail @@ -68,7 +68,7 @@ Describe 'New-MgInvitation' { It 'ShouldThrowInvalidEmailError' { $Mock.PushScenario('ShouldThrowInvalidEmailError') - $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser1]@{ + $MyUser = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser]@{ Id = $env.Users[0].UserId DisplayName = $env.Users[0].DisplayName Mail = $env.Users[0].Mail