From 5f4c484a295bbfe1770ecf003d426e71aa13360a Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Thu, 2 Jun 2022 13:45:06 -0700 Subject: [PATCH 1/4] Remove camel case conversion of additional properties. --- src/readme.graph.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/readme.graph.md b/src/readme.graph.md index a1922c8c583..b2301ce370b 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -682,13 +682,6 @@ directive: let fromJsonRegex = /(\s*FromJson<\w*>\s*\(JsonObject\s*json\s*,\s*System\.Collections\.Generic\.IDictionary.*)(\s*)({)/gm $ = $.replace(fromJsonRegex, '$1$2$3\n$2 if (excludes != null){ excludes = new System.Collections.Generic.HashSet(excludes, global::System.StringComparer.OrdinalIgnoreCase);}'); - let toFirstUpperImplementation = 'internal static string ToFirstCharacterLowerCase(this string text) => String.IsNullOrEmpty(text) ? text : $"{char.ToLowerInvariant(text[0])}{text.Substring(1)}";' - let classRegex = /(internal\sstatic\sclass\sJsonSerializable(\s*){)/gm - $ = $.replace(classRegex, `$1$2${toFirstUpperImplementation}`) - - let directoryKeyRegex = /(container\.Add\(key\.Key)(,)/gm - $ = $.replace(directoryKeyRegex, '$1.ToFirstCharacterLowerCase()$2') - return $; } From 6d0ecf530c78b766955928ec479aa09f9c0d0506 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Thu, 2 Jun 2022 16:51:47 -0700 Subject: [PATCH 2/4] Only camelCase properties of NamedLocation abstract type. --- src/readme.graph.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/readme.graph.md b/src/readme.graph.md index b2301ce370b..81964b3aeb2 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -509,6 +509,16 @@ directive: let propertiesToRemoveRegex = /^.*Microsoft\.Graph\.PowerShell\.Runtime\.IAssociativeArray\.(Count|Keys|Values).*$/gm $ = $.replace(propertiesToRemoveRegex, ''); + let classRegex = /((\s*)public\s*partial\s*class\s*MicrosoftGraph(NamedLocation).*\s.*\s*\{)/gm + if($.match(classRegex)) { + $ = $.replace(classRegex, `$1$2${toFirstUpperImplementation}`) + + let toFirstUpperImplementation = 'internal string ToFirstCharacterLowerCase(string text) => System.String.IsNullOrEmpty(text) ? text : $"{char.ToLowerInvariant(text[0])}{text.Substring(1)}";' + + let directoryKeyRegex = /\.Add\((\s*property\.Key\.ToString\(\))/gm + $ = $.replace(directoryKeyRegex, '$1(ToFirstCharacterLowerCase($2)') + } + return $; } # Modify generated .PowerShell.cs model classes. From 2e3163c52e1c84fed6bb608e1806ae0769ec8377 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Fri, 3 Jun 2022 11:46:01 -0700 Subject: [PATCH 3/4] Add site list item tests. --- .../generate-modules-template.yml | 2 +- .azure-pipelines/integrated-pipeline.yml | 4 +- .../test/v1.0-beta/Get-MgSubSite.Tests.ps1 | 28 -------- .../New-MgSiteListItem.Recording.json | 36 ++++++++++ .../v1.0-beta/New-MgSiteListItem.Tests.ps1 | 66 +++++++++++++------ .../test/v1.0/Get-MgSiteByPath.Tests.ps1 | 8 +-- .../Sites/test/v1.0/Get-MgSubSite.Tests.ps1 | 28 -------- .../v1.0/New-MgSiteListItem.Recording.json | 36 ++++++++++ .../test/v1.0/New-MgSiteListItem.Tests.ps1 | 66 +++++++++++++------ 9 files changed, 171 insertions(+), 103 deletions(-) create mode 100644 src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Recording.json create mode 100644 src/Sites/Sites/test/v1.0/New-MgSiteListItem.Recording.json diff --git a/.azure-pipelines/generate-modules-template.yml b/.azure-pipelines/generate-modules-template.yml index fe66a0842dc..fb4fa65180b 100644 --- a/.azure-pipelines/generate-modules-template.yml +++ b/.azure-pipelines/generate-modules-template.yml @@ -142,7 +142,7 @@ jobs: pwsh: true script: | Write-Host $(BUILDNUMBER) - . $(System.DefaultWorkingDirectory)/tools/GenerateModules.ps1 -ArtifactsLocation $(Build.ArtifactStagingDirectory)\ -Build -EnableSigning -ModulePreviewNumber $(BUILDNUMBER) -RepositoryName "LocalNugetFeed" -ExcludeExampleTemplates -ExcludeNotesSection + . $(System.DefaultWorkingDirectory)/tools/GenerateModules.ps1 -ArtifactsLocation $(Build.ArtifactStagingDirectory)\ -Build -Test -EnableSigning -ModulePreviewNumber $(BUILDNUMBER) -RepositoryName "LocalNugetFeed" -ExcludeExampleTemplates -ExcludeNotesSection - template: ./generation-templates/generate-helpdocs-template.yml diff --git a/.azure-pipelines/integrated-pipeline.yml b/.azure-pipelines/integrated-pipeline.yml index d21770d142f..e7c0ba0b064 100644 --- a/.azure-pipelines/integrated-pipeline.yml +++ b/.azure-pipelines/integrated-pipeline.yml @@ -101,8 +101,8 @@ stages: KEYVAULT: $(KEYVAULT) AZURESUBSCRIPTION: $(AZURESUBSCRIPTION) -- stage: GenerateBetaModules - displayName: 'Generate Beta Modules (Microsoft.Graph.*)' +- stage: GenerateModules + displayName: 'Generate Modules (Microsoft.Graph.*)' jobs: - template: ./generate-modules-template.yml parameters: diff --git a/src/Sites/Sites/test/v1.0-beta/Get-MgSubSite.Tests.ps1 b/src/Sites/Sites/test/v1.0-beta/Get-MgSubSite.Tests.ps1 index 3ac3fcddd72..a730a9f2904 100644 --- a/src/Sites/Sites/test/v1.0-beta/Get-MgSubSite.Tests.ps1 +++ b/src/Sites/Sites/test/v1.0-beta/Get-MgSubSite.Tests.ps1 @@ -33,32 +33,4 @@ Describe 'Get-MgSubSite' { $SubSites.AdditionalProperties | Should -HaveCount 2 } } - - Context 'Get1' { - It 'ShouldGetASingleSubSite' { - $Mock.PushScenario('ShouldGetASingleSubSite') - - $SiteId = "root" - $SubSite = Get-MgSubSite -SiteId $SiteId -SiteId1 "randomId" - $SubSite | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite' - $SubSite | Should -HaveCount 1 - $SubSite.Id | Should -Be 'randomId' - $SubSite.WebUrl | Should -Be 'https://contoso.sharepoint.com/sites/site/subsiteA' - $SubSite.AdditionalProperties | Should -HaveCount 1 - } - } - - Context 'GetViaIdentity1' { - It 'ShouldGetASingleSubSiteViaInputObject' { - $Mock.PushScenario('ShouldGetASingleSubSiteViaInputObject') - - $SiteId = "root" - $SubSite = Get-MgSubSite -InputObject @{ SiteId = $SiteId; SiteId1 = "randomId" } - $SubSite | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite' - $SubSite | Should -HaveCount 1 - $SubSite.Id | Should -Be 'randomId' - $SubSite.WebUrl | Should -Be 'https://contoso.sharepoint.com/sites/site/subsiteA' - $SubSite.AdditionalProperties | Should -HaveCount 1 - } - } } diff --git a/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Recording.json b/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Recording.json new file mode 100644 index 00000000000..d40ac59cff1 --- /dev/null +++ b/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Recording.json @@ -0,0 +1,36 @@ +{ + "New-MgSiteListItem+[NoContext]+ShouldCreateSiteListItemWithFields+$POST+https://graph.microsoft.com/beta/sites/root/lists/listId/items+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/beta/sites/root/lists/listId/items", + "Content": "{\r\n \"fields\": {\r\n \"Title\": \"Test\"\r\n }\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "45" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "ETag": [ "\"973d312d-0eef-4c01-92c3-0bbfcb24b722,1\"" ], + "Location": [ "https://contosodev.sharepoint.com/_api/v2.0/sites/contosodev.sharepoint.com,e21e7ea3-cd7c-4efd-a3cb-b0c93e9c79e7,ecfa5b05-fdf4-4595-9bad-26378ce9b7f2/lists/listId/items/15" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "a104417e-3eb5-4b92-baae-77f5c11f217b" ], + "client-request-id": [ "a104417e-3eb5-4b92-baae-77f5c11f217b" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF0006CC06\"}}" ], + "OData-Version": [ "4.0" ], + "Date": [ "Fri, 03 Jun 2022 17:58:48 GMT" ] + }, + "ContentHeaders": { + "Content-Type": [ "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8" ], + "Content-Encoding": [ "gzip" ] + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#sites(\u0027root\u0027)/lists(\u0027listId\u0027)/items/$entity\",\"@odata.etag\":\"\\\"973d312d-0eef-4c01-92c3-0bbfcb24b722,1\\\"\",\"createdDateTime\":\"2022-06-03T17:58:49Z\",\"eTag\":\"\\\"973d312d-0eef-4c01-92c3-0bbfcb24b722,1\\\"\",\"id\":\"15\",\"lastModifiedDateTime\":\"2022-06-03T17:58:49Z\",\"webUrl\":\"https://contosodev.sharepoint.com/Lists/My%20List/15_.000\",\"createdBy\":{\"user\":{\"email\":\"User@contosodev.onmicrosoft.com\",\"id\":\"222a4aff-966a-4a62-b3d3-1b6ae2f81f4a\",\"displayName\":\"User User\"}},\"lastModifiedBy\":{\"application\":{\"id\":\"14d82eec-204b-4c2f-b7e8-296a70dab67e\",\"displayName\":\"Microsoft Graph PowerShell (Preview)\"},\"user\":{\"email\":\"User@contosodev.onmicrosoft.com\",\"id\":\"222a4aff-966a-4a62-b3d3-1b6ae2f81f4a\",\"displayName\":\"User User\"}},\"parentReference\":{\"siteId\":\"contosodev.sharepoint.com,e21e7ea3-cd7c-4efd-a3cb-b0c93e9c79e7,ecfa5b05-fdf4-4595-9bad-26378ce9b7f2\"},\"contentType\":{\"id\":\"0x010009E05387C7C8AC4D8407A2E88DFF538F0001E8E4E2710BBC42A695BA82E1C3BBE3\",\"name\":\"Item\"},\"fields@odata.context\":\"https://graph.microsoft.com/beta/$metadata#sites(\u0027root\u0027)/lists(\u0027listId\u0027)/items(\u002715\u0027)/fields/$entity\",\"fields\":{\"@odata.etag\":\"\\\"973d312d-0eef-4c01-92c3-0bbfcb24b722,1\\\"\",\"id\":\"15\",\"ContentType\":\"Item\",\"Title\":\"Test\",\"Modified\":\"2022-06-03T17:58:49Z\",\"Created\":\"2022-06-03T17:58:49Z\",\"AuthorLookupId\":\"11\",\"EditorLookupId\":\"11\",\"_UIVersionString\":\"1.0\",\"Attachments\":false,\"Edit\":\"\",\"LinkTitleNoMenu\":\"Test\",\"LinkTitle\":\"Test\",\"ItemChildCount\":\"0\",\"FolderChildCount\":\"0\",\"_ComplianceFlags\":\"\",\"_ComplianceTag\":\"\",\"_ComplianceTagWrittenTime\":\"\",\"_ComplianceTagUserId\":\"\",\"AppAuthorLookupId\":\"11\",\"AppEditorLookupId\":\"11\"}}" + } + } +} \ No newline at end of file diff --git a/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Tests.ps1 b/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Tests.ps1 index e5e524e6045..4c87c669d85 100644 --- a/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Tests.ps1 +++ b/src/Sites/Sites/test/v1.0-beta/New-MgSiteListItem.Tests.ps1 @@ -1,30 +1,56 @@ -$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' -if (-Not (Test-Path -Path $loadEnvPath)) { - $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' -} -. ($loadEnvPath) -$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgSiteListItem.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-MgSiteListItem.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 'beta' } -. ($mockingPath | Select-Object -First 1).FullName Describe 'New-MgSiteListItem' { - It 'CreateExpanded1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + BeforeAll { + $Mock.PushDescription('New-MgSiteListItem') + $siteId = "root" + $listId = "listId" + $fields = @{ + Title = "Test" + } } - It 'Create1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw - } + Context 'CreateExpanded' { + It 'Should create site list item with custom fields' { + $Mock.PushScenario('ShouldCreateSiteListItemWithFields') + # Redirect debug stream to variable. + $ListItem = New-MgSiteListItem -SiteId $siteId -ListId $listId -Fields $fields -Debug -Confirm:$false 5>&1 - It 'CreateViaIdentityExpanded1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + $ListItem.Fields.AdditionalProperties.Title | Should -Be $fields.Title + $HttpRequestLog = $ListItem | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"Title": "Test"*' + } } - It 'CreateViaIdentity1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + Context 'Create' { + It 'Should create site list item with custom fields' { + $Mock.PushScenario('ShouldCreateSiteListItemWithFields') + $params = @{ + Fields = $fields + } + # Redirect debug stream to variable. + $ListItem = New-MgSiteListItem -SiteId $siteId -ListId $listId -BodyParameter $params -Debug -Confirm:$false 5>&1 + + $ListItem.Fields.AdditionalProperties.Title | Should -Be $fields.Title + $HttpRequestLog = $ListItem | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"Title": "Test"*' + } } } diff --git a/src/Sites/Sites/test/v1.0/Get-MgSiteByPath.Tests.ps1 b/src/Sites/Sites/test/v1.0/Get-MgSiteByPath.Tests.ps1 index 5a1344cc0e9..d2bc97e464e 100644 --- a/src/Sites/Sites/test/v1.0/Get-MgSiteByPath.Tests.ps1 +++ b/src/Sites/Sites/test/v1.0/Get-MgSiteByPath.Tests.ps1 @@ -24,21 +24,21 @@ Describe 'Get-MgSiteByPath' { $Mock.PushDescription('Get-MgSiteByPath') } - Context 'Get3' { + Context 'Get2' { It 'ShouldFailToGetSiteByPath' { $Mock.PushScenario('ShouldFailToGetSiteByPath') $SiteId = "root" - { Get-MgSiteByPath -SiteId $SiteId -Path "randomPath" -ErrorAction Stop } | Should -Throw -ErrorId 'invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgSiteByPath_Get3' -ExpectedMessage 'Invalid request' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' + { Get-MgSiteByPath -SiteId $SiteId -Path "randomPath" -ErrorAction Stop } | Should -Throw -ErrorId 'invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgSiteByPath_Get2' -ExpectedMessage 'Invalid request' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' } } - Context 'GetViaIdentity3' { + Context 'GetViaIdentity2' { It 'ShouldFailToGetSiteByPathViaInputObject' { $Mock.PushScenario('ShouldFailToGetSiteByPathViaInputObject') $SiteId = "root" - { Get-MgSiteByPath -InputObject @{ SiteId = $SiteId; Path = "randomPath" } -ErrorAction Stop } | Should -Throw -ErrorId 'invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgSiteByPath_GetViaIdentity3' -ExpectedMessage 'Invalid request' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' + { Get-MgSiteByPath -InputObject @{ SiteId = $SiteId; Path = "randomPath" } -ErrorAction Stop } | Should -Throw -ErrorId 'invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgSiteByPath_GetViaIdentity2' -ExpectedMessage 'Invalid request' -ExceptionType 'Microsoft.Graph.PowerShell.Runtime.RestException' } } diff --git a/src/Sites/Sites/test/v1.0/Get-MgSubSite.Tests.ps1 b/src/Sites/Sites/test/v1.0/Get-MgSubSite.Tests.ps1 index 49238576f75..9d593753125 100644 --- a/src/Sites/Sites/test/v1.0/Get-MgSubSite.Tests.ps1 +++ b/src/Sites/Sites/test/v1.0/Get-MgSubSite.Tests.ps1 @@ -33,32 +33,4 @@ Describe 'Get-MgSubSite' { $SubSites.AdditionalProperties | Should -HaveCount 2 } } - - Context 'Get4' { - It 'ShouldGetASingleSubSite' { - $Mock.PushScenario('ShouldGetASingleSubSite') - - $SiteId = "root" - $SubSite = Get-MgSubSite -SiteId $SiteId -SiteId1 "randomId" - $SubSite | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite1' - $SubSite | Should -HaveCount 1 - $SubSite.Id | Should -Be 'randomId' - $SubSite.WebUrl | Should -Be 'https://contoso.sharepoint.com/sites/site/subsiteA' - $SubSite.AdditionalProperties | Should -HaveCount 1 - } - } - - Context 'GetViaIdentity4' { - It 'ShouldGetASingleSubSiteViaInputObject' { - $Mock.PushScenario('ShouldGetASingleSubSiteViaInputObject') - - $SiteId = "root" - $SubSite = Get-MgSubSite -InputObject @{ SiteId = $SiteId; SiteId1 = "randomId" } - $SubSite | Should -BeOfType -ExpectedType 'Microsoft.Graph.PowerShell.Models.MicrosoftGraphSite1' - $SubSite | Should -HaveCount 1 - $SubSite.Id | Should -Be 'randomId' - $SubSite.WebUrl | Should -Be 'https://contoso.sharepoint.com/sites/site/subsiteA' - $SubSite.AdditionalProperties | Should -HaveCount 1 - } - } } diff --git a/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Recording.json b/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Recording.json new file mode 100644 index 00000000000..1c8cdb4150b --- /dev/null +++ b/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Recording.json @@ -0,0 +1,36 @@ +{ + "New-MgSiteListItem+[NoContext]+ShouldCreateSiteListItemWithFields+$POST+https://graph.microsoft.com/v1.0/sites/root/lists/listId/items+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/v1.0/sites/root/lists/listId/items", + "Content": "{\r\n \"fields\": {\r\n \"Title\": \"Test\"\r\n }\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "45" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "ETag": [ "\"63bf1e50-f2cb-4ba5-a313-b86b405691a9,1\"" ], + "Location": [ "https://contoso.sharepoint.com/_api/v2.0/sites/contoso.sharepoint.com,e21e7ea3-cd7c-4efd-a3cb-b0c93e9c79e7,ecfa5b05-fdf4-4595-9bad-26378ce9b7f2/lists/listId/items/13" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "b5cb97c4-143a-406e-9acc-1e159d447cc3" ], + "client-request-id": [ "b5cb97c4-143a-406e-9acc-1e159d447cc3" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"MWH0EPF00070F96\"}}" ], + "OData-Version": [ "4.0" ], + "Date": [ "Fri, 03 Jun 2022 17:58:17 GMT" ] + }, + "ContentHeaders": { + "Content-Type": [ "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8" ], + "Content-Encoding": [ "gzip" ] + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#sites(\u0027root\u0027)/lists(\u0027listId\u0027)/items/$entity\",\"@odata.etag\":\"\\\"63bf1e50-f2cb-4ba5-a313-b86b405691a9,1\\\"\",\"createdDateTime\":\"2022-06-03T17:58:18Z\",\"eTag\":\"\\\"63bf1e50-f2cb-4ba5-a313-b86b405691a9,1\\\"\",\"id\":\"13\",\"lastModifiedDateTime\":\"2022-06-03T17:58:18Z\",\"webUrl\":\"https://contoso.sharepoint.com/Lists/My%20List/13_.000\",\"createdBy\":{\"user\":{\"email\":\"user@contoso.onmicrosoft.com\",\"id\":\"222a4aff-966a-4a62-b3d3-1b6ae2f81f4a\",\"displayName\":\"User User\"}},\"lastModifiedBy\":{\"application\":{\"id\":\"14d82eec-204b-4c2f-b7e8-296a70dab67e\",\"displayName\":\"Microsoft Graph PowerShell (Preview)\"},\"user\":{\"email\":\"user@contoso.onmicrosoft.com\",\"id\":\"222a4aff-966a-4a62-b3d3-1b6ae2f81f4a\",\"displayName\":\"User User\"}},\"parentReference\":{\"siteId\":\"contoso.sharepoint.com,e21e7ea3-cd7c-4efd-a3cb-b0c93e9c79e7,ecfa5b05-fdf4-4595-9bad-26378ce9b7f2\"},\"contentType\":{\"id\":\"0x010009E05387C7C8AC4D8407A2E88DFF538F0001E8E4E2710BBC42A695BA82E1C3BBE3\",\"name\":\"Item\"},\"fields@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#sites(\u0027root\u0027)/lists(\u0027listId\u0027)/items(\u002713\u0027)/fields/$entity\",\"fields\":{\"@odata.etag\":\"\\\"63bf1e50-f2cb-4ba5-a313-b86b405691a9,1\\\"\",\"id\":\"13\",\"ContentType\":\"Item\",\"Title\":\"Test\",\"Modified\":\"2022-06-03T17:58:18Z\",\"Created\":\"2022-06-03T17:58:18Z\",\"AuthorLookupId\":\"11\",\"EditorLookupId\":\"11\",\"_UIVersionString\":\"1.0\",\"Attachments\":false,\"Edit\":\"\",\"LinkTitleNoMenu\":\"Test\",\"LinkTitle\":\"Test\",\"ItemChildCount\":\"0\",\"FolderChildCount\":\"0\",\"_ComplianceFlags\":\"\",\"_ComplianceTag\":\"\",\"_ComplianceTagWrittenTime\":\"\",\"_ComplianceTagUserId\":\"\",\"AppAuthorLookupId\":\"11\",\"AppEditorLookupId\":\"11\"}}" + } + } +} \ No newline at end of file diff --git a/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Tests.ps1 b/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Tests.ps1 index 5d051c48dfa..8b0f112e281 100644 --- a/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Tests.ps1 +++ b/src/Sites/Sites/test/v1.0/New-MgSiteListItem.Tests.ps1 @@ -1,30 +1,56 @@ -$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' -if (-Not (Test-Path -Path $loadEnvPath)) { - $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' -} -. ($loadEnvPath) -$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgSiteListItem.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-MgSiteListItem.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-MgSiteListItem' { - It 'CreateExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + BeforeAll { + $Mock.PushDescription('New-MgSiteListItem') + $siteId = "root" + $listId = "listId" + $fields = @{ + Title = "Test" + } } - It 'Create' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw - } + Context 'CreateExpanded' { + It 'Should create site list item with custom fields' { + $Mock.PushScenario('ShouldCreateSiteListItemWithFields') + # Redirect debug stream to variable. + $ListItem = New-MgSiteListItem -SiteId $siteId -ListId $listId -Fields $fields -Debug -Confirm:$false 5>&1 - It 'CreateViaIdentityExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + $ListItem.Fields.AdditionalProperties.Title | Should -Be $fields.Title + $HttpRequestLog = $ListItem | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"Title": "Test"*' + } } - It 'CreateViaIdentity' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + Context 'Create' { + It 'Should create site list item with custom fields' { + $Mock.PushScenario('ShouldCreateSiteListItemWithFields') + $params = @{ + Fields = $fields + } + # Redirect debug stream to variable. + $ListItem = New-MgSiteListItem -SiteId $siteId -ListId $listId -BodyParameter $params -Debug -Confirm:$false 5>&1 + + $ListItem.Fields.AdditionalProperties.Title | Should -Be $fields.Title + $HttpRequestLog = $ListItem | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"Title": "Test"*' + } } } From fa69d5c7f7a2725165d8bda58aedb10599e9f8c1 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Fri, 3 Jun 2022 12:31:50 -0700 Subject: [PATCH 4/4] Add Identity.Signins Pester tests. --- ...ditionalAccessNamedLocation.Recording.json | 68 +++++++++++++++ ...tyConditionalAccessNamedLocation.Tests.ps1 | 84 +++++++++++++++---- ...ditionalAccessNamedLocation.Recording.json | 68 +++++++++++++++ ...tyConditionalAccessNamedLocation.Tests.ps1 | 84 +++++++++++++++---- src/readme.graph.md | 5 +- 5 files changed, 276 insertions(+), 33 deletions(-) create mode 100644 src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Recording.json create mode 100644 src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Recording.json diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Recording.json b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Recording.json new file mode 100644 index 00000000000..11ee01411aa --- /dev/null +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Recording.json @@ -0,0 +1,68 @@ +{ + "New-MgIdentityConditionalAccessNamedLocation+[NoContext]+ShouldCreateAnIpNamedLocation+$POST+https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations", + "Content": "{\r\n \"isTrusted\": false,\r\n \"ipRanges\": [\r\n {\r\n \"CidrAddress\": \"12.34.221.11/22\",\r\n \"@odata.type\": \"#microsoft.graph.iPv4CidrRange\"\r\n },\r\n {\r\n \"CidrAddress\": \"2001:0:9d38:90d6:0:0:0:0/63\",\r\n \"@odata.type\": \"#microsoft.graph.iPv6CidrRange\"\r\n }\r\n ],\r\n \"@odata.type\": \"#microsoft.graph.ipNamedLocation\",\r\n \"displayName\": \"Untrusted IP named location\"\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "385" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Location": [ "https://na.prod.graph.ipc.msidentity.com/conditionalAccess/namedLocations(\u0027013cca62-944c-462b-8fe7-8d51533b2ce3\u0027)" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "3301729e-ec41-4cbc-9ba4-ef367483c104" ], + "client-request-id": [ "3301729e-ec41-4cbc-9ba4-ef367483c104" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF00009118\"}}" ], + "OData-Version": [ "4.0" ], + "Date": [ "Fri, 03 Jun 2022 19:24:13 GMT" ] + }, + "ContentHeaders": { + "Content-Type": [ "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8" ], + "Content-Encoding": [ "gzip" ] + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#identity/conditionalAccess/namedLocations/$entity\",\"@odata.type\":\"#microsoft.graph.ipNamedLocation\",\"id\":\"013cca62-944c-462b-8fe7-8d51533b2ce3\",\"displayName\":\"Untrusted IP named location\",\"modifiedDateTime\":\"2022-06-03T19:24:12.9772062Z\",\"createdDateTime\":\"2022-06-03T19:24:12.9772062Z\",\"isTrusted\":false,\"ipRanges\":[{\"@odata.type\":\"#microsoft.graph.iPv4CidrRange\",\"cidrAddress\":\"12.34.221.11/22\"},{\"@odata.type\":\"#microsoft.graph.iPv6CidrRange\",\"cidrAddress\":\"2001:0:9d38:90d6:0:0:0:0/63\"}]}" + } + }, + "New-MgIdentityConditionalAccessNamedLocation+[NoContext]+ShouldCreateACountryNamedLocation+$POST+https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations", + "Content": "{\r\n \"countriesAndRegions\": [ \"US\", \"GB\" ],\r\n \"includeUnknownCountriesAndRegions\": true,\r\n \"@odata.type\": \"#microsoft.graph.countryNamedLocation\",\r\n \"displayName\": \"Named location with unknown countries and regions\"\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "221" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Location": [ "https://na.prod.graph.ipc.msidentity.com/conditionalAccess/namedLocations(\u00271aefaad3-f427-4c97-9683-fead95178e99\u0027)" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "92a311dd-5cc9-4756-b9cf-bbda241d2307" ], + "client-request-id": [ "92a311dd-5cc9-4756-b9cf-bbda241d2307" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF00009118\"}}" ], + "OData-Version": [ "4.0" ], + "Date": [ "Fri, 03 Jun 2022 19:24:15 GMT" ] + }, + "ContentHeaders": { + "Content-Type": [ "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8" ], + "Content-Encoding": [ "gzip" ] + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/beta/$metadata#identity/conditionalAccess/namedLocations/$entity\",\"@odata.type\":\"#microsoft.graph.countryNamedLocation\",\"id\":\"1aefaad3-f427-4c97-9683-fead95178e99\",\"displayName\":\"Named location with unknown countries and regions\",\"modifiedDateTime\":\"2022-06-03T19:24:14.6544147Z\",\"createdDateTime\":\"2022-06-03T19:24:14.6544147Z\",\"countriesAndRegions\":[\"US\",\"GB\"],\"includeUnknownCountriesAndRegions\":true,\"countryLookupMethod\":\"clientIpAddress\"}" + } + } +} \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 index aca87f8cd7b..81ab486e3d6 100644 --- a/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0-beta/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 @@ -1,22 +1,76 @@ -$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' -if (-Not (Test-Path -Path $loadEnvPath)) { - $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' -} -. ($loadEnvPath) -$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgIdentityConditionalAccessNamedLocation.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-MgIdentityConditionalAccessNamedLocation.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 'beta' } -. ($mockingPath | Select-Object -First 1).FullName Describe 'New-MgIdentityConditionalAccessNamedLocation' { - It 'CreateExpanded1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + BeforeAll { + $Mock.PushDescription('New-MgIdentityConditionalAccessNamedLocation') } - It 'Create1' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + Context 'Create' { + It 'Should create an ipNamedLocation' { + $Mock.PushScenario('ShouldCreateAnIpNamedLocation') + $params = @{ + "@odata.type" = "#microsoft.graph.ipNamedLocation" + DisplayName = "Untrusted IP named location" + IsTrusted = $false + IpRanges = @( + @{ + "@odata.type" = "#microsoft.graph.iPv4CidrRange" + CidrAddress = "12.34.221.11/22" + } + @{ + "@odata.type" = "#microsoft.graph.iPv6CidrRange" + CidrAddress = "2001:0:9d38:90d6:0:0:0:0/63" + } + ) + } + + # Redirect debug stream to variable. + $IpNamedLocation = New-MgIdentityConditionalAccessNamedLocation -BodyParameter $params -Debug -Confirm:$false 5>&1 + + $IpNamedLocation.DisplayName | Should -Be $params.DisplayName + $IpNamedLocation.AdditionalProperties.ipRanges | Should -HaveCount 2 + $HttpRequestLog = $IpNamedLocation | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"isTrusted": false*' + $HttpRequestLog.Message | Should -BeLikeExactly '*"ipRanges":*' + } + + It 'Should create a countryNamedLocation' { + $Mock.PushScenario('ShouldCreateACountryNamedLocation') + $params = @{ + "@odata.type" = "#microsoft.graph.countryNamedLocation" + DisplayName = "Named location with unknown countries and regions" + CountriesAndRegions = @( + "US" + "GB" + ) + IncludeUnknownCountriesAndRegions = $true + } + + # Redirect debug stream to variable. + $CountryNamedLocation = New-MgIdentityConditionalAccessNamedLocation -BodyParameter $params -Debug -Confirm:$false 5>&1 + + $CountryNamedLocation.DisplayName | Should -Be $params.DisplayName + $CountryNamedLocation.AdditionalProperties.countriesAndRegions | Should -HaveCount 2 + $HttpRequestLog = $CountryNamedLocation | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"includeUnknownCountriesAndRegions": true*' + $HttpRequestLog.Message | Should -BeLikeExactly '*"countriesAndRegions":*' + } } } diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Recording.json b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Recording.json new file mode 100644 index 00000000000..ace74af42e8 --- /dev/null +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Recording.json @@ -0,0 +1,68 @@ +{ + "New-MgIdentityConditionalAccessNamedLocation+[NoContext]+ShouldCreateAnIpNamedLocation+$POST+https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations", + "Content": "{\r\n \"isTrusted\": false,\r\n \"ipRanges\": [\r\n {\r\n \"CidrAddress\": \"12.34.221.11/22\",\r\n \"@odata.type\": \"#microsoft.graph.iPv4CidrRange\"\r\n },\r\n {\r\n \"CidrAddress\": \"2001:0:9d38:90d6:0:0:0:0/63\",\r\n \"@odata.type\": \"#microsoft.graph.iPv6CidrRange\"\r\n }\r\n ],\r\n \"@odata.type\": \"#microsoft.graph.ipNamedLocation\",\r\n \"displayName\": \"Untrusted IP named location\"\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "385" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Location": [ "https://na.prod.graph.ipc.msidentity.com/conditionalAccess/namedLocations(\u002700eabbed-3856-479e-8de4-c2c4bd1768c1\u0027)" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "17f9929b-59d6-480a-aaeb-c9e121e93c7b" ], + "client-request-id": [ "17f9929b-59d6-480a-aaeb-c9e121e93c7b" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF00009119\"}}" ], + "OData-Version": [ "4.0" ], + "Date": [ "Fri, 03 Jun 2022 19:23:59 GMT" ] + }, + "ContentHeaders": { + "Content-Type": [ "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8" ], + "Content-Encoding": [ "gzip" ] + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#identity/conditionalAccess/namedLocations/$entity\",\"@odata.type\":\"#microsoft.graph.ipNamedLocation\",\"id\":\"00eabbed-3856-479e-8de4-c2c4bd1768c1\",\"displayName\":\"Untrusted IP named location\",\"modifiedDateTime\":\"2022-06-03T19:23:59.6882138Z\",\"createdDateTime\":\"2022-06-03T19:23:59.6882138Z\",\"isTrusted\":false,\"ipRanges\":[{\"@odata.type\":\"#microsoft.graph.iPv4CidrRange\",\"cidrAddress\":\"12.34.221.11/22\"},{\"@odata.type\":\"#microsoft.graph.iPv6CidrRange\",\"cidrAddress\":\"2001:0:9d38:90d6:0:0:0:0/63\"}]}" + } + }, + "New-MgIdentityConditionalAccessNamedLocation+[NoContext]+ShouldCreateACountryNamedLocation+$POST+https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations+1": { + "Request": { + "Method": "POST", + "RequestUri": "https://graph.microsoft.com/v1.0/identity/conditionalAccess/namedLocations", + "Content": "{\r\n \"countriesAndRegions\": [ \"US\", \"GB\" ],\r\n \"includeUnknownCountriesAndRegions\": true,\r\n \"@odata.type\": \"#microsoft.graph.countryNamedLocation\",\r\n \"displayName\": \"Named location with unknown countries and regions\"\r\n}", + "Headers": { + }, + "ContentHeaders": { + "Content-Type": [ "application/json" ], + "Content-Length": [ "221" ] + } + }, + "Response": { + "StatusCode": 201, + "Headers": { + "Cache-Control": [ "no-cache" ], + "Transfer-Encoding": [ "chunked" ], + "Location": [ "https://na.prod.graph.ipc.msidentity.com/conditionalAccess/namedLocations(\u00271c14a6aa-4e2a-44b4-8ba8-ada756528559\u0027)" ], + "Vary": [ "Accept-Encoding" ], + "Strict-Transport-Security": [ "max-age=31536000" ], + "request-id": [ "80c7c0c1-dce3-459c-94f1-2156fbd1540f" ], + "client-request-id": [ "80c7c0c1-dce3-459c-94f1-2156fbd1540f" ], + "x-ms-ags-diagnostic": [ "{\"ServerInfo\":{\"DataCenter\":\"West US 2\",\"Slice\":\"E\",\"Ring\":\"1\",\"ScaleUnit\":\"001\",\"RoleInstance\":\"MW2PEPF00009119\"}}" ], + "OData-Version": [ "4.0" ], + "Date": [ "Fri, 03 Jun 2022 19:24:01 GMT" ] + }, + "ContentHeaders": { + "Content-Type": [ "application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8" ], + "Content-Encoding": [ "gzip" ] + }, + "Content": "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#identity/conditionalAccess/namedLocations/$entity\",\"@odata.type\":\"#microsoft.graph.countryNamedLocation\",\"id\":\"1c14a6aa-4e2a-44b4-8ba8-ada756528559\",\"displayName\":\"Named location with unknown countries and regions\",\"modifiedDateTime\":\"2022-06-03T19:24:01.5082252Z\",\"createdDateTime\":\"2022-06-03T19:24:01.5082252Z\",\"countriesAndRegions\":[\"US\",\"GB\"],\"includeUnknownCountriesAndRegions\":true,\"countryLookupMethod\":\"clientIpAddress\"}" + } + } +} \ No newline at end of file diff --git a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 index 24757097de4..a1f7d6920fc 100644 --- a/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 +++ b/src/Identity.SignIns/Identity.SignIns/test/v1.0/New-MgIdentityConditionalAccessNamedLocation.Tests.ps1 @@ -1,22 +1,76 @@ -$loadEnvPath = Join-Path $PSScriptRoot 'loadEnv.ps1' -if (-Not (Test-Path -Path $loadEnvPath)) { - $loadEnvPath = Join-Path $PSScriptRoot '..\loadEnv.ps1' -} -. ($loadEnvPath) -$TestRecordingFile = Join-Path $PSScriptRoot 'New-MgIdentityConditionalAccessNamedLocation.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-MgIdentityConditionalAccessNamedLocation.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-MgIdentityConditionalAccessNamedLocation' { - It 'CreateExpanded' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + BeforeAll { + $Mock.PushDescription('New-MgIdentityConditionalAccessNamedLocation') } - It 'Create' -skip { - { throw [System.NotImplementedException] } | Should -Not -Throw + Context 'Create' { + It 'Should create an ipNamedLocation' { + $Mock.PushScenario('ShouldCreateAnIpNamedLocation') + $params = @{ + "@odata.type" = "#microsoft.graph.ipNamedLocation" + DisplayName = "Untrusted IP named location" + IsTrusted = $false + IpRanges = @( + @{ + "@odata.type" = "#microsoft.graph.iPv4CidrRange" + CidrAddress = "12.34.221.11/22" + } + @{ + "@odata.type" = "#microsoft.graph.iPv6CidrRange" + CidrAddress = "2001:0:9d38:90d6:0:0:0:0/63" + } + ) + } + + # Redirect debug stream to variable. + $IpNamedLocation = New-MgIdentityConditionalAccessNamedLocation -BodyParameter $params -Debug -Confirm:$false 5>&1 + + $IpNamedLocation.DisplayName | Should -Be $params.DisplayName + $IpNamedLocation.AdditionalProperties.ipRanges | Should -HaveCount 2 + $HttpRequestLog = $IpNamedLocation | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"isTrusted": false*' + $HttpRequestLog.Message | Should -BeLikeExactly '*"ipRanges":*' + } + + It 'Should create a countryNamedLocation' { + $Mock.PushScenario('ShouldCreateACountryNamedLocation') + $params = @{ + "@odata.type" = "#microsoft.graph.countryNamedLocation" + DisplayName = "Named location with unknown countries and regions" + CountriesAndRegions = @( + "US" + "GB" + ) + IncludeUnknownCountriesAndRegions = $true + } + + # Redirect debug stream to variable. + $CountryNamedLocation = New-MgIdentityConditionalAccessNamedLocation -BodyParameter $params -Debug -Confirm:$false 5>&1 + + $CountryNamedLocation.DisplayName | Should -Be $params.DisplayName + $CountryNamedLocation.AdditionalProperties.countriesAndRegions | Should -HaveCount 2 + $HttpRequestLog = $CountryNamedLocation | Where-Object { $_ -Like "*HTTP REQUEST*" } + $HttpRequestLog.Message | Should -BeLikeExactly '*"includeUnknownCountriesAndRegions": true*' + $HttpRequestLog.Message | Should -BeLikeExactly '*"countriesAndRegions":*' + } } } diff --git a/src/readme.graph.md b/src/readme.graph.md index 81964b3aeb2..5ce971e170c 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -511,12 +511,11 @@ directive: let classRegex = /((\s*)public\s*partial\s*class\s*MicrosoftGraph(NamedLocation).*\s.*\s*\{)/gm if($.match(classRegex)) { - $ = $.replace(classRegex, `$1$2${toFirstUpperImplementation}`) - let toFirstUpperImplementation = 'internal string ToFirstCharacterLowerCase(string text) => System.String.IsNullOrEmpty(text) ? text : $"{char.ToLowerInvariant(text[0])}{text.Substring(1)}";' + $ = $.replace(classRegex, `$1$2${toFirstUpperImplementation}`) let directoryKeyRegex = /\.Add\((\s*property\.Key\.ToString\(\))/gm - $ = $.replace(directoryKeyRegex, '$1(ToFirstCharacterLowerCase($2)') + $ = $.replace(directoryKeyRegex, '.Add(ToFirstCharacterLowerCase($1)') } return $;