public void PolicyCrudTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"];
                string resourceName      = ConfigurationManager.AppSettings["RsVaultNameRP"];
                string location          = ConfigurationManager.AppSettings["vaultLocationRP"];
                string defaultPolicyName = ConfigurationManager.AppSettings["DefaultPolicyName"];

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                // 1. Create vault
                VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client);
                vaultTestHelper.CreateVault(resourceGroupName, resourceName, location);

                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);

                // ACTION: Get default policy
                ProtectionPolicyResponse response = policyTestHelper.GetProtectionPolicy(resourceGroupName, resourceName, defaultPolicyName);

                // VALIDATION: Name should match
                Assert.NotNull(response.Item.Name);
                Assert.Equal(response.Item.Name, defaultPolicyName);
                Assert.NotNull(response.Item.Id);
                Assert.NotNull(response.Item.Type);
                Assert.NotNull(response.Item.Properties);

                // ACTION: Add new policy
                ProtectionPolicyRequest request = new ProtectionPolicyRequest();
                request.Item            = new ProtectionPolicyResource();
                request.Item.Properties = response.Item.Properties;
                string newPolicyName = defaultPolicyName + "_updated";
                response = policyTestHelper.AddOrUpdateProtectionPolicy(resourceGroupName, resourceName, newPolicyName, request);

                // ACTION: Update the policy
                response = policyTestHelper.AddOrUpdateProtectionPolicy(resourceGroupName, resourceName, newPolicyName, request);

                // VALIDATION: Name should match
                Assert.NotNull(response.Item.Name);
                Assert.Equal(response.Item.Name, newPolicyName);
                Assert.NotNull(response.Item.Id);
                Assert.NotNull(response.Item.Type);
                Assert.NotNull(response.Item.Properties);

                // ACTION: Delete the policy
                AzureOperationResponse deleteResponse = policyTestHelper.DeleteProtectionPolicy(resourceGroupName, resourceName, newPolicyName);
                Assert.Equal(deleteResponse.StatusCode, HttpStatusCode.OK);
            }
        }
        public void PolicyCrudTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                string rsVaultRgName     = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName);
                string rsVaultName       = CommonTestHelper.GetSetting(TestConstants.RsVaultName);

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);
                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);
                string            policyName       = ConfigurationManager.AppSettings["AzureSqlPolicyName"];

                //create policy request
                SimpleRetentionPolicy retPolicy = new SimpleRetentionPolicy();
                retPolicy.RetentionDuration = new RetentionDuration()
                {
                    DurationType = "Weeks",
                    Count        = 6
                };

                AzureSqlProtectionPolicy sqlPolicy = new AzureSqlProtectionPolicy()
                {
                    RetentionPolicy = retPolicy
                };

                ProtectionPolicyRequest policyRequest = new ProtectionPolicyRequest()
                {
                    Item = new ProtectionPolicyResource()
                    {
                        Properties = sqlPolicy
                    }
                };

                //create policy
                ProtectionPolicyResponse response = policyTestHelper.AddOrUpdateProtectionPolicy(rsVaultRgName, rsVaultName, policyName, policyRequest);

                // get policy
                response = policyTestHelper.GetProtectionPolicy(rsVaultRgName, rsVaultName, policyName);
                Assert.NotNull(response.Item.Name);
                Assert.Equal(response.Item.Name, policyName);
                Assert.NotNull(response.Item.Id);
                Assert.NotNull(response.Item.Type);
                Assert.NotNull(response.Item.Properties);
                Assert.NotNull(response.Item.Properties as AzureSqlProtectionPolicy);
                AzureSqlProtectionPolicy resultPolicy   = response.Item.Properties as AzureSqlProtectionPolicy;
                SimpleRetentionPolicy    resultRetetion = resultPolicy.RetentionPolicy as SimpleRetentionPolicy;
                Assert.Equal(resultRetetion.RetentionDuration.DurationType, "Weeks");
                Assert.Equal(resultRetetion.RetentionDuration.Count, 6);

                //update policy request
                retPolicy.RetentionDuration = new RetentionDuration()
                {
                    DurationType = "Months",
                    Count        = 2
                };

                sqlPolicy = new AzureSqlProtectionPolicy()
                {
                    RetentionPolicy = retPolicy
                };

                policyRequest = new ProtectionPolicyRequest()
                {
                    Item = new ProtectionPolicyResource()
                    {
                        Properties = sqlPolicy
                    }
                };


                // update policy
                response = policyTestHelper.AddOrUpdateProtectionPolicy(rsVaultRgName, rsVaultName, policyName, policyRequest);
                // validations
                Assert.NotNull(response.Item.Name);
                Assert.Equal(response.Item.Name, policyName);
                Assert.NotNull(response.Item.Id);
                Assert.NotNull(response.Item.Type);
                Assert.NotNull(response.Item.Properties);
                Assert.NotNull(response.Item.Properties as AzureSqlProtectionPolicy);
                resultPolicy   = response.Item.Properties as AzureSqlProtectionPolicy;
                resultRetetion = resultPolicy.RetentionPolicy as SimpleRetentionPolicy;
                Assert.Equal(resultRetetion.RetentionDuration.DurationType, "Months");
                Assert.Equal(resultRetetion.RetentionDuration.Count, 2);


                // delete the policy
                AzureOperationResponse deleteResponse = policyTestHelper.DeleteProtectionPolicy(rsVaultRgName, rsVaultName, policyName);
                Assert.Equal(deleteResponse.StatusCode, HttpStatusCode.OK);
            }
        }