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

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

                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgName"];
                string resourceName      = ConfigurationManager.AppSettings["RsVaultName"];
                string fabricName        = ConfigurationManager.AppSettings["AzureBackupFabricName"];

                string containerUniqueName = ConfigurationManager.AppSettings[TestConstants.AzureSqlContainerName];
                string containeType        = ConfigurationManager.AppSettings[TestConstants.ContainerTypeAzureSql];
                string containerUri        = containeType + ";" + containerUniqueName;

                string itemUniqueName = ConfigurationManager.AppSettings[TestConstants.AzureSqlItemName];
                string itemType       = ConfigurationManager.AppSettings[TestConstants.WorkloadTypeAzureSqlDb];
                string itemUri        = itemType + ";" + itemUniqueName;
                string rpId           = ConfigurationManager.AppSettings[TestConstants.AzureSqlRpId];

                var response = client.RecoveryPoints.Get(resourceGroupName, resourceName, CommonTestHelper.GetCustomRequestHeaders(),
                                                         fabricName, containerUri, itemUri, rpId);

                var rpo = response.RecPoint;
                Assert.NotNull(rpo);
                Assert.True(!string.IsNullOrEmpty(rpo.Name), "RP Id cant be null");
                GenericRecoveryPoint rp = rpo.Properties as GenericRecoveryPoint;
                Assert.True(!string.IsNullOrEmpty(rp.RecoveryPointTime), "RecoveryPointTime can't be null or empty");
            }
        }
        public void ListRecoveryPointTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

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

                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgName"];
                string resourceName      = ConfigurationManager.AppSettings["RsVaultName"];
                string fabricName        = ConfigurationManager.AppSettings["AzureBackupFabricName"];

                string containerUniqueName = ConfigurationManager.AppSettings[TestConstants.AzureSqlContainerName];
                string containeType        = ConfigurationManager.AppSettings[TestConstants.ContainerTypeAzureSql];
                string containerUri        = containeType + ";" + containerUniqueName;

                string itemUniqueName = ConfigurationManager.AppSettings[TestConstants.AzureSqlItemName];
                string itemType       = ConfigurationManager.AppSettings[TestConstants.WorkloadTypeAzureSqlDb];
                string itemUri        = itemType + ";" + itemUniqueName;

                DateTime startTime = new DateTime(2016, 6, 13, 15, 25, 9, DateTimeKind.Utc);
                DateTime endTime   = new DateTime(2016, 6, 16, 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");
                    GenericRecoveryPoint rp = rpo.Properties as GenericRecoveryPoint;
                    Assert.True(!string.IsNullOrEmpty(rp.RecoveryPointTime), "RecoveryPointTime can't be null or empty");
                }
            }
        }
        /// <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='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>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// List of recovery points as returned by the service with the list
        /// recovery points call.
        /// </returns>
        public async Task <RecoveryPointListResponse> ListAsync(string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string fabricName, string containerName, string protectedItemName, RecoveryPointQueryParameters queryFilter, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (resourceName == null)
            {
                throw new ArgumentNullException("resourceName");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("resourceName", resourceName);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                tracingParameters.Add("fabricName", fabricName);
                tracingParameters.Add("containerName", containerName);
                tracingParameters.Add("protectedItemName", protectedItemName);
                tracingParameters.Add("queryFilter", queryFilter);
                TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/";
            if (this.Client.ResourceNamespace != null)
            {
                url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            }
            url = url + "/";
            url = url + "vaults";
            url = url + "/";
            url = url + Uri.EscapeDataString(resourceName);
            url = url + "/backupFabrics/";
            if (fabricName != null)
            {
                url = url + Uri.EscapeDataString(fabricName);
            }
            url = url + "/protectionContainers/";
            if (containerName != null)
            {
                url = url + Uri.EscapeDataString(containerName);
            }
            url = url + "/protectedItems/";
            if (protectedItemName != null)
            {
                url = url + Uri.EscapeDataString(protectedItemName);
            }
            url = url + "/recoveryPoints";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2016-05-01");
            List <string> odataFilter = new List <string>();

            if (queryFilter != null && queryFilter.StartDate != null)
            {
                odataFilter.Add("startDate eq '" + Uri.EscapeDataString(queryFilter.StartDate) + "'");
            }
            if (queryFilter != null && queryFilter.EndDate != null)
            {
                odataFilter.Add("endDate eq '" + Uri.EscapeDataString(queryFilter.EndDate) + "'");
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(" and ", odataFilter));
            }
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept-Language", customRequestHeaders.Culture);
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    RecoveryPointListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new RecoveryPointListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            RecoveryPointResourceList recoveryPointListInstance = new RecoveryPointResourceList();
                            result.RecoveryPointList = recoveryPointListInstance;

                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    RecoveryPointResource recoveryPointResourceInstance = new RecoveryPointResource();
                                    recoveryPointListInstance.RecoveryPoints.Add(recoveryPointResourceInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        string typeName = ((string)propertiesValue["objectType"]);
                                        if (typeName == "IaasVMRecoveryPoint")
                                        {
                                            RecoveryPoint recoveryPointInstance = new RecoveryPoint();

                                            JToken recoveryPointTypeValue = propertiesValue["recoveryPointType"];
                                            if (recoveryPointTypeValue != null && recoveryPointTypeValue.Type != JTokenType.Null)
                                            {
                                                string recoveryPointTypeInstance = ((string)recoveryPointTypeValue);
                                                recoveryPointInstance.RecoveryPointType = recoveryPointTypeInstance;
                                            }

                                            JToken recoveryPointTimeValue = propertiesValue["recoveryPointTime"];
                                            if (recoveryPointTimeValue != null && recoveryPointTimeValue.Type != JTokenType.Null)
                                            {
                                                string recoveryPointTimeInstance = ((string)recoveryPointTimeValue);
                                                recoveryPointInstance.RecoveryPointTime = recoveryPointTimeInstance;
                                            }

                                            JToken recoveryPointAdditionalInfoValue = propertiesValue["recoveryPointAdditionalInfo"];
                                            if (recoveryPointAdditionalInfoValue != null && recoveryPointAdditionalInfoValue.Type != JTokenType.Null)
                                            {
                                                string recoveryPointAdditionalInfoInstance = ((string)recoveryPointAdditionalInfoValue);
                                                recoveryPointInstance.RecoveryPointAdditionalInfo = recoveryPointAdditionalInfoInstance;
                                            }

                                            JToken sourceVMStorageTypeValue = propertiesValue["sourceVMStorageType"];
                                            if (sourceVMStorageTypeValue != null && sourceVMStorageTypeValue.Type != JTokenType.Null)
                                            {
                                                string sourceVMStorageTypeInstance = ((string)sourceVMStorageTypeValue);
                                                recoveryPointInstance.SourceVMStorageType = sourceVMStorageTypeInstance;
                                            }
                                            recoveryPointResourceInstance.Properties = recoveryPointInstance;
                                        }
                                        if (typeName == "GenericRecoveryPoint")
                                        {
                                            GenericRecoveryPoint genericRecoveryPointInstance = new GenericRecoveryPoint();

                                            JToken recoveryPointTypeValue2 = propertiesValue["recoveryPointType"];
                                            if (recoveryPointTypeValue2 != null && recoveryPointTypeValue2.Type != JTokenType.Null)
                                            {
                                                string recoveryPointTypeInstance2 = ((string)recoveryPointTypeValue2);
                                                genericRecoveryPointInstance.RecoveryPointType = recoveryPointTypeInstance2;
                                            }

                                            JToken recoveryPointTimeValue2 = propertiesValue["recoveryPointTime"];
                                            if (recoveryPointTimeValue2 != null && recoveryPointTimeValue2.Type != JTokenType.Null)
                                            {
                                                string recoveryPointTimeInstance2 = ((string)recoveryPointTimeValue2);
                                                genericRecoveryPointInstance.RecoveryPointTime = recoveryPointTimeInstance2;
                                            }

                                            JToken recoveryPointAdditionalInfoValue2 = propertiesValue["recoveryPointAdditionalInfo"];
                                            if (recoveryPointAdditionalInfoValue2 != null && recoveryPointAdditionalInfoValue2.Type != JTokenType.Null)
                                            {
                                                string recoveryPointAdditionalInfoInstance2 = ((string)recoveryPointAdditionalInfoValue2);
                                                genericRecoveryPointInstance.RecoveryPointAdditionalInfo = recoveryPointAdditionalInfoInstance2;
                                            }
                                            recoveryPointResourceInstance.Properties = genericRecoveryPointInstance;
                                        }
                                    }

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        string idInstance = ((string)idValue);
                                        recoveryPointResourceInstance.Id = idInstance;
                                    }

                                    JToken nameValue = valueValue["name"];
                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                    {
                                        string nameInstance = ((string)nameValue);
                                        recoveryPointResourceInstance.Name = nameInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        recoveryPointResourceInstance.Type = typeInstance;
                                    }

                                    JToken locationValue = valueValue["location"];
                                    if (locationValue != null && locationValue.Type != JTokenType.Null)
                                    {
                                        string locationInstance = ((string)locationValue);
                                        recoveryPointResourceInstance.Location = locationInstance;
                                    }

                                    JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
                                    if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property in tagsSequenceElement)
                                        {
                                            string tagsKey   = ((string)property.Name);
                                            string tagsValue = ((string)property.Value);
                                            recoveryPointResourceInstance.Tags.Add(tagsKey, tagsValue);
                                        }
                                    }

                                    JToken eTagValue = valueValue["eTag"];
                                    if (eTagValue != null && eTagValue.Type != JTokenType.Null)
                                    {
                                        string eTagInstance = ((string)eTagValue);
                                        recoveryPointResourceInstance.ETag = eTagInstance;
                                    }
                                }
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                recoveryPointListInstance.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }