1+ # ----------------------------------------------------------------------------------
2+ #
3+ # Copyright Microsoft Corporation
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ # Unless required by applicable law or agreed to in writing, software
9+ # distributed under the License is distributed on an "AS IS" BASIS,
10+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+ # See the License for the specific language governing permissions and
12+ # limitations under the License.
13+ # ----------------------------------------------------------------------------------
14+
15+ function Test-AccountRelatedCmdlets
16+ {
17+ $rgName = " CosmosDBResourceGroup1"
18+ $location = " East US"
19+ $locationlist = " East US" , " West US"
20+ $locationlist2 = " East US" , " UK South" , " UK West" , " South India"
21+ $locationlist3 = " West US" , " East US"
22+
23+ $resourceGroup = New-AzResourceGroup - ResourceGroupName $rgName - Location $location
24+
25+ $cosmosDBAccountName = " cosmosdb67127712"
26+
27+ $cosmosDBExistingAccountName = " dbaccount27"
28+ $existingResourceGroupName = " CosmosDBResourceGroup27"
29+
30+ $ipRangeFilter = " 192.168.0.1"
31+ $tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
32+
33+ $cosmosDBAccount = New-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - Location $location - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork - EnableMultipleWriteLocations - EnableAutomaticFailover - ApiKind " MongoDB"
34+ do
35+ {
36+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
37+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
38+
39+ Assert-AreEqual $cosmosDBAccountName $cosmosDBAccount.Name
40+ Assert-AreEqual " BoundedStaleness" $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
41+ Assert-AreEqual 10 $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
42+ Assert-AreEqual 20 $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
43+ Assert-AreEqual $ipRangeFilter $cosmosDBAccount.IpRangeFilter
44+ Assert-AreEqual $cosmosDBAccount.EnableAutomaticFailover 1
45+ Assert-AreEqual $cosmosDBAccount.EnableMultipleWriteLocations 1
46+ Assert-AreEqual $cosmosDBAccount.IsVirtualNetworkFilterEnabled 1
47+
48+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
49+ do
50+ {
51+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
52+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
53+
54+ Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
55+ Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
56+ Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
57+ Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
58+ Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
59+ Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
60+ Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
61+
62+ $cosmosDBAccountKey = Get-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname
63+ Assert-NotNull $cosmosDBAccountKey
64+
65+ $cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname - Type " ConnectionStrings"
66+ Assert-NotNull $cosmosDBAccountConnectionStrings
67+
68+ $cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname - Type " ReadOnlyKeys"
69+ Assert-NotNull $cosmosDBAccountReadOnlyKeys
70+
71+ $IsKeyRegenerated = New-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname - KeyKind " primary" - PassThru
72+ Assert-AreEqual $IsKeyRegenerated true
73+
74+ $IsAccountDeleted = Remove-AzCosmosDBAccount - Name $cosmosDBAccountName - ResourceGroupName $rgName - PassThru
75+ Assert-AreEqual $IsAccountDeleted true
76+ }
77+
78+ function Test-AccountRelatedCmdletsUsingRid
79+ {
80+ $FailoverPolicy = " UK West" , " East US" , " UK South" , " South India"
81+ $locationlist2 = " UK South"
82+
83+ $cosmosDBExistingAccountName = " dbaccount27"
84+ $existingResourceGroupName = " CosmosDBResourceGroup27"
85+
86+ $ipRangeFilter = " 192.168.0.1"
87+ $tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
88+
89+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
90+ $cosmosDBAccountByRid = Get-AzCosmosDBAccount - ResourceId $cosmosDBAccount.Id
91+
92+ Assert-AreEqual $cosmosDBAccountByRid.Name $cosmosDBAccount.Name
93+ Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.DefaultConsistencyLevel $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
94+ Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxIntervalInSeconds $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
95+ Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxStalenessPrefix $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
96+ Assert-AreEqual $cosmosDBAccountByRid.IpRangeFilter $cosmosDBAccount.IpRangeFilter
97+ Assert-AreEqual $cosmosDBAccountByRid.EnableAutomaticFailover $cosmosDBAccount.EnableAutomaticFailover
98+ Assert-AreEqual $cosmosDBAccountByRid.EnableMultipleWriteLocations $cosmosDBAccount.EnableMultipleWriteLocations
99+ Assert-AreEqual $cosmosDBAccountByRid.IsVirtualNetworkFilterEnabled $cosmosDBAccount.IsVirtualNetworkFilterEnabled
100+
101+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceId $cosmosDBAccount.Id - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
102+ do
103+ {
104+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
105+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
106+
107+ Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
108+ Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
109+ Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
110+ Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
111+ Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
112+ Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
113+ Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
114+
115+ $cosmosDBAccountKey = Get-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id
116+ Assert-NotNull $cosmosDBAccountKey
117+
118+ $cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id - Type " ConnectionStrings"
119+ Assert-NotNull $cosmosDBAccountConnectionStrings
120+
121+ $cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id - Type " ReadOnlyKeys"
122+ Assert-NotNull $cosmosDBAccountReadOnlyKeys
123+
124+ $IsKeyRegenerated = New-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id - KeyKind " primary" - PassThru
125+ Assert-AreEqual $IsKeyRegenerated true
126+ }
127+
128+ function Test-AccountRelatedCmdletsUsingObject
129+ {
130+ $cosmosDBExistingAccountName = " dbaccount27"
131+ $existingResourceGroupName = " CosmosDBResourceGroup27"
132+
133+ $ipRangeFilter = " 192.168.0.1"
134+ $tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
135+
136+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
137+
138+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - InputObject $cosmosDBAccount - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
139+ do
140+ {
141+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
142+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
143+
144+ Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
145+ Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
146+ Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
147+ Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
148+ Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
149+ Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
150+ Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
151+
152+ $cosmosDBAccountKey = Get-AzCosmosDBAccountKey - InputObject $cosmosDBAccount
153+ Assert-NotNull $cosmosDBAccountKey
154+
155+ $cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey - InputObject $cosmosDBAccount - Type " ConnectionStrings"
156+ Assert-NotNull $cosmosDBAccountConnectionStrings
157+
158+ $cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey - InputObject $cosmosDBAccount - Type " ReadOnlyKeys"
159+ Assert-NotNull $cosmosDBAccountReadOnlyKeys
160+
161+ $IsKeyRegenerated = New-AzCosmosDBAccountKey - InputObject $cosmosDBAccount - KeyKind " primary" - PassThru
162+ Assert-AreEqual $IsKeyRegenerated true
163+
164+ $IsAccountDeleted = Remove-AzCosmosDBAccount - InputObject $cosmosDBAccount - PassThru
165+ Assert-AreEqual $IsAccountDeleted true
166+ }
0 commit comments