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
+ . SYNOPSIS
16
+ Gets and removes custom domain with running endpoint.
17
+ #>
18
+
19
+ function Test-GremlinOperationsCmdlets
20
+ {
21
+ $AccountName = " db1002"
22
+ $rgName = " CosmosDBResourceGroup2510"
23
+ $DatabaseName = " dbName"
24
+ $GraphName = " graph1"
25
+
26
+ $PartitionKeyPathValue = " /foo"
27
+ $PartitionKeyKindValue = " Hash"
28
+
29
+ $NewDatabase = Set-AzCosmosDBGremlinDatabase - AccountName $AccountName - ResourceGroupName $rgName - Name $DatabaseName
30
+ Assert-AreEqual $NewDatabase.Name $DatabaseName
31
+
32
+ # Indexing Policy Creation
33
+ $ipath1 = New-AzCosmosDBGremlinIncludedPathIndex - DataType String - Precision -1 - Kind Hash
34
+ $ipath2 = New-AzCosmosDBGremlinIncludedPathIndex - DataType String - Precision -1 - Kind Hash
35
+ $IncludedPath = New-AzCosmosDBGremlinIncludedPath - Path " /*" - Index $ipath1 , $ipath2
36
+ $SpatialSpec = New-AzCosmosDBGremlinSpatialSpec - Path " /mySpatialPath/*" - Type " Point" , " LineString" , " Polygon" , " MultiPolygon"
37
+ $cp1 = New-AzCosmosDBGremlinCompositePath - Path " /abc" - Order Ascending
38
+ $cp2 = New-AzCosmosDBGremlinCompositePath - Path " /aberc" - Order Descending
39
+ $CompositePaths = (($cp1 , $cp2 ), ($cp2 , $cp1 ))
40
+
41
+ $IndexingPolicy = New-AzCosmosDBGremlinIndexingPolicy - IncludedPath $IncludedPath - SpatialSpec $SpatialSpec - CompositePath $CompositePaths - ExcludedPath " /myPathToNotIndex/*" - Automatic 1 - IndexingMode Consistent
42
+
43
+ # UniqueKey Creation
44
+ $p1 = New-AzCosmosDBGremlinUniqueKey - Path " /myUniqueKey3"
45
+ $p2 = New-AzCosmosDBGremlinUniqueKey - Path " /myUniqueKey4"
46
+ $p3 = New-AzCosmosDBGremlinUniqueKey - Path " /myUniqueKey2"
47
+ $p4 = New-AzCosmosDBGremlinUniqueKey - Path " /myUniqueKey1"
48
+
49
+ $uk1 = New-AzCosmosDBGremlinUniqueKeyPolicy - UniqueKey $p1 , $p2 , $p3 , $p4
50
+
51
+ $NewGraph = Set-AzCosmosDBGremlinGraph - AccountName $AccountName - ResourceGroupName $rgName - DatabaseName $DatabaseName - Name $GraphName - PartitionKeyPath $PartitionKeyPathValue - PartitionKeyKind $PartitionKeyKindValue - IndexingPolicy $IndexingPolicy - UniqueKeyPolicy $uk1
52
+ Assert-AreEqual $NewGraph.Name $GraphName
53
+ Assert-AreEqual $NewGraph.Resource.IndexingPolicy.Automatic $IndexingPolicy.Automatic
54
+ Assert-AreEqual $NewGraph.Resource.IndexingPolicy.IndexingMode $IndexingPolicy.IndexingMode
55
+ Assert-AreEqual $NewGraph.Resource.IndexingPolicy.IncludedPath.Path $IndexingPolicy.IncludedPath.Path
56
+ Assert-AreEqual $NewGraph.Resource.IndexingPolicy.CompositeIndexes.Count 2
57
+ Assert-AreEqual $NewGraph.Resource.IndexingPolicy.SpatialIndexes.Path $SpatialSpec.Path
58
+ Assert-AreEqual $NewGraph.Resource.UniqueKeyPolicy.UniqueKeys.Count 4
59
+
60
+ $Database = Get-AzCosmosDBGremlinDatabase - AccountName $AccountName - ResourceGroupName $rgName - Name $DatabaseName
61
+ Assert-AreEqual $NewDatabase.Id $Database.Id
62
+ Assert-AreEqual $NewDatabase.Name $Database.Name
63
+ Assert-AreEqual $NewDatabase.Resource.Id $Database.Resource.Id
64
+ Assert-AreEqual $NewDatabase.Resource._rid $Database.Resource._rid
65
+ Assert-AreEqual $NewDatabase.Resource._ts $Database.Resource._ts
66
+ Assert-AreEqual $NewDatabase.Resource._etag $Database.Resource._etag
67
+
68
+ $Graph = Get-AzCosmosDBGremlinGraph - AccountName $AccountName - ResourceGroupName $rgName - DatabaseName $DatabaseName - Name $GraphName
69
+ Assert-AreEqual $NewGraph.Id $Graph.Id
70
+ Assert-AreEqual $NewGraph.Name $Graph.Name
71
+ Assert-AreEqual $NewGraph.GremlinGraphGetResultsId $Graph.GremlinGraphGetResultsId
72
+ Assert-AreEqual $NewGraph._rid $Graph._rid
73
+ Assert-AreEqual $NewGraph._ts $Graph._ts
74
+ Assert-AreEqual $NewGraph._etag $Graph._etag
75
+
76
+ $ListGraphs = Get-AzCosmosDBGremlinGraph - AccountName $AccountName - ResourceGroupName $rgName - DatabaseName $DatabaseName
77
+ Assert-NotNull ($ListGraphs )
78
+
79
+ $ListDatabases = Get-AzCosmosDBGremlinDatabase - AccountName $AccountName - ResourceGroupName $rgName
80
+ Assert-NotNull ($ListDatabases )
81
+
82
+ $IsGraphRemoved = Remove-AzCosmosDBGremlinGraph - AccountName $AccountName - ResourceGroupName $rgName - DatabaseName $DatabaseName - Name $GraphName - PassThru
83
+ Assert-AreEqual $IsGraphRemoved true
84
+
85
+ $IsDatabaseRemoved = Remove-AzCosmosDBGremlinDatabase - AccountName $AccountName - ResourceGroupName $rgName - Name $DatabaseName - PassThru
86
+ Assert-AreEqual $IsDatabaseRemoved true
87
+ }
88
+
89
+ function Test-GremlinOperationsCmdletsUsingInputObject
90
+ {
91
+ $AccountName = " db1002"
92
+ $rgName = " CosmosDBResourceGroup2510"
93
+ $DatabaseName = " dbName2"
94
+ $GraphName = " graph1"
95
+
96
+ $PartitionKeyPathValue = " /foo"
97
+ $PartitionKeyKindValue = " Hash"
98
+
99
+ $cosmosDBAccount = Get-AzCosmosDBAccount - ResourceGroupName $rgName - Name $AccountName
100
+
101
+ $NewDatabase = Set-AzCosmosDBGremlinDatabase - InputObject $cosmosDBAccount - Name $DatabaseName
102
+ Assert-AreEqual $NewDatabase.Name $DatabaseName
103
+
104
+ $NewGraph = Set-AzCosmosDBGremlinGraph - InputObject $NewDatabase - Name $GraphName - PartitionKeyPath $PartitionKeyPathValue - PartitionKeyKind $PartitionKeyKindValue
105
+ Assert-AreEqual $NewGraph.Name $GraphName
106
+
107
+ $Database = Get-AzCosmosDBGremlinDatabase - InputObject $cosmosDBAccount - Name $DatabaseName
108
+ Assert-AreEqual $NewDatabase.Id $Database.Id
109
+ Assert-AreEqual $NewDatabase.Name $Database.Name
110
+ Assert-AreEqual $NewDatabase.Resource.Id $Database.Resource.Id
111
+ Assert-AreEqual $NewDatabase.Resource._rid $Database.Resource._rid
112
+ Assert-AreEqual $NewDatabase.Resource._ts $Database.Resource._ts
113
+ Assert-AreEqual $NewDatabase.Resource._etag $Database.Resource._etag
114
+
115
+ $Graph = Get-AzCosmosDBGremlinGraph - InputObject $NewDatabase - Name $GraphName
116
+ Assert-AreEqual $NewGraph.Id $Graph.Id
117
+ Assert-AreEqual $NewGraph.Name $Graph.Name
118
+ Assert-AreEqual $NewGraph.Resource.Id $Graph.Resource.Id
119
+ Assert-AreEqual $NewGraph.Resource._rid $Graph.Resource._rid
120
+ Assert-AreEqual $NewGraph.Resource._ts $Graph.Resource._ts
121
+ Assert-AreEqual $NewGraph.Resource._etag $Graph.Resource._etag
122
+
123
+ $ListGraphs = Get-AzCosmosDBGremlinGraph - InputObject $NewDatabase
124
+ Assert-NotNull ($ListGraphs )
125
+
126
+ $ListDatabases = Get-AzCosmosDBGremlinDatabase - InputObject $cosmosDBAccount
127
+ Assert-NotNull ($ListDatabases )
128
+
129
+ $IsGraphRemoved = Remove-AzCosmosDBGremlinGraph - InputObject $NewGraph - PassThru
130
+ Assert-AreEqual $IsGraphRemoved true
131
+
132
+ $IsDatabaseRemoved = Remove-AzCosmosDBGremlinDatabase - InputObject $NewDatabase - PassThru
133
+ Assert-AreEqual $IsDatabaseRemoved true
134
+ }
0 commit comments