@@ -31,6 +31,7 @@ InModuleScope $ProjectName {
3131 $script :testBaseUri = ' documents.contoso.com'
3232 $script :testBaseUriAzureCloud = ' documents.azure.com'
3333 $script :testBaseUriAzureUsGov = ' documents.azure.us'
34+ $script :testBaseUriAzureChinaCloud = ' documents.azure.cn'
3435 $script :testDate = (Get-Date - Year 2017 - Month 11 - Day 29 - Hour 10 - Minute 45 - Second 10 )
3536 $script :testUniversalDate = ' Tue, 28 Nov 2017 21:45:10 GMT'
3637 $script :testContext = [CosmosDb.Context ] @ {
@@ -261,6 +262,30 @@ console.log("done");
261262 }
262263 }
263264
265+ Context ' When called with Account and Environment AzureChinaCloud parameters' {
266+ $script :result = $null
267+
268+ It ' Should not throw exception' {
269+ $newCosmosDbContextParameters = @ {
270+ Account = $script :testAccount
271+ Database = $script :testDatabase
272+ Key = $script :testKeySecureString
273+ KeyType = ' master'
274+ Environment = ' AzureChinaCloud'
275+ }
276+
277+ { $script :result = New-CosmosDbContext @newCosmosDbContextParameters } | Should -Not - Throw
278+ }
279+
280+ It ' Should return expected result' {
281+ $script :result.Account | Should - Be $script :testAccount
282+ $script :result.Database | Should - Be $script :testDatabase
283+ $script :result.Key | Should - Be $script :testKeySecureString
284+ $script :result.KeyType | Should - Be ' master'
285+ $script :result.BaseUri | Should - Be (' https://{0}.{1}/' -f $script :testAccount , $script :testBaseUriAzureChinaCloud )
286+ }
287+ }
288+
264289 Context ' When called with Account parameters and Back-off Policy' {
265290 $script :result = $null
266291
@@ -375,6 +400,46 @@ console.log("done");
375400 }
376401 }
377402
403+ Context ' When called with AzureAccount and Environment AzureChinaCloud parameters and not connected to Azure and PrimaryMasterKey requested' {
404+ $script :result = $null
405+
406+ Mock - CommandName Get-AzContext - MockWith { throw }
407+ Mock - CommandName Connect-AzAccount
408+ Mock `
409+ - CommandName Get-CosmosDbAccountMasterKey `
410+ - MockWith { $script :testKeySecureString }
411+
412+ It ' Should not throw exception' {
413+ $newCosmosDbContextParameters = @ {
414+ Account = $script :testAccount
415+ Database = $script :testDatabase
416+ ResourceGroupName = $script :testResourceGroupName
417+ MasterKeyType = ' PrimaryMasterKey'
418+ Environment = ' AzureChinaCloud'
419+ }
420+
421+ { $script :result = New-CosmosDbContext @newCosmosDbContextParameters } | Should -Not - Throw
422+ }
423+
424+ It ' Should return expected result' {
425+ $script :result.Account | Should - Be $script :testAccount
426+ $script :result.Database | Should - Be $script :testDatabase
427+ $script :result.KeyType | Should - Be ' master'
428+ $script :result.Key | Convert-CosmosDbSecureStringToString | Should - Be $script :testKey
429+ $script :result.BaseUri | Should - Be (' https://{0}.{1}/' -f $script :testAccount , $script :testBaseUriAzureChinaCloud )
430+ }
431+
432+ It ' Should call expected mocks' {
433+ Assert-MockCalled - CommandName Get-AzContext - Exactly - Times 1
434+ Assert-MockCalled - CommandName Connect-AzAccount `
435+ - ParameterFilter { $Environment -eq ' AzureChinaCloud' } `
436+ - Exactly - Times 1
437+ Assert-MockCalled - CommandName Get-CosmosDbAccountMasterKey `
438+ - ParameterFilter { $MasterKeyType -eq ' PrimaryMasterKey' } `
439+ - Exactly - Times 1
440+ }
441+ }
442+
378443 Context ' When called with AzureAccount parameters and connected to Azure' {
379444 $script :result = $null
380445
@@ -571,6 +636,25 @@ console.log("done");
571636 $script :result.ToString () | Should - Be (' https://{0}.{1}/' -f $script :testAccount , $script :testBaseUriAzureUsGov )
572637 }
573638 }
639+
640+ Context ' When called with Account and AzureChinaCloud Environment parameters' {
641+ $script :result = $null
642+
643+ It ' Should not throw exception' {
644+ $GetCosmosDbUriParameters = @ {
645+ Account = $script :testAccount
646+ Environment = [CosmosDb.Environment ]::AzureChinaCloud
647+ Verbose = $true
648+ }
649+
650+ { $script :result = Get-CosmosDbUri @GetCosmosDbUriParameters } | Should -Not - Throw
651+ }
652+
653+ It ' Should return expected result' {
654+ $script :result | Should - BeOfType uri
655+ $script :result.ToString () | Should - Be (' https://{0}.{1}/' -f $script :testAccount , $script :testBaseUriAzureChinaCloud )
656+ }
657+ }
574658 }
575659
576660 Describe ' ConvertTo-CosmosDbTokenDateString' - Tag ' Unit' {
0 commit comments