Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/CosmosDB/CosmosDB.Test/CosmosDB.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PsModuleName>CosmosDB</PsModuleName>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="1.0.0" />
</ItemGroup>
</Project>
50 changes: 50 additions & 0 deletions src/CosmosDB/CosmosDB.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.Azure.Commands.CosmosDB.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.Azure.Commands.CosmosDB.Test")]
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("822d5889-438f-4c18-9c06-f5db728d417d")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.0.0")]
[assembly: AssemblyFileVersion("4.0.0")]
[assembly: CollectionBehavior(DisableTestParallelization = true)]
51 changes: 51 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.CosmosDB.Test.ScenarioTests.ScenarioTest
{
public class AccountTests
{
private ServiceManagement.Common.Models.XunitTracingInterceptor _logger;

public AccountTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new ServiceManagement.Common.Models.XunitTracingInterceptor(output);
ServiceManagement.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAccountRelatedCmdlets()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdlets");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAccountRelatedCmdletsUsingRid()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingRid");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAccountRelatedCmdletsUsingObject()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AccountRelatedCmdletsUsingObject");
}
}
}
166 changes: 166 additions & 0 deletions src/CosmosDB/CosmosDB.Test/ScenarioTests/AccountTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

function Test-AccountRelatedCmdlets
{
$rgName = "CosmosDBResourceGroup1"
$location = "East US"
$locationlist = "East US", "West US"
$locationlist2 = "East US", "UK South", "UK West", "South India"
$locationlist3 = "West US", "East US"

$resourceGroup = New-AzResourceGroup -ResourceGroupName $rgName -Location $location

$cosmosDBAccountName = "cosmosdb67127712"

$cosmosDBExistingAccountName = "dbaccount27"
$existingResourceGroupName = "CosmosDBResourceGroup27"

$ipRangeFilter = "192.168.0.1"
$tags = @{ name = "test"; Shape = "Square"; Color = "Blue"}

$cosmosDBAccount = New-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName -DefaultConsistencyLevel "BoundedStaleness" -MaxStalenessIntervalInSeconds 10 -MaxStalenessPrefix 20 -Location $location -IpRangeFilter $ipRangeFilter -Tag $tags -EnableVirtualNetwork -EnableMultipleWriteLocations -EnableAutomaticFailover -ApiKind "MongoDB"
do
{
$cosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $rgName -Name $cosmosDBAccountName
} while ($cosmosDBAccount.ProvisioningState -ne "Succeeded")

Assert-AreEqual $cosmosDBAccountName $cosmosDBAccount.Name
Assert-AreEqual "BoundedStaleness" $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
Assert-AreEqual 10 $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
Assert-AreEqual 20 $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
Assert-AreEqual $ipRangeFilter $cosmosDBAccount.IpRangeFilter
Assert-AreEqual $cosmosDBAccount.EnableAutomaticFailover 1
Assert-AreEqual $cosmosDBAccount.EnableMultipleWriteLocations 1
Assert-AreEqual $cosmosDBAccount.IsVirtualNetworkFilterEnabled 1

$updatedCosmosDBAccount = Update-AzCosmosDBAccount -ResourceGroupName $existingResourceGroupName -Name $cosmosDBExistingAccountName -DefaultConsistencyLevel "BoundedStaleness" -MaxStalenessIntervalInSeconds 10 -MaxStalenessPrefix 20 -IpRangeFilter $ipRangeFilter -Tag $tags -EnableVirtualNetwork 1 -EnableAutomaticFailover 1
do
{
$updatedCosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $existingResourceGroupName -Name $cosmosDBExistingAccountName
} while ($cosmosDBAccount.ProvisioningState -ne "Succeeded")

Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
Assert-AreEqual "BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1

$cosmosDBAccountKey = Get-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname
Assert-NotNull $cosmosDBAccountKey

$cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname -Type "ConnectionStrings"
Assert-NotNull $cosmosDBAccountConnectionStrings

$cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname -Type "ReadOnlyKeys"
Assert-NotNull $cosmosDBAccountReadOnlyKeys

$IsKeyRegenerated = New-AzCosmosDBAccountKey -Name $cosmosDBAccountName -ResourceGroupName $rgname -KeyKind "primary" -PassThru
Assert-AreEqual $IsKeyRegenerated true

$IsAccountDeleted = Remove-AzCosmosDBAccount -Name $cosmosDBAccountName -ResourceGroupName $rgName -PassThru
Assert-AreEqual $IsAccountDeleted true
}

function Test-AccountRelatedCmdletsUsingRid
{
$FailoverPolicy = "UK West", "East US", "UK South", "South India"
$locationlist2 = "UK South"

$cosmosDBExistingAccountName = "dbaccount27"
$existingResourceGroupName = "CosmosDBResourceGroup27"

$ipRangeFilter = "192.168.0.1"
$tags = @{ name = "test"; Shape = "Square"; Color = "Blue"}

$cosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $existingResourceGroupName -Name $cosmosDBExistingAccountName
$cosmosDBAccountByRid = Get-AzCosmosDBAccount -ResourceId $cosmosDBAccount.Id

Assert-AreEqual $cosmosDBAccountByRid.Name $cosmosDBAccount.Name
Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.DefaultConsistencyLevel $cosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxIntervalInSeconds $cosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
Assert-AreEqual $cosmosDBAccountByRid.ConsistencyPolicy.MaxStalenessPrefix $cosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
Assert-AreEqual $cosmosDBAccountByRid.IpRangeFilter $cosmosDBAccount.IpRangeFilter
Assert-AreEqual $cosmosDBAccountByRid.EnableAutomaticFailover $cosmosDBAccount.EnableAutomaticFailover
Assert-AreEqual $cosmosDBAccountByRid.EnableMultipleWriteLocations $cosmosDBAccount.EnableMultipleWriteLocations
Assert-AreEqual $cosmosDBAccountByRid.IsVirtualNetworkFilterEnabled $cosmosDBAccount.IsVirtualNetworkFilterEnabled

$updatedCosmosDBAccount = Update-AzCosmosDBAccount -ResourceId $cosmosDBAccount.Id -DefaultConsistencyLevel "BoundedStaleness" -MaxStalenessIntervalInSeconds 10 -MaxStalenessPrefix 20 -IpRangeFilter $ipRangeFilter -Tag $tags -EnableVirtualNetwork 1 -EnableAutomaticFailover 1
do
{
$updatedCosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $existingResourceGroupName -Name $cosmosDBExistingAccountName
} while ($cosmosDBAccount.ProvisioningState -ne "Succeeded")

Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
Assert-AreEqual "BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1

$cosmosDBAccountKey = Get-AzCosmosDBAccountKey -ResourceId $cosmosDBAccount.Id
Assert-NotNull $cosmosDBAccountKey

$cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey -ResourceId $cosmosDBAccount.Id -Type "ConnectionStrings"
Assert-NotNull $cosmosDBAccountConnectionStrings

$cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey -ResourceId $cosmosDBAccount.Id -Type "ReadOnlyKeys"
Assert-NotNull $cosmosDBAccountReadOnlyKeys

$IsKeyRegenerated = New-AzCosmosDBAccountKey -ResourceId $cosmosDBAccount.Id -KeyKind "primary" -PassThru
Assert-AreEqual $IsKeyRegenerated true
}

function Test-AccountRelatedCmdletsUsingObject
{
$cosmosDBExistingAccountName = "dbaccount27"
$existingResourceGroupName = "CosmosDBResourceGroup27"

$ipRangeFilter = "192.168.0.1"
$tags = @{ name = "test"; Shape = "Square"; Color = "Blue"}

$cosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $existingResourceGroupName -Name $cosmosDBExistingAccountName

$updatedCosmosDBAccount = Update-AzCosmosDBAccount -InputObject $cosmosDBAccount -DefaultConsistencyLevel "BoundedStaleness" -MaxStalenessIntervalInSeconds 10 -MaxStalenessPrefix 20 -IpRangeFilter $ipRangeFilter -Tag $tags -EnableVirtualNetwork 1 -EnableAutomaticFailover 1
do
{
$updatedCosmosDBAccount = Get-AzCosmosDBAccount -ResourceGroupName $existingResourceGroupName -Name $cosmosDBExistingAccountName
} while ($cosmosDBAccount.ProvisioningState -ne "Succeeded")

Assert-AreEqual $cosmosDBExistingAccountName $updatedCosmosDBAccount.Name
Assert-AreEqual "BoundedStaleness" $updatedCosmosDBAccount.ConsistencyPolicy.DefaultConsistencyLevel
Assert-AreEqual 10 $updatedCosmosDBAccount.ConsistencyPolicy.MaxIntervalInSeconds
Assert-AreEqual 20 $updatedCosmosDBAccount.ConsistencyPolicy.MaxStalenessPrefix
Assert-AreEqual $ipRangeFilter $updatedCosmosDBAccount.IpRangeFilter
Assert-AreEqual $updatedCosmosDBAccount.EnableAutomaticFailover 1
Assert-AreEqual $updatedCosmosDBAccount.IsVirtualNetworkFilterEnabled 1

$cosmosDBAccountKey = Get-AzCosmosDBAccountKey -InputObject $cosmosDBAccount
Assert-NotNull $cosmosDBAccountKey

$cosmosDBAccountConnectionStrings = Get-AzCosmosDBAccountKey -InputObject $cosmosDBAccount -Type "ConnectionStrings"
Assert-NotNull $cosmosDBAccountConnectionStrings

$cosmosDBAccountReadOnlyKeys = Get-AzCosmosDBAccountKey -InputObject $cosmosDBAccount -Type "ReadOnlyKeys"
Assert-NotNull $cosmosDBAccountReadOnlyKeys

$IsKeyRegenerated = New-AzCosmosDBAccountKey -InputObject $cosmosDBAccount -KeyKind "primary" -PassThru
Assert-AreEqual $IsKeyRegenerated true

$IsAccountDeleted = Remove-AzCosmosDBAccount -InputObject $cosmosDBAccount -PassThru
Assert-AreEqual $IsAccountDeleted true
}
Loading