public async Task RestorableSqlDatabaseResourceFeedTest() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create client CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler1); ResourceManagementClient resourcesClient = CosmosDBTestUtilities.GetResourceManagementClient(context, handler2); string resourceGroupName = CosmosDBTestUtilities.CreateResourceGroup(resourcesClient); string databaseAccountName = TestUtilities.GenerateName(prefix: "accountname"); List <Location> locations = new List <Location>(); locations.Add(new Location(locationName: "East US 2")); DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters { Location = "EAST US 2", Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } }, Kind = "MongoDB", ConsistencyPolicy = new ConsistencyPolicy { DefaultConsistencyLevel = DefaultConsistencyLevel.BoundedStaleness, MaxStalenessPrefix = 300, MaxIntervalInSeconds = 1000 }, Locations = locations }; DatabaseAccountGetResults databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccount); List <DatabaseAccountGetResults> databaseFeedResult = (await cosmosDBManagementClient.DatabaseAccounts.ListByResourceGroupAsync(resourceGroupName)).ToList(); Assert.Single(databaseFeedResult); DatabaseAccountUpdateParameters databaseAccountUpdateParameters = new DatabaseAccountUpdateParameters { Location = "EAST US 2", Tags = new Dictionary <string, string> { { "key3", "value3" }, { "key4", "value4" } }, ConsistencyPolicy = new ConsistencyPolicy { DefaultConsistencyLevel = DefaultConsistencyLevel.Session, MaxStalenessPrefix = 1300, MaxIntervalInSeconds = 12000 }, Locations = locations, IpRules = new List <IpAddressOrRange> { new IpAddressOrRange("23.43.230.120") }, IsVirtualNetworkFilterEnabled = false, EnableAutomaticFailover = true, DisableKeyBasedMetadataWriteAccess = true, NetworkAclBypass = NetworkAclBypass.AzureServices, NetworkAclBypassResourceIds = new List <string> { "/subscriptions/subId/resourcegroups/rgName/providers/Microsoft.Synapse/workspaces/workspaceName", "/subscriptions/subId/resourcegroups/rgName/providers/Microsoft.Synapse/workspaces/workspaceName2" } }; DatabaseAccountGetResults updatedDatabaseAccount = cosmosDBManagementClient.DatabaseAccounts.UpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountUpdateParameters).GetAwaiter().GetResult().Body; Assert.NotNull(updatedDatabaseAccount); databaseFeedResult = (await cosmosDBManagementClient.DatabaseAccounts.ListByResourceGroupAsync(resourceGroupName)).ToList(); Assert.Single(databaseFeedResult); await cosmosDBManagementClient.DatabaseAccounts.DeleteWithHttpMessagesAsync(resourceGroupName, databaseAccountName); } }
public void DatabaseAccountCRUDTests() { var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create client CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler1); ResourceManagementClient resourcesClient = CosmosDBTestUtilities.GetResourceManagementClient(context, handler2); string resourceGroupName = CosmosDBTestUtilities.CreateResourceGroup(resourcesClient); string databaseAccountName = TestUtilities.GenerateName(prefix: "accountname"); List <Location> locations = new List <Location>(); locations.Add(new Location(locationName: location)); DefaultRequestDatabaseAccountCreateUpdateProperties databaseAccountCreateUpdateProperties = new DefaultRequestDatabaseAccountCreateUpdateProperties { ConsistencyPolicy = new ConsistencyPolicy { DefaultConsistencyLevel = DefaultConsistencyLevel.BoundedStaleness, MaxStalenessPrefix = 300, MaxIntervalInSeconds = 1000 }, Locations = locations, IpRules = new List <IpAddressOrRange> { new IpAddressOrRange("23.43.230.120") }, IsVirtualNetworkFilterEnabled = true, EnableAutomaticFailover = false, EnableMultipleWriteLocations = true, EnableCassandraConnector = true, ConnectorOffer = "Small", DisableKeyBasedMetadataWriteAccess = false }; DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters { Location = location, Tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } }, Kind = "MongoDB", Properties = databaseAccountCreateUpdateProperties }; DatabaseAccountGetResults databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body; VerifyCosmosDBAccount(databaseAccount, databaseAccountCreateUpdateParameters); Assert.Equal(databaseAccountName, databaseAccount.Name); DatabaseAccountGetResults readDatabaseAccount = cosmosDBManagementClient.DatabaseAccounts.GetWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body; VerifyCosmosDBAccount(readDatabaseAccount, databaseAccountCreateUpdateParameters); Assert.Equal(databaseAccountName, readDatabaseAccount.Name); DatabaseAccountUpdateParameters databaseAccountUpdateParameters = new DatabaseAccountUpdateParameters { Location = location, Tags = new Dictionary <string, string> { { "key3", "value3" }, { "key4", "value4" } }, ConsistencyPolicy = new ConsistencyPolicy { DefaultConsistencyLevel = DefaultConsistencyLevel.Session, MaxStalenessPrefix = 1300, MaxIntervalInSeconds = 12000 }, Locations = locations, IpRules = new List <IpAddressOrRange> { new IpAddressOrRange("23.43.230.120") }, IsVirtualNetworkFilterEnabled = false, EnableAutomaticFailover = true, EnableCassandraConnector = true, ConnectorOffer = "Small", DisableKeyBasedMetadataWriteAccess = true }; DatabaseAccountGetResults updatedDatabaseAccount = cosmosDBManagementClient.DatabaseAccounts.UpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountUpdateParameters).GetAwaiter().GetResult().Body; VerifyCosmosDBAccount(updatedDatabaseAccount, databaseAccountUpdateParameters); Assert.Equal(databaseAccountName, databaseAccount.Name); IEnumerable <DatabaseAccountGetResults> databaseAccounts = cosmosDBManagementClient.DatabaseAccounts.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccounts); IEnumerable <DatabaseAccountGetResults> databaseAccountsByResourceGroupName = cosmosDBManagementClient.DatabaseAccounts.ListByResourceGroupWithHttpMessagesAsync(resourceGroupName).GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccountsByResourceGroupName); DatabaseAccountListKeysResult databaseAccountListKeysResult = cosmosDBManagementClient.DatabaseAccounts.ListKeysWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccountListKeysResult.PrimaryMasterKey); Assert.NotNull(databaseAccountListKeysResult.SecondaryMasterKey); Assert.NotNull(databaseAccountListKeysResult.PrimaryReadonlyMasterKey); Assert.NotNull(databaseAccountListKeysResult.SecondaryReadonlyMasterKey); DatabaseAccountListConnectionStringsResult databaseAccountListConnectionStringsResult = cosmosDBManagementClient.DatabaseAccounts.ListConnectionStringsWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccountListConnectionStringsResult); DatabaseAccountListReadOnlyKeysResult databaseAccountGetReadOnlyKeysResult = cosmosDBManagementClient.DatabaseAccounts.GetReadOnlyKeysWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccountGetReadOnlyKeysResult); DatabaseAccountListReadOnlyKeysResult databaseAccountListReadOnlyKeysResult = cosmosDBManagementClient.DatabaseAccounts.ListReadOnlyKeysWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body; Assert.NotNull(databaseAccountListReadOnlyKeysResult); cosmosDBManagementClient.DatabaseAccounts.RegenerateKeyWithHttpMessagesAsync(resourceGroupName, databaseAccountName, new DatabaseAccountRegenerateKeyParameters { KeyKind = "primary" }); cosmosDBManagementClient.DatabaseAccounts.RegenerateKeyWithHttpMessagesAsync(resourceGroupName, databaseAccountName, new DatabaseAccountRegenerateKeyParameters { KeyKind = "secondary" }); cosmosDBManagementClient.DatabaseAccounts.RegenerateKeyWithHttpMessagesAsync(resourceGroupName, databaseAccountName, new DatabaseAccountRegenerateKeyParameters { KeyKind = "primaryReadonly" }); cosmosDBManagementClient.DatabaseAccounts.RegenerateKeyWithHttpMessagesAsync(resourceGroupName, databaseAccountName, new DatabaseAccountRegenerateKeyParameters { KeyKind = "secondaryReadonly" }); DatabaseAccountListKeysResult databaseAccountListRegeneratedKeysResult = cosmosDBManagementClient.DatabaseAccounts.ListKeysWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body; cosmosDBManagementClient.DatabaseAccounts.DeleteWithHttpMessagesAsync(resourceGroupName, databaseAccountName); } }
public void ManagedCassandraCRUDTests() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var handler2 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType())) { // Create client CosmosDBManagementClient cosmosDBManagementClient = CosmosDBTestUtilities.GetCosmosDBClient(context, handler); ResourceManagementClient resourcesClient = CosmosDBTestUtilities.GetResourceManagementClient(context, handler2); string resourceGroupName = CosmosDBTestUtilities.CreateResourceGroup(resourcesClient); try { string clusterName = TestUtilities.GenerateName("managedcluster"); string dcName = TestUtilities.GenerateName("managedDC"); this.output.WriteLine($"Creating cluster {clusterName} in resource group {resourceGroupName}."); string subnetId = CreateVirtualNetwork(resourcesClient, resourceGroupName); this.output.WriteLine($"Created subnet {subnetId}."); var clusterProperties = new ClusterResourceProperties { DelegatedManagementSubnetId = subnetId, InitialCassandraAdminPassword = "******", ExternalSeedNodes = new List <SeedNode> { new SeedNode { IpAddress = "10.0.1.1" } } }; var clusterPutResource = new ClusterResource { Location = "East US 2", Properties = clusterProperties }; this.output.WriteLine($"Cluster create request body:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterPutResource, Formatting.Indented)); ClusterResource clusterResource = cosmosDBManagementClient.CassandraClusters .CreateUpdateWithHttpMessagesAsync(resourceGroupName: resourceGroupName, clusterName: clusterName, body: clusterPutResource).GetAwaiter().GetResult().Body; this.output.WriteLine($"Cluster create response:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterResource, Formatting.Indented)); Assert.Equal(subnetId, clusterResource.Properties.DelegatedManagementSubnetId); Assert.Null(clusterResource.Properties.InitialCassandraAdminPassword); Assert.Equal("Cassandra", clusterResource.Properties.AuthenticationMethod); Assert.Equal("Succeeded", clusterResource.Properties.ProvisioningState); Assert.NotNull(clusterResource.Properties.ExternalSeedNodes); Assert.Equal(1, clusterResource.Properties.ExternalSeedNodes.Count); Assert.Equal("10.0.1.1", clusterResource.Properties.ExternalSeedNodes[0].IpAddress); clusterPutResource.Properties.ExternalSeedNodes = new List <SeedNode> { new SeedNode { IpAddress = "192.168.12.1" } }; this.output.WriteLine(""); this.output.WriteLine("Updating cluster. Put body:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterPutResource, Formatting.Indented)); ClusterResource clusterResource2 = cosmosDBManagementClient.CassandraClusters .CreateUpdateWithHttpMessagesAsync(resourceGroupName: resourceGroupName, clusterName: clusterName, body: clusterPutResource).GetAwaiter().GetResult().Body; this.output.WriteLine("Response:"); this.output.WriteLine(JsonConvert.SerializeObject(clusterResource2, Formatting.Indented)); Assert.Equal(clusterName, clusterResource2.Name); Assert.Equal("East US 2", clusterResource2.Location); Assert.Equal(subnetId, clusterResource2.Properties.DelegatedManagementSubnetId); Assert.Null(clusterResource2.Properties.InitialCassandraAdminPassword); Assert.Equal("Cassandra", clusterResource2.Properties.AuthenticationMethod); Assert.Null(clusterResource2.Properties.CassandraVersion); Assert.Equal("Succeeded", clusterResource2.Properties.ProvisioningState); Assert.NotNull(clusterResource2.Properties.ExternalSeedNodes); Assert.NotEmpty(clusterResource2.Properties.ExternalSeedNodes); DataCenterResource dataCenterPutResource = new DataCenterResource { Properties = new DataCenterResourceProperties { DataCenterLocation = "East US 2", DelegatedSubnetId = subnetId, NodeCount = 3, } }; this.output.WriteLine($"Creating data center {dcName}. Put request:"); this.output.WriteLine(JsonConvert.SerializeObject(dataCenterPutResource, Formatting.Indented)); DataCenterResource dcResource = cosmosDBManagementClient.CassandraDataCenters .CreateUpdateWithHttpMessagesAsync(resourceGroupName, clusterName, dcName, dataCenterPutResource).GetAwaiter().GetResult().Body; this.output.WriteLine("Response:"); this.output.WriteLine(JsonConvert.SerializeObject(dcResource, Formatting.Indented)); Assert.Equal("East US 2", dcResource.Properties.DataCenterLocation); Assert.Equal(subnetId, dcResource.Properties.DelegatedSubnetId); Assert.Equal(3, dcResource.Properties.NodeCount); Assert.Equal(3, dcResource.Properties.SeedNodes.Count); this.output.WriteLine($"Deleting data center {dcName}."); cosmosDBManagementClient.CassandraDataCenters .DeleteWithHttpMessagesAsync(resourceGroupName, clusterName, dcName).GetAwaiter().GetResult(); this.output.WriteLine($"Deleting cluster {clusterName}."); cosmosDBManagementClient.CassandraClusters .DeleteWithHttpMessagesAsync(resourceGroupName, clusterName).GetAwaiter().GetResult(); this.output.WriteLine("Deleting deployment of vnets."); cosmosDBManagementClient.CassandraClusters .DeleteWithHttpMessagesAsync(resourceGroupName, clusterName).GetAwaiter().GetResult(); } finally { this.output.WriteLine("Deleting resource group."); resourcesClient.Deployments.Delete(resourceGroupName, ManagedCassandraResourcesOperationsTests.VnetDeploymentName); resourcesClient.ResourceGroups.Delete(resourceGroupName); } } }