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 = " CosmosDBResourceGroup2"
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 = " cosmosdb670"
26+
27+ # use an existing account with the following information for Account Update Operations
28+ $cosmosDBExistingAccountName = " dbaccount27"
29+ $existingResourceGroupName = " CosmosDBResourceGroup27"
30+
31+ $ipRangeFilter = " 192.168.0.1"
32+ $tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
33+
34+ $cosmosDBAccount = New-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - Location $location - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork - EnableMultipleWriteLocations - EnableAutomaticFailover - ApiKind " MongoDB"
35+ do
36+ {
37+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $cosmosDBAccountName
38+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
39+
40+ Assert-AreEqual $cosmosDBAccountName $cosmosDBAccount.Name
41+ Assert-AreEqual " BoundedStaleness" $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
42+ Assert-AreEqual 10 $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
43+ Assert-AreEqual 20 $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
44+ Assert-AreEqual $ipRangeFilter $cosmosDBAccount.IpRangeFilter
45+ Assert-AreEqual $cosmosDBAccount.EnableAutomaticFailover 1
46+ Assert-AreEqual $cosmosDBAccount.EnableMultipleWriteLocations 1
47+ Assert-AreEqual $cosmosDBAccount.IsVirtualNetworkFilterEnabled 1
48+
49+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
50+ do
51+ {
52+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
53+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
54+
55+ Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
56+ Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
57+ Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
58+ Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
59+ Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
60+ Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
61+ Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
62+
63+ $cosmosDBAccountKey = Get-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname
64+ Assert-NotNull $cosmosDBAccountKey
65+
66+ $cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname - Type " ConnectionStrings"
67+ Assert-NotNull $cosmosDBAccountConnectionStrings
68+
69+ $cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname - Type " ReadOnlyKeys"
70+ Assert-NotNull $cosmosDBAccountReadOnlyKeys
71+
72+ $RegeneratedKey = New-AzCosmosDBAccountKey - Name $cosmosDBAccountName - ResourceGroupName $rgname - KeyKind " primary"
73+ Assert-NotNull $RegeneratedKey
74+
75+ $IsAccountDeleted = Remove-AzCosmosDBAccount - Name $cosmosDBAccountName - ResourceGroupName $rgName - PassThru
76+ Assert-AreEqual $IsAccountDeleted true
77+ }
78+
79+ function Test-AccountRelatedCmdletsUsingRid
80+ {
81+ $FailoverPolicy = " UK West" , " East US" , " UK South" , " South India"
82+ $locationlist2 = " UK South"
83+
84+ # use an existing account with the following properties
85+ $cosmosDBExistingAccountName = " dbaccount27"
86+ $existingResourceGroupName = " CosmosDBResourceGroup27"
87+
88+ $ipRangeFilter = " 192.168.0.1"
89+ $tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
90+
91+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
92+ $cosmosDBAccountByRid = Get-AzCosmosDBAccount - ResourceId $cosmosDBAccount.Id
93+
94+ Assert-AreEqual $cosmosDBAccountByRid.Name $cosmosDBAccount.Name
95+ Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.DefaultConsistencyLevel $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
96+ Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxIntervalInSeconds $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
97+ Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxStalenessPrefix $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
98+ Assert-AreEqual $cosmosDBAccountByRid.IpRangeFilter $cosmosDBAccount.IpRangeFilter
99+ Assert-AreEqual $cosmosDBAccountByRid.EnableAutomaticFailover $cosmosDBAccount.EnableAutomaticFailover
100+ Assert-AreEqual $cosmosDBAccountByRid.EnableMultipleWriteLocations $cosmosDBAccount.EnableMultipleWriteLocations
101+ Assert-AreEqual $cosmosDBAccountByRid.IsVirtualNetworkFilterEnabled $cosmosDBAccount.IsVirtualNetworkFilterEnabled
102+
103+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - ResourceId $cosmosDBAccount.Id - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
104+ do
105+ {
106+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
107+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
108+
109+ Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
110+ Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
111+ Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
112+ Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
113+ Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
114+ Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
115+ Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
116+
117+ $cosmosDBAccountKey = Get-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id
118+ Assert-NotNull $cosmosDBAccountKey
119+
120+ $cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id - Type " ConnectionStrings"
121+ Assert-NotNull $cosmosDBAccountConnectionStrings
122+
123+ $cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id - Type " ReadOnlyKeys"
124+ Assert-NotNull $cosmosDBAccountReadOnlyKeys
125+
126+ $RegeneratedKey = New-AzCosmosDBAccountKey - ResourceId $cosmosDBAccount.Id - KeyKind " secondaryReadonly"
127+ Assert-NotNull $RegeneratedKey
128+ }
129+
130+ function Test-AccountRelatedCmdletsUsingObject
131+ {
132+ # use an existing account with the following properties
133+ $cosmosDBExistingAccountName = " dbaccount27"
134+ $existingResourceGroupName = " CosmosDBResourceGroup27"
135+
136+ $ipRangeFilter = " 192.168.0.1"
137+ $tags = @ { name = " test" ; Shape = " Square" ; Color = " Blue" }
138+
139+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
140+
141+ $updatedCosmosDBAccount = Update-AzCosmosDBAccount - InputObject $cosmosDBAccount - DefaultConsistencyLevel " BoundedStaleness" - MaxStalenessIntervalInSeconds 10 - MaxStalenessPrefix 20 - IpRangeFilter $ipRangeFilter - Tag $tags - EnableVirtualNetwork 1 - EnableAutomaticFailover 1
142+ do
143+ {
144+ $updatedCosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $existingResourceGroupName - Name $cosmosDBExistingAccountName
145+ } while ($cosmosDBAccount.ProvisioningState -ne " Succeeded" )
146+
147+ Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
148+ Assert-AreEqual " BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
149+ Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
150+ Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
151+ Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
152+ Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
153+ Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1
154+
155+ $cosmosDBAccountKey = Get-AzCosmosDBAccountKey - InputObject $cosmosDBAccount
156+ Assert-NotNull $cosmosDBAccountKey
157+
158+ $cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey - InputObject $cosmosDBAccount - Type " ConnectionStrings"
159+ Assert-NotNull $cosmosDBAccountConnectionStrings
160+
161+ $cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey - InputObject $cosmosDBAccount - Type " ReadOnlyKeys"
162+ Assert-NotNull $cosmosDBAccountReadOnlyKeys
163+
164+ $RegeneratedKey = New-AzCosmosDBAccountKey - InputObject $cosmosDBAccount - KeyKind " primaryReadonly"
165+ Assert-NotNull $RegeneratedKey
166+
167+ $IsAccountDeleted = Remove-AzCosmosDBAccount - InputObject $cosmosDBAccount - PassThru
168+ Assert-AreEqual $IsAccountDeleted true
169+ }
0 commit comments