/// <summary>
        /// Gets account users available to the authenticated user.
        /// </summary>
        /// <param name="start">the index (0 based) of the first user record, useful for paging</param>
        /// <param name="max">retrieve no more than this many user records</param>
        /// <returns>
        /// a list of available users, observing the start and max constraints
        /// </returns>
        /// <exception cref="TrackViaApiException">if the service fails to process this request</exception>
        /// <exception cref="TrackviaClientException">if an error occurs outside the service, failing the request</exception>
        public List <User> getUsers(int start, int max)
        {
            string path = String.Format("{0}/openapi/users", this._baseUriPath);

            UriBuilder uriBuilder = new UriBuilder()
            {
                Scheme = this._scheme.ToString(),
                Host   = this._hostName,
                Port   = this._port,
                Path   = path,
                Query  = new UriHelper()
                         .SetParameter(ACCESS_TOKEN_QUERY_PARAM, GetAccessToken())
                         .SetParameter(USER_KEY_QUERY_PARAM, GetApiUserKey())
                         .Build()
            };

            string url = uriBuilder.ToString();

            Task <HttpClientResponse> Request = _httpClient.SendGetRequestAsync(url);

            Request.Wait();

            HttpClientResponse Response = Request.Result;

            CheckTrackViaApiResponseForErrors(Response);

            UserRecordSet recordSet = JsonConvert.DeserializeObject <UserRecordSet>(Response.Content);

            return(recordSet.Data);
        }
Exemplo n.º 2
0
        public void TrackViaClient_GetUsers_ShouldReturnListOfUsers()
        {
            // Assemble
            UserRecordSet userRecordSet = TestData.getUnitTestUserRecordSet1();

            Mock <IAsyncHttpClientHelper> httpClient = new Mock <IAsyncHttpClientHelper>();

            TestHelper.HttpClient_SetupGetRequest(HttpStatusCode.OK, userRecordSet, httpClient);

            TrackViaClient client = new TrackViaClient(httpClient.Object, TestHelper.HostName_Fake, TestHelper.ApiKey_Fake);

            // Act
            List <User> usersResponse = client.getUsers(0, 25);

            // Assert
            usersResponse
            .ShouldNotBeNull()
            .Count.ShouldEqual(userRecordSet.Count);
            usersResponse[0]
            .ShouldEqual(userRecordSet.Data[0]);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Create UserRemoteService instance.
            UserRemoteService service = (UserRemoteService)user.GetService(
                DfaService.v1_20.UserRemoteService);

            String searchString = _T("INSERT_SEARCH_STRING_CRITERIA_HERE");

            // Set user search criteria.
            UserSearchCriteria searchCriteria = new UserSearchCriteria();

            searchCriteria.pageSize     = 10;
            searchCriteria.searchString = searchString;

            try {
                // Get users that match the search criteria.
                UserRecordSet users = service.getUsersByCriteria(searchCriteria);

                // Display user names, ids, network ids, subnetwork ids, and group ids.
                if (users != null && users.records != null)
                {
                    foreach (User userResult in users.records)
                    {
                        Console.WriteLine("User with name \"{0}\", id \"{1}\", network id \"{2}\", subnetwork" +
                                          " id \"{3}\", and user group id \"{4}\" was found.", userResult.name, userResult.id,
                                          userResult.networkId, userResult.subnetworkId, userResult.userGroupId);
                    }
                }
                else
                {
                    Console.WriteLine("No users found for your search criteria.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to retrieve users. Exception says \"{0}\"", ex.Message);
            }
        }