Skip to content

Commit ef61e22

Browse files
authored
Merge pull request #10726 from MehaKaushik/20191216
Cmdlets for CosmosDB Sql and Account Operations
2 parents 4acbc27 + e99f8c6 commit ef61e22

File tree

99 files changed

+22165
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+22165
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<PsModuleName>CosmosDB</PsModuleName>
4+
</PropertyGroup>
5+
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.0.0" />
8+
</ItemGroup>
9+
</Project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
using System.Reflection;
16+
using System.Runtime.InteropServices;
17+
using Xunit;
18+
19+
// General Information about an assembly is controlled through the following
20+
// set of attributes. Change these attribute values to modify the information
21+
// associated with an assembly.
22+
[assembly: AssemblyTitle("Microsoft.Azure.Commands.CosmosDB.Test")]
23+
[assembly: AssemblyDescription("")]
24+
[assembly: AssemblyConfiguration("")]
25+
[assembly: AssemblyCompany("")]
26+
[assembly: AssemblyProduct("Microsoft.Azure.Commands.CosmosDB.Test")]
27+
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
28+
[assembly: AssemblyTrademark("")]
29+
[assembly: AssemblyCulture("")]
30+
31+
// Setting ComVisible to false makes the types in this assembly not visible
32+
// to COM components. If you need to access a type in this assembly from
33+
// COM, set the ComVisible attribute to true on that type.
34+
[assembly: ComVisible(false)]
35+
36+
// The following GUID is for the ID of the typelib if this project is exposed to COM
37+
[assembly: Guid("822d5889-438f-4c18-9c06-f5db728d417d")]
38+
39+
// Version information for an assembly consists of the following four values:
40+
//
41+
// Major Version
42+
// Minor Version
43+
// Build Number
44+
// Revision
45+
//
46+
// You can specify all the values or you can default the Build and Revision Numbers
47+
// by using the '*' as shown below:
48+
[assembly: AssemblyVersion("4.0.0")]
49+
[assembly: AssemblyFileVersion("4.0.0")]
50+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
19+
{
20+
public class AccountTests
21+
{
22+
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;
23+
24+
public AccountTests(Xunit.Abstractions.ITestOutputHelper output)
25+
{
26+
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
27+
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
28+
}
29+
30+
[Fact]
31+
[Trait(Category.AcceptanceType, Category.CheckIn)]
32+
public void TestAccountRelatedCmdlets()
33+
{
34+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdlets");
35+
}
36+
37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestAccountRelatedCmdletsUsingRid()
40+
{
41+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingRid");
42+
}
43+
44+
[Fact]
45+
[Trait(Category.AcceptanceType, Category.CheckIn)]
46+
public void TestAccountRelatedCmdletsUsingObject()
47+
{
48+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingObject");
49+
}
50+
}
51+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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

Comments
 (0)