public void UndeleteStorageAccounts()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token  = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);
            StorageAccountUndeleteParameters para = new StorageAccountUndeleteParameters();
            var result = client.StorageAccounts.Undelete(Constants.ResourceGroupName, Constants.FarmId, "myaccount", para);

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Post);

            var expectedUri = string.Format(
                UndeleteUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                "myaccount");

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            // Validate headers
            Assert.Equal(HttpMethod.Post, handler.Method);
        }
        protected override void Execute()
        {
            StorageAccountUndeleteParameters undeleteParam = new StorageAccountUndeleteParameters
            {
                NewAccountName = NewAccountName
            };

            if (ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.StorageAccountAdminView, AccountId),
                    string.Format(CultureInfo.InvariantCulture, Resources.UndeleteOperation)))
            {
                var response = Client.StorageAccounts.Undelete(ResourceGroupName, FarmName, AccountId, undeleteParam);
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.FailedToUndeleteAccount));
                }

                // get recovered account to set parameters for resource sync
                WriteVerbose(Resources.RetrieveUndeletedStorageAccount);
                StorageAccountListResponse accounts = Client.StorageAccounts.List(ResourceGroupName, FarmName, "{accountid eq '" + AccountId + "'}", true);
                if (accounts.StatusCode != System.Net.HttpStatusCode.OK ||
                    accounts.StorageAccounts.Count == 0 ||
                    accounts.StorageAccounts[0].Properties == null ||
                    accounts.StorageAccounts[0].Properties.TenantSubscriptionId.Equals(Guid.Empty) == true ||
                    accounts.StorageAccounts[0].Properties.TenantViewId == null ||
                    accounts.StorageAccounts[0].Properties.TenantResourceGroupName == null ||
                    accounts.StorageAccounts[0].Location == null)
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.FailedToGetAccount));
                }

                // trigger resource sync
                WriteVerbose(Resources.TriggerResourceSync);
                StorageAccountSyncRequest req = new StorageAccountSyncRequest();
                if (StorageAccountApiVersion == null)
                {
                    StorageAccountApiVersion = SyncDefaultStorageAccountApiVersion;
                }
                if (string.IsNullOrEmpty(ResourceAdminApiVersion))
                {
                    ResourceAdminApiVersion = SyncDefaultResourceAdminApiVersion;
                }
                req.ApiVersion       = StorageAccountApiVersion;
                req.TargetOperaton   = SyncTargetOperation;
                req.ResourceLocation = accounts.StorageAccounts[0].Location;
                req.Id = accounts.StorageAccounts[0].Properties.TenantViewId;

                Client.StorageAccounts.Sync(accounts.StorageAccounts[0].Properties.TenantSubscriptionId.ToString(), accounts.StorageAccounts[0].Properties.TenantResourceGroupName, ResourceAdminApiVersion, req);

                WriteWarning(Resources.WaitAfterArmSync);
            }
        }
        protected override void Execute()
        {
            StorageAccountUndeleteParameters undeleteParam = new StorageAccountUndeleteParameters
            {
                NewAccountName = NewAccountName
            };
            if (ShouldProcess(
                    string.Format(CultureInfo.InvariantCulture, Resources.StorageAccountAdminView, AccountId),
                    string.Format(CultureInfo.InvariantCulture, Resources.UndeleteOperation)))
            {
                var response = Client.StorageAccounts.Undelete(ResourceGroupName, FarmName, AccountId.ToString(CultureInfo.InvariantCulture), undeleteParam);
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.FailedToUndeleteAccount));
                }

                // get recovered account to set parameters for resource sync
                WriteVerbose(Resources.RetrieveUndeletedStorageAccount);
                StorageAccountListResponse accounts = Client.StorageAccounts.List(ResourceGroupName, FarmName, "{versionedaccountname eq '" + AccountId + "'}", true);
                if (accounts.StatusCode != System.Net.HttpStatusCode.OK ||
                    accounts.StorageAccounts.Count == 0 ||
                    accounts.StorageAccounts[0].Properties == null ||
                    accounts.StorageAccounts[0].Properties.TenantSubscriptionId.Equals(Guid.Empty) == true ||
                    accounts.StorageAccounts[0].Properties.TenantViewId == null ||
                    accounts.StorageAccounts[0].Properties.TenantResourceGroupName == null ||
                    accounts.StorageAccounts[0].Location == null)
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, Resources.FailedToGetAccount));
                }

                // trigger resource sync
                WriteVerbose(Resources.TriggerResourceSync);
                StorageAccountSyncRequest req = new StorageAccountSyncRequest();
                if (StorageAccountApiVersion == null)
                    StorageAccountApiVersion = SyncStorageAccount.DefaultStorageAccountApiVersion;
                req.ApiVersion = StorageAccountApiVersion;
                req.TargetOperaton = SyncStorageAccount.SyncTargetOperation;
                req.ResourceLocation = accounts.StorageAccounts[0].Location;
                req.Id = accounts.StorageAccounts[0].Properties.TenantViewId;

                Client.StorageAccounts.Sync(accounts.StorageAccounts[0].Properties.TenantSubscriptionId.ToString(), accounts.StorageAccounts[0].Properties.TenantResourceGroupName, req);

                WriteWarning(Resources.WaitAfterArmSync);
            }
        }
        public void UndeleteStorageAccounts()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            var subscriptionId = Guid.NewGuid().ToString();

            var token = new TokenCloudCredentials(subscriptionId, Constants.TokenString);
            var client = GetClient(handler, token);
            StorageAccountUndeleteParameters para = new StorageAccountUndeleteParameters();
            var result = client.StorageAccounts.Undelete(Constants.ResourceGroupName, Constants.FarmId, "myaccount", para);

            // validate requestor
            Assert.Equal(handler.Method, HttpMethod.Post);

            var expectedUri = string.Format(
                UndeleteUriTemplate,
                Constants.BaseUri,
                subscriptionId,
                Constants.ResourceGroupName,
                Constants.FarmId,
                "myaccount");

            Assert.Equal(handler.Uri.AbsoluteUri, expectedUri);

            // Validate headers 
            Assert.Equal(HttpMethod.Post, handler.Method);
        }