public void CanSetAccount() { using (var undoContext = UndoContext.Current) { undoContext.Start(); RemoteAppManagementClient client = GetRemoteAppManagementClient(); GetAccountResult accountResult = client.Account.Get(); Assert.NotNull(accountResult); Assert.NotNull(accountResult.Details); string oldName = accountResult.Details.EndUserFeedName; string newName = "TestWorkspaceName"; AccountDetailsParameter param = new AccountDetailsParameter(); param.AccountInfo = new AccountUpdateDetails();//accountResult.Details; param.AccountInfo.EndUserFeedName = newName; OperationResultWithTrackingId result = client.Account.Set(param); Assert.NotNull(result); accountResult = client.Account.Get(); Assert.Equal(newName, accountResult.Details.EndUserFeedName); param.AccountInfo.EndUserFeedName = oldName; result = client.Account.Set(param); Assert.NotNull(result); } }
public static void SetUpDefaultEditWorkspace(Mock <IRemoteAppManagementClient> clientMock, string endUserFeedName) { ISetup <IRemoteAppManagementClient, Task <OperationResultWithTrackingId> > Setup = null; AccountDetailsParameter details = new AccountDetailsParameter() { AccountInfo = new AccountDetails() { EndUserFeedName = endUserFeedName } }; OperationResultWithTrackingId response = new OperationResultWithTrackingId() { StatusCode = System.Net.HttpStatusCode.Accepted, TrackingId = "34167", RequestId = "111-2222-4444" }; mockTrackingId = new List <TrackingResult>() { new TrackingResult(response) }; Setup = clientMock.Setup(c => c.Account.SetAsync(It.IsAny <AccountDetailsParameter>(), It.IsAny <CancellationToken>())); Setup.Returns(Task.Factory.StartNew(() => response)); }
public override void ExecuteCmdlet() { AccountDetailsParameter details = new AccountDetailsParameter() { AccountInfo = new AccountDetails() { EndUserFeedName = WorkspaceName } }; CallClient(() => Client.Account.Set(details), Client.Account); }
public override void ExecuteCmdlet() { OperationResultWithTrackingId response = null; AccountDetailsParameter details = new AccountDetailsParameter() { AccountInfo = new AccountDetails() { EndUserFeedName = WorkspaceName } }; response = CallClient(() => Client.Account.Set(details), Client.Account); if (response != null) { WriteTrackingId(response); } }
/// <summary> /// Sets the new details of the account. /// </summary> /// <param name='accountInfo'> /// Required. New details of account. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response containing the operation tracking id. /// </returns> public async Task <OperationResultWithTrackingId> SetAsync(AccountDetailsParameter accountInfo, CancellationToken cancellationToken) { // Validate if (accountInfo == null) { throw new ArgumentNullException("accountInfo"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("accountInfo", accountInfo); TracingAdapter.Enter(invocationId, this, "SetAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/services/"; if (this.Client.RdfeNamespace != null) { url = url + Uri.EscapeDataString(this.Client.RdfeNamespace); } url = url + "/account"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-09-01"); 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.Put; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/json; charset=utf-8"); httpRequest.Headers.Add("x-ms-version", "2014-08-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; JToken requestDoc = null; JObject accountDetailsParameterValue = new JObject(); requestDoc = accountDetailsParameterValue; if (accountInfo.AccountInfo != null) { if (accountInfo.AccountInfo.EndUserFeedName != null) { accountDetailsParameterValue["WorkspaceName"] = accountInfo.AccountInfo.EndUserFeedName; } } requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); // 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, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result OperationResultWithTrackingId result = null; // Deserialize Response result = new OperationResultWithTrackingId(); result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// Sets the new details of the account. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RemoteApp.IAccountsOperations. /// </param> /// <param name='accountInfo'> /// Required. New details of account. /// </param> /// <returns> /// The response containing the operation tracking id. /// </returns> public static Task <OperationResultWithTrackingId> SetAsync(this IAccountsOperations operations, AccountDetailsParameter accountInfo) { return(operations.SetAsync(accountInfo, CancellationToken.None)); }
/// <summary> /// Sets the new details of the account. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.RemoteApp.IAccountsOperations. /// </param> /// <param name='accountInfo'> /// Required. New details of account. /// </param> /// <returns> /// The response containing the operation tracking id. /// </returns> public static OperationResultWithTrackingId Set(this IAccountsOperations operations, AccountDetailsParameter accountInfo) { return(Task.Factory.StartNew((object s) => { return ((IAccountsOperations)s).SetAsync(accountInfo); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }