Exemplo n.º 1
0
 private void VerifyCosmosDBAccount(DatabaseAccount databaseAccount, DatabaseAccountUpdateOptions parameters)
 {
     Assert.True(databaseAccount.Data.Tags.SequenceEqual(parameters.Tags));
     Assert.AreEqual(databaseAccount.Data.IsVirtualNetworkFilterEnabled, parameters.IsVirtualNetworkFilterEnabled);
     Assert.AreEqual(databaseAccount.Data.EnableAutomaticFailover, parameters.EnableAutomaticFailover);
     Assert.AreEqual(databaseAccount.Data.DisableKeyBasedMetadataWriteAccess, parameters.DisableKeyBasedMetadataWriteAccess);
 }
Exemplo n.º 2
0
        public async Task DatabaseAccountCreateAndUpdateTest()
        {
            var account = await CreateDatabaseAccount(Recording.GenerateAssetName("dbaccount-"), DatabaseAccountKind.MongoDB);

            bool ifExists = await DatabaseAccountCollection.CheckIfExistsAsync(_databaseAccountName);

            Assert.AreEqual(true, ifExists);

            DatabaseAccount account2 = await DatabaseAccountCollection.GetAsync(_databaseAccountName);

            VerifyCosmosDBAccount(account, account2);

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

            updateOptions.Tags.Add("key3", "value3");
            updateOptions.Tags.Add("key4", "value4");
            await account2.Update(updateOptions).WaitForCompletionAsync();

            var failoverPolicyList = new List <FailoverPolicy>
            {
                new FailoverPolicy()
                {
                    LocationName     = Resources.Models.Location.WestUS,
                    FailoverPriority = 0
                }
            };
            FailoverPolicies failoverPolicies = new FailoverPolicies(failoverPolicyList);
            await account2.FailoverPriorityChange(new FailoverPolicies(failoverPolicyList)).WaitForCompletionResponseAsync();

            DatabaseAccount account3 = await DatabaseAccountCollection.GetAsync(_databaseAccountName);

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