/// <summary>
 /// Begin moving resources.To determine whether the operation has
 /// finished processing the request, call
 /// GetLongRunningOperationStatus.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='sourceResourceGroupName'>
 /// Required. Source resource group name.
 /// </param>
 /// <param name='parameters'>
 /// Required. move resources' parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static LongRunningOperationResponse BeginMoving(this IResourceOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters)
 {
     return Task.Factory.StartNew((object s) =>
     {
         return ((IResourceOperations)s).BeginMovingAsync(sourceResourceGroupName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void ResourcesMoveTest()
        {
            var response = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
            };
            response.Headers.Add("x-ms-request-id", "1");
            response.Headers.Add("Location", "http://foo");

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.Accepted,
                SubsequentStatusCodeToReturn = HttpStatusCode.NoContent
            };

            var client = GetResourceManagementClient(handler);

            var resourceToMove = new ResourcesMoveInfo();
            resourceToMove.TargetResourceGroup = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup1";

            var resource1 = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Web/website/website1";
            resourceToMove.Resources.Add(resource1);

            var resource2 = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Compute/hostservice/vm1";
            resourceToMove.Resources.Add(resource2);

            var moveResult = client.Resources.MoveResources("resourceGroup0", resourceToMove);

            // Validate headers 
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));

            // Valid response
            Assert.Equal(moveResult.StatusCode, HttpStatusCode.NoContent);


        }
 /// <summary>
 /// Begin moving resources.To determine whether the operation has
 /// finished processing the request, call
 /// GetLongRunningOperationStatus.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='sourceResourceGroupName'>
 /// Required. Source resource group name.
 /// </param>
 /// <param name='parameters'>
 /// Required. move resources' parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static Task<LongRunningOperationResponse> BeginMovingAsync(this IResourceOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters)
 {
     return operations.BeginMovingAsync(sourceResourceGroupName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// Move resources within or across subscriptions.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Resources.IResourceOperations.
 /// </param>
 /// <param name='sourceResourceGroupName'>
 /// Required. Source resource group name.
 /// </param>
 /// <param name='parameters'>
 /// Required. move resources' parameters.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> MoveResourcesAsync(this IResourceOperations operations, string sourceResourceGroupName, ResourcesMoveInfo parameters)
 {
     return operations.MoveResourcesAsync(sourceResourceGroupName, parameters, CancellationToken.None);
 }
        public void ResourcesMoveTest()
        {
            var response = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
            };
            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };
           
            var client = GetResourceManagementClient(handler);

            var resourceToMove = new ResourcesMoveInfo();
            resourceToMove.TargetResourceGroup = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup1";

            var resource1 = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Web/website/website1";
            resourceToMove.Resources.Add(resource1);

            var resource2 = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/providers/Microsoft.Compute/hostservice/vm1";
            resourceToMove.Resources.Add(resource2);

            var moveResult = client.Resources.MoveResources("resourceGroup0", resourceToMove);

            // Validate headers 
            Assert.Equal(HttpMethod.Post, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("Authorization"));

            //Valid payload
            //Construct expected URL
            string expectedUrl = "/subscriptions/" + Uri.EscapeDataString(client.Credentials.SubscriptionId) + "/resourceGroups/resourceGroup0/moveResources?";
            expectedUrl = expectedUrl + "api-version=2014-04-01-preview";
            string baseUrl = 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 (expectedUrl[0] == '/')
            {
                expectedUrl = expectedUrl.Substring(1);
            }
            expectedUrl = baseUrl + "/" + expectedUrl;
            expectedUrl = expectedUrl.Replace(" ", "%20");

            Assert.Equal(expectedUrl, handler.Uri.ToString());
            
            // Valid response
            Assert.Equal(moveResult.StatusCode, HttpStatusCode.Accepted);
           
           
        }
        /// <summary>
        /// Moves a number of resources from one resource group to another
        /// </summary>
        /// <param name="sourceResourceGroupName"></param>
        /// <param name="destinationResourceGroup"></param>
        /// <param name="resourceIds"></param>
        public virtual AzureOperationResponse MoveResources(string sourceResourceGroupName, string destinationResourceGroup, string[] resourceIds)
        {
            var resourcesMoveInfo = new ResourcesMoveInfo
            {
                Resources = resourceIds,
                TargetResourceGroup = destinationResourceGroup,
            };

            return ResourceManagementClient.Resources.MoveResources(sourceResourceGroupName, resourcesMoveInfo);
        }