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);
            }
        }
Ejemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            GetAccountResult response = null;

            response = CallClient(() => Client.Account.Get(), Client.Account);

            if (response != null)
            {
                Workspace workspace = new Workspace(response);
                WriteObject(workspace);
            }
        }
        public void CanGetAccount()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();

                RemoteAppManagementClient client        = GetRemoteAppManagementClient();
                GetAccountResult          accountResult = client.Account.Get();

                Assert.NotNull(accountResult);
                Assert.NotNull(accountResult.Details);
                Assert.False(string.IsNullOrWhiteSpace(accountResult.Details.ClientUrl), "The client URL is empty.");
                Assert.False(string.IsNullOrWhiteSpace(accountResult.Details.EndUserFeedName), "The Workspace name is empty.");
            }
        }
Ejemplo n.º 4
0
        public async Task Then_Gets_Account_From_Mediator(
            string hashedAccountId,
            GetAccountResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] AccountsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetAccountQuery>(x => x.HashedAccountId == hashedAccountId),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.Get(hashedAccountId) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetAccountResult;

            Assert.IsNotNull(model);
            model.Should().BeEquivalentTo(mediatorResult);
        }
Ejemplo n.º 5
0
        public static void SetUpDefaultWorkspace(Mock <IRemoteAppManagementClient> clientMock, string clientUrl, string endUserFeedName)
        {
            ISetup <IRemoteAppManagementClient, Task <GetAccountResult> > Setup = null;
            GetAccountResult response = new GetAccountResult()
            {
                RequestId  = "7834-12346",
                StatusCode = System.Net.HttpStatusCode.OK,
                Details    = new AccountDetails()
                {
                    ClientUrl       = clientUrl,
                    EndUserFeedName = endUserFeedName
                }
            };

            mockWorkspace = new List <Workspace>()
            {
                new Workspace(response)
            };

            Setup = clientMock.Setup(c => c.Account.GetAsync(It.IsAny <CancellationToken>()));
            Setup.Returns(Task.Factory.StartNew(() => response));
        }
Ejemplo n.º 6
0
        public async Task Then_Gets_Account_From_Mediator(
            string encodedAccountId,
            GetAccountResult getAccountResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] AccountController accountController)
        {
            mockMediator
            .Setup(x => x.Send(
                       It.Is <GetAccountQuery>(y => y.EncodedAccountId.Equals(encodedAccountId)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(getAccountResult);

            var controllerResult = await accountController.GetAccount(encodedAccountId) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            Assert.AreEqual(controllerResult.StatusCode, (int)HttpStatusCode.OK);

            var model = controllerResult.Value as AccountDto;

            Assert.IsNotNull(model);
            Assert.AreEqual(getAccountResult.Account.RemainingTransferAllowance, model.RemainingTransferAllowance);
        }
        /// <summary>
        /// Gets the details of the account.
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Definition for result of GetAccount operaton.
        /// </returns>
        public async Task <GetAccountResult> GetAsync(CancellationToken cancellationToken)
        {
            // Validate

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

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                TracingAdapter.Enter(invocationId, this, "GetAsync", 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.Get;
                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);

                // 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
                    GetAccountResult result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

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

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            AccountDetails detailsInstance = new AccountDetails();
                            result.Details = detailsInstance;

                            JToken maxPublishedAppsPerServiceValue = responseDoc["MaxPublishedAppsPerService"];
                            if (maxPublishedAppsPerServiceValue != null && maxPublishedAppsPerServiceValue.Type != JTokenType.Null)
                            {
                                int maxPublishedAppsPerServiceInstance = ((int)maxPublishedAppsPerServiceValue);
                                detailsInstance.MaxPublishedAppsPerCollection = maxPublishedAppsPerServiceInstance;
                            }

                            JToken contactEmailValue = responseDoc["ContactEmail"];
                            if (contactEmailValue != null && contactEmailValue.Type != JTokenType.Null)
                            {
                                string contactEmailInstance = ((string)contactEmailValue);
                                detailsInstance.ContactEmail = contactEmailInstance;
                            }

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

                            JToken maxServicesValue = responseDoc["MaxServices"];
                            if (maxServicesValue != null && maxServicesValue.Type != JTokenType.Null)
                            {
                                int maxServicesInstance = ((int)maxServicesValue);
                                detailsInstance.MaxCollections = maxServicesInstance;
                            }

                            JToken maxUsersPerServiceValue = responseDoc["MaxUsersPerService"];
                            if (maxUsersPerServiceValue != null && maxUsersPerServiceValue.Type != JTokenType.Null)
                            {
                                int maxUsersPerServiceInstance = ((int)maxUsersPerServiceValue);
                                detailsInstance.MaxUsersPerCollection = maxUsersPerServiceInstance;
                            }

                            JToken optIntoMarketingEmailValue = responseDoc["OptIntoMarketingEmail"];
                            if (optIntoMarketingEmailValue != null && optIntoMarketingEmailValue.Type != JTokenType.Null)
                            {
                                bool optIntoMarketingEmailInstance = ((bool)optIntoMarketingEmailValue);
                                detailsInstance.OptIntoMarketingEmail = optIntoMarketingEmailInstance;
                            }

                            JToken isDesktopEnabledValue = responseDoc["IsDesktopEnabled"];
                            if (isDesktopEnabledValue != null && isDesktopEnabledValue.Type != JTokenType.Null)
                            {
                                bool isDesktopEnabledInstance = ((bool)isDesktopEnabledValue);
                                detailsInstance.DesktopEnabled = isDesktopEnabledInstance;
                            }

                            JToken rdWebUrlValue = responseDoc["RdWebUrl"];
                            if (rdWebUrlValue != null && rdWebUrlValue.Type != JTokenType.Null)
                            {
                                string rdWebUrlInstance = ((string)rdWebUrlValue);
                                detailsInstance.ClientUrl = rdWebUrlInstance;
                            }

                            JToken workspaceNameValue = responseDoc["WorkspaceName"];
                            if (workspaceNameValue != null && workspaceNameValue.Type != JTokenType.Null)
                            {
                                string workspaceNameInstance = ((string)workspaceNameValue);
                                detailsInstance.EndUserFeedName = workspaceNameInstance;
                            }
                        }
                    }
                    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();
                }
            }
        }
Ejemplo n.º 8
0
 public Workspace(GetAccountResult accountResult)
 {
     ClientUrl       = accountResult.Details.ClientUrl;
     EndUserFeedName = accountResult.Details.EndUserFeedName;
 }
Ejemplo n.º 9
0
 public Workspace(GetAccountResult accountResult)
 {
     ClientUrl = accountResult.Details.ClientUrl;
     EndUserFeedName = accountResult.Details.EndUserFeedName;
 }