public async Task TestTearDown()
 {
     if (await DatabaseAccountCollection.ExistsAsync(_databaseAccountName))
     {
         var id = DatabaseAccountCollection.Id;
         id = DatabaseAccountResource.CreateResourceIdentifier(id.SubscriptionId, id.ResourceGroupName, _databaseAccountName);
         DatabaseAccountResource account = this.ArmClient.GetDatabaseAccountResource(id);
         await account.DeleteAsync(WaitUntil.Completed);
     }
 }
Exemple #2
0
        public async Task DatabaseAccountCreateAndUpdateTest()
        {
            var account = await CreateDatabaseAccount(Recording.GenerateAssetName("dbaccount-"), DatabaseAccountKind.MongoDB);

            bool ifExists = await DatabaseAccountCollection.ExistsAsync(_databaseAccountName);

            Assert.AreEqual(true, ifExists);

            DatabaseAccount account2 = await DatabaseAccountCollection.GetAsync(_databaseAccountName);

            VerifyCosmosDBAccount(account, account2);

            var updateOptions = new PatchableDatabaseAccountData()
            {
                IsVirtualNetworkFilterEnabled      = false,
                EnableAutomaticFailover            = true,
                DisableKeyBasedMetadataWriteAccess = true,
            };

            updateOptions.Tags.Add("key3", "value3");
            updateOptions.Tags.Add("key4", "value4");
            await account2.UpdateAsync(WaitUntil.Completed, updateOptions);

            var failoverPolicyList = new List <FailoverPolicy>
            {
                new FailoverPolicy()
                {
                    LocationName     = AzureLocation.WestUS,
                    FailoverPriority = 0
                }
            };
            FailoverPolicies failoverPolicies = new FailoverPolicies(failoverPolicyList);
            await account2.FailoverPriorityChangeAsync(WaitUntil.Completed, new FailoverPolicies(failoverPolicyList));

            DatabaseAccount account3 = await DatabaseAccountCollection.GetAsync(_databaseAccountName);

            VerifyCosmosDBAccount(account3, updateOptions);
            VerifyFailoverPolicies(failoverPolicyList, account3.Data.FailoverPolicies);
        }