コード例 #1
0
        /// <summary>
        /// Returns user properties
        /// </summary>
        /// <param name="email">User email</param>
        /// <returns>(<see cref="UserData"/>) User properties object</returns>
        private static UserData GetUserData(string email)
        {
            SidsTenants.GetSidUd();
            var body = new UserListRequest
            {
                Email = email,
                Pager = new Pager
                {
                    StartRecordIndex = 0,
                    RecordsPerPage   = 2000,
                    SortBy           = "Id",
                    SortDesc         = false,
                    PageIndex        = 0
                }
            };

            var response = RestController.HttpRequestJsonUserDirectory(UriUserDirectory.UserList, Method.POST,
                                                                       Headers, body);

            var userList = JsonConvert.DeserializeObject <UserListResponse>(response);
            var id       = userList?.Rows?.FirstOrDefault()?.Data.Id;

            response = RestController.HttpRequestJsonUserDirectory(
                string.Format(UriUserDirectory.UserById, id), Method.GET, Headers);
            var userModel = JsonConvert.DeserializeObject <UserModel>(response);
            var userData  = userModel.Model;

            return(userData);
        }
コード例 #2
0
        /// <summary>
        /// The method does not really delete user. It changes user email to a random one and sets
        /// this user Status to Disabled. This gives the opportunity to create the same user.
        /// Endpoint Users/Save.
        /// </summary>
        /// <param name="user">User dictionary with keys "Email" and "Password"</param>
        public static void DeleteUser(User user)
        {
            SidsTenants.GetSidUd();
            var userProperties = GetUserData(user);

            if (userProperties == null)
            {
                throw new Exception($"User Directory API: user {user.Email} not found");
            }

            userProperties.Email      = $"Auto{ActionManager.RandomNumber}@autotest.com";
            userProperties.Status.Key = (int)UserStatus.Disabled;

            RestController.HttpRequestJsonUserDirectory(UriUserDirectory.UserSave,
                                                        Method.POST,
                                                        Headers,
                                                        userProperties);
        }
コード例 #3
0
        /// <summary>
        /// Makes a form-data HTTP(S) request to any web service</summary>
        /// <param name="url">Endpoint full URL</param>
        /// <param name="method">HTTP request method (see <see cref="Method"/>)</param>
        /// <param name="headers">Additional request header parameters (optional)</param>
        /// <param name="parameters">Form parameters in request (optional)</param>
        /// <returns>(<see cref="string"/>) Response body</returns>
        internal static string HttpRequestForm(
            string url,
            Method method,
            IDictionary <string, string> headers    = null,
            IDictionary <string, object> parameters = null)
        {
            SidsTenants.GetSidUd();
            var request = new RestRequest(url, method)
            {
                Timeout = TestConfig.ApiRequestTimeout
            };

            if (headers != null && headers.Count > 0)
            {
                foreach (var header in headers)
                {
                    request.AddHeader(header.Key, header.Value);
                }
            }

            if (parameters != null && parameters.Count > 0)
            {
                foreach (var parameter in parameters)
                {
                    if (parameter.Key != null)
                    {
                        request.AddParameter(parameter.Key, parameter.Value);
                    }
                }
            }

            var client   = new RestClient(TestConfig.UserDirectoryBaseUrlApi);
            var response = client.Execute(request);

            // when no response from service, try one more time
            if (response.StatusCode == 0)
            {
                response = client.Execute(request);
            }

            ResponseValidator(response);
            return(response.Content);
        }
コード例 #4
0
        /// <summary>
        /// Returns application properties object
        /// </summary>
        /// <param name="applicationName">Application name to find</param>
        /// <returns>(<see cref="ApplicationData"/>) Application properties object</returns>
        private static ApplicationData GetApplicationProperties(string applicationName)
        {
            SidsTenants.GetSidUd();
            var body = new ApplicationListRequest
            {
                Name  = applicationName,
                Pager = new Pager
                {
                    StartRecordIndex = 0,
                    RecordsPerPage   = 2000,
                    SortBy           = "Id",
                    SortDesc         = false,
                    PageIndex        = 0
                }
            };

            var response = RestController.HttpRequestJsonUserDirectory(UriUserDirectory.ApplicationList, Method.POST,
                                                                       Headers, body);

            var applicationList = JsonConvert.DeserializeObject <ApplicationListResponse>(response);
            var appProperties   = applicationList?.Rows?.FirstOrDefault()?.Data;

            return(appProperties);
        }