public void ListRecoveryPointTest()
        {
            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 fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"];
                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);
                protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri);

                // 4. Trigger backup and wait for completion
                BackupTestHelpers backupTestHelper = new BackupTestHelpers(client);
                DateTime backupStartTime = DateTime.UtcNow;
                string jobId = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri);
                JobTestHelpers jobTestHelper = new JobTestHelpers(client);
                jobTestHelper.WaitForJob(resourceGroupName, resourceName, jobId);
                DateTime backupEndTime = DateTime.UtcNow;

                // ACTION: Fetch RP
                RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters();
                queryFilter.StartDate = backupStartTime.ToString(utcDateTimeFormat);
                queryFilter.EndDate = backupEndTime.ToString(utcDateTimeFormat);
                var response = client.RecoveryPoints.List(
                    resourceGroupName, resourceName, CommonTestHelper.GetCustomRequestHeaders(), fabricName, containerUri, itemUri, queryFilter);

                // VALIDATION: Should be only one RP
                Assert.NotNull(response.RecoveryPointList);
                Assert.NotNull(response.RecoveryPointList.RecoveryPoints);
                Assert.Equal(1, response.RecoveryPointList.RecoveryPoints.Count);
            }
        }
        public List<RecoveryPointResource> ListRecoveryPoints(string resourceGroupName, string resourceName, string containerUri, string itemUri, DateTime backupStartTime, DateTime backupEndTime)
        {
            string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"];
            string utcDateTimeFormat = ConfigurationManager.AppSettings["UTCDateTimeFormat"];

            RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters();
            queryFilter.StartDate = backupStartTime.ToString(utcDateTimeFormat);
            queryFilter.EndDate = backupEndTime.ToString(utcDateTimeFormat);
            var response = Client.RecoveryPoints.List(
                resourceGroupName, resourceName, CommonTestHelper.GetCustomRequestHeaders(), fabricName, containerUri, itemUri, queryFilter);

            return response.RecoveryPointList.RecoveryPoints.ToList();
        }
        public void ListRecoveryPointTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace);

                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRestore"];
                string resourceName = ConfigurationManager.AppSettings["RsVaultNameRestore"];
                string fabricName = ConfigurationManager.AppSettings["AzureBackupFabricName"];

                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRestore"];
                string containeType = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string containerUri = containeType + ";" + containerUniqueName;

                string itemUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRestore"];
                string itemType = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string itemUri = itemType + ";" + itemUniqueName;

                DateTime startTime = new DateTime(2016, 4, 17, 15, 25, 9, DateTimeKind.Utc);
                DateTime endTime = new DateTime(2016, 4, 18, 19, 25, 9, DateTimeKind.Utc);

                RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters();
                queryFilter.StartDate = startTime.ToString("yyyy-MM-dd hh:mm:ss tt");
                queryFilter.EndDate = endTime.ToString("yyyy-MM-dd hh:mm:ss tt");

                var response = client.RecoveryPoints.List(resourceGroupName, resourceName, CommonTestHelper.GetCustomRequestHeaders(),
                    fabricName, containerUri, itemUri, queryFilter);
                
                Assert.NotNull(response.RecoveryPointList);
                Assert.NotNull(response.RecoveryPointList.RecoveryPoints);

                foreach (var rpo in response.RecoveryPointList.RecoveryPoints)
                {
                    Assert.True(!string.IsNullOrEmpty(rpo.Name), "RP Id cant be null");
                    RecoveryPoint rp = rpo.Properties as RecoveryPoint;
                    Assert.True(!string.IsNullOrEmpty(rp.RecoveryPointTime), "RecoveryPointTime can't be null or empty");
                    Assert.True(!string.IsNullOrEmpty(rp.SourceVMStorageType), "SourceVMStorageType can't be null or empty");
                }
            }
        }
        /// <summary>
        /// Lists recovery points according to the input parameters
        /// </summary>
        /// <param name="containerName">Name of the container which the item belongs to</param>
        /// <param name="protectedItemName">Name of the item</param>
        /// <param name="queryFilter">Query filter</param>
        /// <returns>List of recovery points</returns>
        public RecoveryPointListResponse GetRecoveryPoints
            (
            string containerName, 
            string protectedItemName, 
            RecoveryPointQueryParameters queryFilter
            )
        {
            string resourceGroupName = BmsAdapter.GetResourceGroupName();
            string resourceName = BmsAdapter.GetResourceName();

            var response = BmsAdapter.Client.RecoveryPoints.ListAsync(
                resourceGroupName, 
                resourceName,
                BmsAdapter.GetCustomRequestHeaders(), 
                AzureFabricName, 
                containerName, 
                protectedItemName, 
                queryFilter, 
                BmsAdapter.CmdletCancellationToken).Result;

            return response;
        }
        /// <summary>
        /// Lists recovery points generated for the given item
        /// </summary>
        /// <returns>List of recovery point PowerShell model objects</returns>
        public List<CmdletModel.RecoveryPointBase> ListRecoveryPoints()
        {
            DateTime startDate = (DateTime)(ProviderData[RecoveryPointParams.StartDate]);
            DateTime endDate = (DateTime)(ProviderData[RecoveryPointParams.EndDate]);
            AzureVmItem item = ProviderData[RecoveryPointParams.Item]
                as AzureVmItem;

            Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri = HelperUtils.GetContainerUri(uriDict, item.Id);
            string protectedItemName = HelperUtils.GetProtectedItemUri(uriDict, item.Id);

            TimeSpan duration = endDate - startDate;
            if (duration.TotalDays > 30)
            {
                throw new Exception(Resources.RestoreDiskTimeRangeError); 
            }

            //we need to fetch the list of RPs
            RecoveryPointQueryParameters queryFilter = new RecoveryPointQueryParameters();
            queryFilter.StartDate = CommonHelpers.GetDateTimeStringForService(startDate);
            queryFilter.EndDate = CommonHelpers.GetDateTimeStringForService(endDate);
            RecoveryPointListResponse rpListResponse = null;

            rpListResponse = ServiceClientAdapter.GetRecoveryPoints(containerUri, protectedItemName, queryFilter);
            return RecoveryPointConversions.GetPSAzureRecoveryPoints(rpListResponse, item);
        }
 /// <summary>
 /// Lists all the recovery points of the given item protected by your
 /// Recovery Services Vault according to the query filter supplied in
 /// the arguments.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IRecoveryPointOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <param name='fabricName'>
 /// Optional. Fabric name of the protected item.
 /// </param>
 /// <param name='containerName'>
 /// Optional. Name of the container where the protected item belongs to.
 /// </param>
 /// <param name='protectedItemName'>
 /// Optional. Name of the protected item whose recovery points are to
 /// be fetched.
 /// </param>
 /// <param name='queryFilter'>
 /// Optional. Query parameters for listing recovery points.
 /// </param>
 /// <returns>
 /// List of recovery points as returned by the service with the list
 /// recovery points call.
 /// </returns>
 public static Task<RecoveryPointListResponse> ListAsync(this IRecoveryPointOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string fabricName, string containerName, string protectedItemName, RecoveryPointQueryParameters queryFilter)
 {
     return operations.ListAsync(resourceGroupName, resourceName, customRequestHeaders, fabricName, containerName, protectedItemName, queryFilter, CancellationToken.None);
 }
 /// <summary>
 /// Lists all the recovery points of the given item protected by your
 /// Recovery Services Vault according to the query filter supplied in
 /// the arguments.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IRecoveryPointOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <param name='fabricName'>
 /// Optional. Fabric name of the protected item.
 /// </param>
 /// <param name='containerName'>
 /// Optional. Name of the container where the protected item belongs to.
 /// </param>
 /// <param name='protectedItemName'>
 /// Optional. Name of the protected item whose recovery points are to
 /// be fetched.
 /// </param>
 /// <param name='queryFilter'>
 /// Optional. Query parameters for listing recovery points.
 /// </param>
 /// <returns>
 /// List of recovery points as returned by the service with the list
 /// recovery points call.
 /// </returns>
 public static RecoveryPointListResponse List(this IRecoveryPointOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string fabricName, string containerName, string protectedItemName, RecoveryPointQueryParameters queryFilter)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRecoveryPointOperations)s).ListAsync(resourceGroupName, resourceName, customRequestHeaders, fabricName, containerName, protectedItemName, queryFilter);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }