public void ListJobsAndGetJobTest()
        {
            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"];
                // TODO: Create VM instead of taking these parameters from config
                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"];
                string itemUniqueName      = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"];
                string containeType        = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string itemType            = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string containerUri        = containeType + ";" + containerUniqueName;
                string itemUri             = itemType + ";" + itemUniqueName;
                string utcDateTimeFormat   = ConfigurationManager.AppSettings["UTCDateTimeFormat"];

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

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

                // 2. Get default policy
                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);
                string            policyId         = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName);

                // 3. Enable protection
                ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client);
                DateTime protectionStartTime = DateTime.UtcNow;
                protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri);
                DateTime protectionEndTime = DateTime.UtcNow;

                // ACTION: List jobs
                CommonJobQueryFilters commonFilters = new CommonJobQueryFilters();
                commonFilters.BackupManagementType = BackupManagementType.AzureIaasVM.ToString();
                commonFilters.StartTime            = protectionStartTime.ToString(utcDateTimeFormat);
                commonFilters.EndTime = protectionEndTime.ToString(utcDateTimeFormat);
                JobTestHelpers helper  = new JobTestHelpers(client);
                var            jobList = helper.ListJobs(resourceGroupName, resourceName, commonFilters, null);

                // VALIDATION
                foreach (var job in jobList.ItemList.Value)
                {
                    Assert.NotNull(job.Id);
                    Assert.NotNull(job.Name);
                    helper.ValidateJobResponse(job.Properties, commonFilters);

                    // validating getjob
                    var jobDetails = helper.GetJob(resourceGroupName, resourceName, job.Name);
                    Assert.NotNull(jobDetails);
                    Assert.NotNull(jobDetails.Item);
                    helper.ValidateJobResponse(jobDetails.Item.Properties, null);
                }
            }
        }
        public void CancelJobTest()
        {
            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"];
                // TODO: Create VM instead of taking these parameters from config
                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"];
                string itemUniqueName      = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"];
                string containeType        = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string itemType            = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string containerUri        = containeType + ";" + containerUniqueName;
                string itemUri             = itemType + ";" + itemUniqueName;

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

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

                // 2. Get default policy
                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);
                string            policyId         = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName);

                // 3. Enable protection
                ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client);
                DateTime protectionStartTime = DateTime.UtcNow;
                protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri);
                DateTime protectionEndTime = DateTime.UtcNow;

                // 4. Trigger backup and get the job
                BackupTestHelpers     backupTestHelper = new BackupTestHelpers(client);
                string                jobId            = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri);
                CommonJobQueryFilters commonFilters    = new CommonJobQueryFilters();
                commonFilters.Status    = JobStatus.InProgress.ToString();
                commonFilters.Operation = JobOperation.Backup.ToString();
                JobTestHelpers helper = new JobTestHelpers(client);
                var            job    = helper.GetJob(resourceGroupName, resourceName, jobId);

                // ACTION: Cancel the job
                var cancelResponse = helper.CancelJob(resourceGroupName, resourceName, jobId);
                var opId           = helper.GetOpId(cancelResponse.Location);
                var opStatus       = helper.GetJobOperationStatus(resourceGroupName, resourceName, jobId, opId);
                TestUtilities.RetryActionWithTimeout(
                    () => opStatus = helper.GetJobOperationStatus(resourceGroupName, resourceName, jobId, opId),
                    () => opStatus.StatusCode != HttpStatusCode.Accepted,
                    TimeSpan.FromMinutes(30),
                    statusCode =>
                {
                    if (HttpMockServer.Mode == HttpRecorderMode.Record)
                    {
                        Thread.Sleep(15 * 1000);
                    }
                    return(true);
                });
            }
        }