public async Task RestoreDatabaseAccountTests()
        {
            var handler1 = 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, handler1);
                string restoredatabaseAccountName = TestUtilities.GenerateName(prefix: "restoredaccountname");

                DatabaseAccountGetResults databaseAccount = await cosmosDBManagementClient.DatabaseAccounts.GetAsync(resourceGroupName, sourceDatabaseAccountName);

                DateTime restoreTs = DateTime.Parse(restoreTimestamp);

                List <RestorableDatabaseAccountGetResult> restorableAccounts        = (await cosmosDBManagementClient.RestorableDatabaseAccounts.ListAsync()).ToList();
                RestorableDatabaseAccountGetResult        restorableDatabaseAccount = restorableAccounts.
                                                                                      SingleOrDefault(account => account.Name.Equals(databaseAccount.InstanceId, StringComparison.OrdinalIgnoreCase));

                List <Location> locations = new List <Location>
                {
                    new Location(locationName: location)
                };

                RestoreReqeustDatabaseAccountCreateUpdateProperties databaseAccountCreateUpdateProperties = new RestoreReqeustDatabaseAccountCreateUpdateProperties
                {
                    Locations         = locations,
                    RestoreParameters = new RestoreParameters()
                    {
                        RestoreMode           = "PointInTime",
                        RestoreTimestampInUtc = restoreTs,
                        RestoreSource         = restorableDatabaseAccount.Id
                    }
                };

                DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    },
                    Kind       = "GlobalDocumentDB",
                    Properties = databaseAccountCreateUpdateProperties
                };

                DatabaseAccountGetResults restoredDatabaseAccount = (await cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, restoredatabaseAccountName, databaseAccountCreateUpdateParameters)).Body;
                Assert.NotNull(restoredDatabaseAccount);
                Assert.NotNull(restoredDatabaseAccount.RestoreParameters);
                Assert.Equal(restoredDatabaseAccount.RestoreParameters.RestoreSource.ToLower(), restorableDatabaseAccount.Id.ToLower());
                Assert.True(restoredDatabaseAccount.BackupPolicy is ContinuousModeBackupPolicy);
            }
        }
Пример #2
0
        public void MongoCRUDTests()
        {
            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   = "CosmosDBResourceGroup3668";
                string databaseAccountName = "db001";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    List <Location> locations = new List <Location>();
                    locations.Add(new Location(locationName: "East US"));
                    DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    {
                        Location  = "EAST US",
                        Kind      = "MongoDB",
                        Locations = locations
                    };

                    databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string databaseName  = "databaseName3668";
                string databaseName2 = "databaseName23668";
                MongoDBDatabaseCreateUpdateParameters mongoDBDatabaseCreateUpdateParameters = new MongoDBDatabaseCreateUpdateParameters
                {
                    Resource = new MongoDBDatabaseResource {
                        Id = databaseName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                MongoDBDatabaseGetResults mongoDBDatabaseGetResults = cosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, mongoDBDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.Equal(databaseName, mongoDBDatabaseGetResults.Name);
                Assert.NotNull(mongoDBDatabaseGetResults);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/mongodbDatabases", mongoDBDatabaseGetResults.Type);

                MongoDBDatabaseGetResults mongoDBDatabaseGetResults1 = cosmosDBManagementClient.MongoDBResources.GetMongoDBDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(mongoDBDatabaseGetResults1);
                Assert.Equal(databaseName, mongoDBDatabaseGetResults1.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/mongodbDatabases", mongoDBDatabaseGetResults1.Type);


                VerifyEqualMongoDBDatabases(mongoDBDatabaseGetResults, mongoDBDatabaseGetResults1);

                MongoDBDatabaseCreateUpdateParameters mongoDBDatabaseCreateUpdateParameters2 = new MongoDBDatabaseCreateUpdateParameters
                {
                    Resource = new MongoDBDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                MongoDBDatabaseGetResults mongoDBDatabaseGetResults2 = cosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, mongoDBDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(mongoDBDatabaseGetResults2);
                Assert.Equal(databaseName2, mongoDBDatabaseGetResults2.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/mongodbDatabases", mongoDBDatabaseGetResults2.Type);

                IEnumerable <MongoDBDatabaseGetResults> mongoDBDatabases = cosmosDBManagementClient.MongoDBResources.ListMongoDBDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(mongoDBDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.MongoDBResources.GetMongoDBDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/mongodbDatabases/throughputSettings", throughputSettingsGetResults.Type);

                string collectionName = "collectionName3668";

                MongoDBCollectionCreateUpdateParameters mongoDBCollectionCreateUpdateParameters = new MongoDBCollectionCreateUpdateParameters
                {
                    Resource = new MongoDBCollectionResource
                    {
                        Id = collectionName,
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" },
                    }
                };

                MongoDBCollectionGetResults mongoDBCollectionGetResults = cosmosDBManagementClient.MongoDBResources.CreateUpdateMongoDBCollectionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, collectionName, mongoDBCollectionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(mongoDBCollectionGetResults);

                IEnumerable <MongoDBCollectionGetResults> mongoDBCollections = cosmosDBManagementClient.MongoDBResources.ListMongoDBCollectionsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(mongoDBCollections);

                foreach (MongoDBCollectionGetResults mongoDBCollection in mongoDBCollections)
                {
                    cosmosDBManagementClient.MongoDBResources.DeleteMongoDBCollectionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, mongoDBCollection.Name);
                }

                foreach (MongoDBDatabaseGetResults mongoDBDatabase in mongoDBDatabases)
                {
                    cosmosDBManagementClient.MongoDBResources.DeleteMongoDBDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, mongoDBDatabase.Name);
                }
            }
        }
        public void SqlCRUDTests()
        {
            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   = "CosmosDBResourceGroup822"; // Using a pre-existing ResourceGroup and DatabaseAccount, because Database Account provisioning takes some time
                string databaseAccountName = "db9934";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    List <Location> locations = new List <Location>();
                    locations.Add(new Location(locationName: "East US"));
                    DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    {
                        Location  = "EAST US",
                        Kind      = "GlobalDocumentDB",
                        Locations = locations
                    };

                    databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string databaseName  = "databaseName822";
                string databaseName2 = "databaseName2822";
                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters = new SqlDatabaseCreateUpdateParameters
                {
                    Resource = new SqlDatabaseResource {
                        Id = databaseName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlDatabaseGetResults sqlDatabaseGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, sqlDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults);
                Assert.Equal(databaseName, sqlDatabaseGetResults.Name);

                SqlDatabaseGetResults sqlDatabaseGetResults2 = cosmosDBManagementClient.SqlResources.GetSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults2);
                Assert.Equal(databaseName, sqlDatabaseGetResults2.Name);

                VerifyEqualSqlDatabases(sqlDatabaseGetResults, sqlDatabaseGetResults2);

                SqlDatabaseCreateUpdateParameters sqlDatabaseCreateUpdateParameters2 = new SqlDatabaseCreateUpdateParameters
                {
                    Location = "EAST US",
                    Tags     = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" }
                    },
                    Resource = new SqlDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                SqlDatabaseGetResults sqlDatabaseGetResults3 = cosmosDBManagementClient.SqlResources.CreateUpdateSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, sqlDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabaseGetResults3);
                Assert.Equal(databaseName2, sqlDatabaseGetResults3.Name);

                IEnumerable <SqlDatabaseGetResults> sqlDatabases = cosmosDBManagementClient.SqlResources.ListSqlDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.SqlResources.GetSqlDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings", throughputSettingsGetResults.Type);

                string containerName = "containerName822";

                SqlContainerCreateUpdateParameters sqlContainerCreateUpdateParameters = new SqlContainerCreateUpdateParameters
                {
                    Resource = new SqlContainerResource {
                        Id           = containerName,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address/zipCode"
                            }
                        }
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                SqlContainerGetResults sqlContainerGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlContainerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlContainerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainerGetResults);

                IEnumerable <SqlContainerGetResults> sqlContainers = cosmosDBManagementClient.SqlResources.ListSqlContainersWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlContainers);

                string storedProcedureName = "storedProcedureName822";

                SqlStoredProcedureCreateUpdateParameters sqlStoredProcedureCreateUpdateParameters = new SqlStoredProcedureCreateUpdateParameters
                {
                    Resource = new SqlStoredProcedureResource
                    {
                        Id   = storedProcedureName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlStoredProcedureGetResults sqlStoredProcedureGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlStoredProcedureWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, storedProcedureName, sqlStoredProcedureCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedureGetResults);

                IEnumerable <SqlStoredProcedureGetResults> sqlStoredProcedures = cosmosDBManagementClient.SqlResources.ListSqlStoredProceduresWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedures);

                foreach (SqlStoredProcedureGetResults sqlStoredProcedure in sqlStoredProcedures)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlStoredProcedureWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlStoredProcedure.Name);
                }

                string userDefinedFunctionName = "userDefinedFunctionName822";

                SqlUserDefinedFunctionCreateUpdateParameters sqlUserDefinedFunctionCreateUpdateParameters = new SqlUserDefinedFunctionCreateUpdateParameters
                {
                    Resource = new SqlUserDefinedFunctionResource
                    {
                        Id   = userDefinedFunctionName,
                        Body = "function () { var context = getContext(); " +
                               "var response = context.getResponse();" +
                               "response.setBody('Hello, World');" +
                               "}"
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlUserDefinedFunctionGetResults sqlUserDefinedFunctionGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlUserDefinedFunctionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, userDefinedFunctionName, sqlUserDefinedFunctionCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlStoredProcedureGetResults);

                IEnumerable <SqlUserDefinedFunctionGetResults> sqlUserDefinedFunctions = cosmosDBManagementClient.SqlResources.ListSqlUserDefinedFunctionsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlUserDefinedFunctions);

                foreach (SqlUserDefinedFunctionGetResults sqlUserDefinedFunction in sqlUserDefinedFunctions)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlUserDefinedFunctionWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlUserDefinedFunction.Name);
                }

                string triggerName = "triggerName822";

                SqlTriggerCreateUpdateParameters sqlTriggerCreateUpdateParameters = new SqlTriggerCreateUpdateParameters
                {
                    Resource = new SqlTriggerResource
                    {
                        Id = triggerName,
                        TriggerOperation = "All",
                        TriggerType      = "Pre",
                        Body             = "function () { var context = getContext(); " +
                                           "var response = context.getResponse();" +
                                           "response.setBody('Hello, World');" +
                                           "}"
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                SqlTriggerGetResults sqlTriggerGetResults = cosmosDBManagementClient.SqlResources.CreateUpdateSqlTriggerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, triggerName, sqlTriggerCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggerGetResults);

                IEnumerable <SqlTriggerGetResults> sqlTriggers = cosmosDBManagementClient.SqlResources.ListSqlTriggersWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName).GetAwaiter().GetResult().Body;
                Assert.NotNull(sqlTriggers);

                foreach (SqlTriggerGetResults sqlTrigger in sqlTriggers)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlTriggerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, containerName, sqlTrigger.Name);
                }

                foreach (SqlContainerGetResults sqlContainer in sqlContainers)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlContainerWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, sqlContainer.Name);
                }

                foreach (SqlDatabaseGetResults sqlDatabase in sqlDatabases)
                {
                    cosmosDBManagementClient.SqlResources.DeleteSqlDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, sqlDatabase.Name);
                }
            }
        }
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        public void CassandraCRUDTests()
        {
            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   = "CosmosDBResourceGroup2510";
                string databaseAccountName = "db2725";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    return;
                    // SDK doesnt support creation of Cassandra, Table, Gremlin Accounts, use accounts created using Azure portal

                    // List<Location> locations = new List<Location>();
                    // locations.Add(new Location(locationName: "East US"));
                    // DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    // {
                    //     Location = "EAST US",
                    //     Locations = locations
                    // };

                    //databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string keyspaceName  = "keyspaceName2510";
                string keyspaceName2 = "keyspaceName22510";
                CassandraKeyspaceCreateUpdateParameters cassandraKeyspaceCreateUpdateParameters = new CassandraKeyspaceCreateUpdateParameters
                {
                    Resource = new CassandraKeyspaceResource {
                        Id = keyspaceName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                CassandraKeyspaceGetResults cassandraKeyspaceGetResults = cosmosDBManagementClient.CassandraResources.CreateUpdateCassandraKeyspaceWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName, cassandraKeyspaceCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(cassandraKeyspaceGetResults);
                Assert.Equal(keyspaceName, cassandraKeyspaceGetResults.Name);

                CassandraKeyspaceGetResults cassandraKeyspaceGetResults1 = cosmosDBManagementClient.CassandraResources.GetCassandraKeyspaceWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName).GetAwaiter().GetResult().Body;
                Assert.NotNull(cassandraKeyspaceGetResults1);
                Assert.Equal(keyspaceName, cassandraKeyspaceGetResults1.Name);

                VerifyEqualCassandraDatabases(cassandraKeyspaceGetResults, cassandraKeyspaceGetResults1);

                CassandraKeyspaceCreateUpdateParameters cassandraKeyspaceCreateUpdateParameters2 = new CassandraKeyspaceCreateUpdateParameters
                {
                    Location = "EAST US",
                    Tags     = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" }
                    },
                    Resource = new CassandraKeyspaceResource {
                        Id = keyspaceName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                CassandraKeyspaceGetResults cassandraKeyspaceGetResults2 = cosmosDBManagementClient.CassandraResources.CreateUpdateCassandraKeyspaceWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName2, cassandraKeyspaceCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(cassandraKeyspaceGetResults2);
                Assert.Equal(keyspaceName2, cassandraKeyspaceGetResults2.Name);

                IEnumerable <CassandraKeyspaceGetResults> cassandraKeyspaces = cosmosDBManagementClient.CassandraResources.ListCassandraKeyspacesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(cassandraKeyspaces);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.CassandraResources.GetCassandraKeyspaceThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces/throughputSettings", throughputSettingsGetResults.Type);

                string tableName = "tableName2510";

                CassandraTableCreateUpdateParameters cassandraTableCreateUpdateParameters = new CassandraTableCreateUpdateParameters
                {
                    Resource = new CassandraTableResource
                    {
                        Id     = tableName,
                        Schema = new CassandraSchema
                        {
                            Columns = new List <Column> {
                                new Column {
                                    Name = "columnA", Type = "int"
                                }, new Column {
                                    Name = "columnB", Type = "ascii"
                                }
                            },
                            ClusterKeys = new List <ClusterKey> {
                                new ClusterKey {
                                    Name = "columnB", OrderBy = "Asc"
                                }
                            },
                            PartitionKeys = new List <CassandraPartitionKey> {
                                new CassandraPartitionKey {
                                    Name = "columnA"
                                }
                            }
                        }
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                CassandraTableGetResults cassandraTableGetResults = cosmosDBManagementClient.CassandraResources.CreateUpdateCassandraTableWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName, tableName, cassandraTableCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(cassandraTableGetResults);

                IEnumerable <CassandraTableGetResults> cassandraTables = cosmosDBManagementClient.CassandraResources.ListCassandraTablesWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName).GetAwaiter().GetResult().Body;
                Assert.NotNull(cassandraTables);

                foreach (CassandraTableGetResults cassandraTable in cassandraTables)
                {
                    cosmosDBManagementClient.CassandraResources.DeleteCassandraTableWithHttpMessagesAsync(resourceGroupName, databaseAccountName, keyspaceName, cassandraTable.Name);
                }

                foreach (CassandraKeyspaceGetResults cassandraKeyspace in cassandraKeyspaces)
                {
                    cosmosDBManagementClient.CassandraResources.DeleteCassandraKeyspaceWithHttpMessagesAsync(resourceGroupName, databaseAccountName, cassandraKeyspace.Name);
                }
            }
        }
        public void TableCRUDTests()
        {
            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   = "CosmosDBResourceGroup2510";
                string databaseAccountName = "db2527";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                //DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    return;
                    // SDK doesnt support creation of Cassandra, Table, Gremlin Accounts, use accounts created using Azure portal

                    // List<Location> locations = new List<Location>();
                    // locations.Add(new Location(locationName: "East US"));
                    // DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    // {
                    //     Location = "EAST US",
                    //     Locations = locations
                    // };

                    //databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string tableName  = "tableName2527";
                string tableName2 = "tableName22527";
                TableCreateUpdateParameters tableCreateUpdateParameters = new TableCreateUpdateParameters
                {
                    Resource = new TableResource {
                        Id = tableName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                TableGetResults tableGetResults = cosmosDBManagementClient.TableResources.CreateUpdateTableWithHttpMessagesAsync(resourceGroupName, databaseAccountName, tableName, tableCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(tableGetResults);
                Assert.Equal(tableName, tableGetResults.Name);

                TableGetResults tableGetResults2 = cosmosDBManagementClient.TableResources.GetTableWithHttpMessagesAsync(resourceGroupName, databaseAccountName, tableName).GetAwaiter().GetResult().Body;
                Assert.NotNull(tableGetResults2);
                Assert.Equal(tableName, tableGetResults2.Name);

                VerifyEqualTables(tableGetResults, tableGetResults2);

                TableCreateUpdateParameters tableCreateUpdateParameters2 = new TableCreateUpdateParameters
                {
                    Location = "EAST US",
                    Tags     = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" }
                    },
                    Resource = new TableResource {
                        Id = tableName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                TableGetResults tableGetResults3 = cosmosDBManagementClient.TableResources.CreateUpdateTableWithHttpMessagesAsync(resourceGroupName, databaseAccountName, tableName2, tableCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(tableGetResults3);
                Assert.Equal(tableName2, tableGetResults3.Name);

                IEnumerable <TableGetResults> tables = cosmosDBManagementClient.TableResources.ListTablesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(tables);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.TableResources.GetTableThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, tableName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/tables/throughputSettings", throughputSettingsGetResults.Type);

                foreach (TableGetResults table in tables)
                {
                    cosmosDBManagementClient.TableResources.DeleteTableWithHttpMessagesAsync(resourceGroupName, databaseAccountName, table.Name);
                }
            }
        }
Пример #8
0
        public void GraphCRUDTests()
        {
            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   = "CosmosDBResourceGroup2510";
                string databaseAccountName = "db1002";

                bool isDatabaseNameExists = cosmosDBManagementClient.DatabaseAccounts.CheckNameExistsWithHttpMessagesAsync(databaseAccountName).GetAwaiter().GetResult().Body;

                //DatabaseAccountGetResults databaseAccount = null;
                if (!isDatabaseNameExists)
                {
                    return;
                    // SDK doesnt support creation of Cassandra, Table, Gremlin Accounts, use accounts created using Azure portal

                    // List<Location> locations = new List<Location>();
                    // locations.Add(new Location(locationName: "East US"));
                    // DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters
                    // {
                    //     Location = "EAST US",
                    //     Locations = locations
                    // };

                    //databaseAccount = cosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                }

                string databaseName  = "databaseName1002";
                string databaseName2 = "databaseName21002";
                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters = new GremlinDatabaseCreateUpdateParameters
                {
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "foo", "bar" }
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinDatabaseCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults);
                Assert.Equal(databaseName, gremlinDatabaseGetResults.Name);

                GremlinDatabaseGetResults gremlinDatabaseGetResults1 = cosmosDBManagementClient.GremlinResources.GetGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults1);
                Assert.Equal(databaseName, gremlinDatabaseGetResults1.Name);

                VerifyEqualGremlinDatabases(gremlinDatabaseGetResults, gremlinDatabaseGetResults1);

                GremlinDatabaseCreateUpdateParameters gremlinDatabaseCreateUpdateParameters2 = new GremlinDatabaseCreateUpdateParameters
                {
                    Location = "EAST US",
                    Tags     = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" }
                    },
                    Resource = new GremlinDatabaseResource {
                        Id = databaseName2
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                GremlinDatabaseGetResults gremlinDatabaseGetResults2 = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2, gremlinDatabaseCreateUpdateParameters2).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabaseGetResults2);
                Assert.Equal(databaseName2, gremlinDatabaseGetResults2.Name);

                IEnumerable <GremlinDatabaseGetResults> gremlinDatabases = cosmosDBManagementClient.GremlinResources.ListGremlinDatabasesWithHttpMessagesAsync(resourceGroupName, databaseAccountName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinDatabases);

                ThroughputSettingsGetResults throughputSettingsGetResults = cosmosDBManagementClient.GremlinResources.GetGremlinDatabaseThroughputWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName2).GetAwaiter().GetResult().Body;
                Assert.NotNull(throughputSettingsGetResults);
                Assert.NotNull(throughputSettingsGetResults.Name);
                Assert.Equal("Microsoft.DocumentDB/databaseAccounts/gremlinDatabases/throughputSettings", throughputSettingsGetResults.Type);

                string gremlinGraphName = "gremlinGraphName1002";

                GremlinGraphCreateUpdateParameters gremlinGraphCreateUpdateParameters = new GremlinGraphCreateUpdateParameters
                {
                    Resource = new GremlinGraphResource
                    {
                        Id           = gremlinGraphName,
                        PartitionKey = new ContainerPartitionKey
                        {
                            Kind  = "Hash",
                            Paths = new List <string> {
                                "/address"
                            }
                        }
                    },
                    Options = new Dictionary <string, string>()
                    {
                        { "Throughput", "700" }
                    }
                };

                GremlinGraphGetResults gremlinGraphGetResults = cosmosDBManagementClient.GremlinResources.CreateUpdateGremlinGraphWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraphName, gremlinGraphCreateUpdateParameters).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphGetResults);

                IEnumerable <GremlinGraphGetResults> gremlinGraphs = cosmosDBManagementClient.GremlinResources.ListGremlinGraphsWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName).GetAwaiter().GetResult().Body;
                Assert.NotNull(gremlinGraphs);

                foreach (GremlinGraphGetResults gremlinGraph in gremlinGraphs)
                {
                    cosmosDBManagementClient.GremlinResources.DeleteGremlinGraphWithHttpMessagesAsync(resourceGroupName, databaseAccountName, databaseName, gremlinGraph.Name);
                }

                foreach (GremlinDatabaseGetResults gremlinDatabase in gremlinDatabases)
                {
                    cosmosDBManagementClient.GremlinResources.DeleteGremlinDatabaseWithHttpMessagesAsync(resourceGroupName, databaseAccountName, gremlinDatabase.Name);
                }
            }
        }
Пример #9
0
        public async Task RestorableSqlTests()
        {
            var handler1 = 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, handler1);
                DatabaseAccountGetResults databaseAccount          = await cosmosDBManagementClient.DatabaseAccounts.GetAsync(resourceGroupName, sourceDatabaseAccountName);

                RestorableDatabaseAccountGetResult restorableDatabaseAccount = (await cosmosDBManagementClient.RestorableDatabaseAccounts.GetByLocationAsync(location, sourceDatabaseAccountInstanceId));

                Assert.Equal(databaseAccount.InstanceId, restorableDatabaseAccount.Name);
                Assert.Equal(databaseAccount.Name, restorableDatabaseAccount.AccountName);
                Assert.Equal(ApiType.Sql, restorableDatabaseAccount.ApiType);
                Assert.Equal(3, restorableDatabaseAccount.RestorableLocations.Count);

                foreach (var location in restorableDatabaseAccount.RestorableLocations)
                {
                    Assert.NotNull(location.CreationTime);
                    // Assert.Null(location.DeletionTime);
                    Assert.False(string.IsNullOrEmpty(location.LocationName));
                    Assert.False(string.IsNullOrEmpty(location.RegionalDatabaseAccountInstanceId));
                }

                List <RestorableSqlDatabaseGetResult> restorableSqlDatabases =
                    (await cosmosDBManagementClient.RestorableSqlDatabases.ListAsync(location, restorableDatabaseAccount.Name)).ToList();

                RestorableSqlDatabaseGetResult restorableSqlDatabase = restorableSqlDatabases.First();

                Assert.Equal(2, restorableSqlDatabases.Count());

                string dbRid = restorableSqlDatabase.Resource.OwnerResourceId;

                List <RestorableSqlContainerGetResult> restorableSqlContainers =
                    (await cosmosDBManagementClient.RestorableSqlContainers.ListAsync(location, restorableDatabaseAccount.Name, dbRid)).ToList();

                Assert.Equal(2, restorableSqlContainers.Count());

                List <DatabaseRestoreResource> restorableSqlResources =
                    (await cosmosDBManagementClient.RestorableSqlResources.ListAsync(location, restorableDatabaseAccount.Name, location, restoreTimestamp.ToString())).ToList();

                DatabaseRestoreResource databaseRestoreResource1 = new DatabaseRestoreResource()
                {
                    DatabaseName    = "database1",
                    CollectionNames = new List <string>()
                    {
                        "container1", "container2"
                    }
                };

                DatabaseRestoreResource databaseRestoreResource2 = new DatabaseRestoreResource()
                {
                    DatabaseName    = "databaseA",
                    CollectionNames = new List <string>()
                };

                List <DatabaseRestoreResource> resources = new List <DatabaseRestoreResource>()
                {
                    databaseRestoreResource1,
                    databaseRestoreResource2
                };

                ValidateDatabaseRestoreResource(resources, restorableSqlResources);
            }
        }
Пример #10
0
        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);
                }
            }
        }