public async Task GetUserByIdAsyncTest() { // Create the user var created = await UserHelper.CreateNewUserAsync(); await AppContext.LoginAsync(new UsernamePasswordCredentials(created.Username, created.Password)); // Setup user token string token = await UserHelper.AuthenticateAsync(created.Username, created.Password); // Get the created user GetUserResponse getUserResponse = null; var getUserRequest = new GetUserRequest() { UserId = created.Id }; getUserResponse = await getUserRequest.ExecuteAsync(); ApiHelper.EnsureValidResponse(getUserResponse); Assert.IsNotNull(getUserResponse.User); Assert.IsTrue(getUserResponse.User.Username == created.Username); Assert.IsTrue(getUserResponse.User.FirstName == created.FirstName); Assert.IsTrue(getUserResponse.User.LastName == created.LastName); Assert.IsTrue(getUserResponse.User.Email == created.Email); Assert.IsTrue(getUserResponse.User.DateOfBirth == created.DateOfBirth); Assert.IsTrue(getUserResponse.User.Phone == created.Phone); var user2 = getUserResponse.User; Console.WriteLine("Username: {0}", user2.Username); Console.WriteLine("Firstname: {0}", user2.FirstName); Console.WriteLine("Lastname: {0}", user2.LastName); Console.WriteLine("Email: {0}", user2.Email); Console.WriteLine("Birthdate: {0}", user2.DateOfBirth); Console.WriteLine("Phone: {0}", user2.Phone); }
public static async Task<User> GetExistingUserAsync(string id) { Console.WriteLine("Getting existing user with id {0}.", id); var getRequest = new GetUserRequest() { UserId = id }; var getResponse = await getRequest.ExecuteAsync(); Assert.IsNotNull(getResponse, "Cannot get updated user for user id {0}.", id); Assert.IsNotNull(getResponse.Status, "Status for get user call is null."); if (getResponse.Status.IsSuccessful == false) Assert.Fail(getResponse.Status.Message); Assert.IsNotNull(getResponse.User, "Get user for id {0} returned null.", id); return getResponse.User; }
/// <summary> /// Gets an existing user by user session token. /// </summary> /// <param name="token">User session token.</param> /// <param name="fields">The user fields to be retrieved.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> public static async Task<APUser> GetUserByTokenAsync(string token, IEnumerable<string> fields = null, ApiOptions options = null) { var request = new GetUserRequest { UserIdType = "token", UserToken = token }; if (fields != null) request.Fields.AddRange(fields); ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); Debug.Assert(response.User != null, "For a successful get call, object should always be returned."); return response.User; }
/// <summary> /// Get user by id. /// </summary> /// <param name="id">Id of the user article</param> /// <param name="fields">Optional fields that you want to get. </param> /// <returns>The user with the specified id</returns> public static async Task<User> GetByUsernameAsync(string username, IEnumerable<string> fields = null) { var request = new GetUserRequest { UserId = username, UserIdType = "username" }; if (fields != null) request.Fields.AddRange(fields); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); Debug.Assert(response.User != null, "For a successful get call, article should always be returned."); return response.User; }
public async Task<GetUserResponse> GetUserAsync(GetUserRequest request) { byte[] bytes = null; bytes = await HttpOperation .WithUrl(Urls.For.GetUser(request.UserId, request.UserIdType, request.CurrentLocation, request.DebugEnabled, request.Verbosity, request.Fields)) .WithAppacitiveSession(request.SessionToken) .WithEnvironment(request.Environment) .WithUserToken(request.UserToken) .GetAsync(); var response = GetUserResponse.Parse(bytes); return response; }
/// <summary> /// Get user by id. /// </summary> /// <param name="id">Id of the user article</param> /// <param name="fields">Optional fields that you want to get. </param> /// <returns>The user with the specified id</returns> public static async Task<User> GetByIdAsync(string id, IEnumerable<string> fields = null) { var service = ObjectFactory.Build<IUserService>(); var request = new GetUserRequest { UserId = id }; if (fields != null) request.Fields.AddRange(fields); var response = await service.GetUserAsync(request); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); Debug.Assert(response.User != null, "For a successful get call, article should always be returned."); return response.User; }
public async Task GetUserByUsernameAsyncTest() { // Create the user var created = await UserHelper.CreateNewUserAsync(); // Setup user token string token = await UserHelper.AuthenticateAsync(created.Username, created.Password); App.SetLoggedInUser(token); // Get the created user IUserService userService = new UserService(); // Get the created user var getUserRequest = new GetUserRequest() { UserId = created.Username, UserIdType = "username" }; var getUserResponse = await userService.GetUserAsync(getUserRequest); ApiHelper.EnsureValidResponse(getUserResponse); Assert.IsNotNull(getUserResponse.User); Assert.IsTrue(getUserResponse.User.Username == created.Username); Assert.IsTrue(getUserResponse.User.FirstName == created.FirstName); Assert.IsTrue(getUserResponse.User.LastName == created.LastName); Assert.IsTrue(getUserResponse.User.Email == created.Email); Assert.IsTrue(getUserResponse.User.DateOfBirth == created.DateOfBirth); Assert.IsTrue(getUserResponse.User.Phone == created.Phone); var user2 = getUserResponse.User; Console.WriteLine("Username: {0}", user2.Username); Console.WriteLine("Firstname: {0}", user2.FirstName); Console.WriteLine("Lastname: {0}", user2.LastName); Console.WriteLine("Email: {0}", user2.Email); Console.WriteLine("Birthdate: {0}", user2.DateOfBirth); Console.WriteLine("Phone: {0}", user2.Phone); }
public async Task GetUserByTokenAsyncTest() { // Create the user var created = await UserHelper.CreateNewUserAsync(); // Setup user token var token = await UserHelper.AuthenticateAsync(created.Username, created.Password); App.UserToken = token; // Get the created user var getUserRequest = new GetUserRequest() { UserId = token, UserIdType = "token" }; var getUserResponse = await getUserRequest.ExecuteAsync(); ApiHelper.EnsureValidResponse(getUserResponse); Assert.IsNotNull(getUserResponse.User); Assert.IsTrue(getUserResponse.User.Username == created.Username); Assert.IsTrue(getUserResponse.User.FirstName == created.FirstName); Assert.IsTrue(getUserResponse.User.LastName == created.LastName); Assert.IsTrue(getUserResponse.User.Email == created.Email); Assert.IsTrue(getUserResponse.User.DateOfBirth == created.DateOfBirth); Assert.IsTrue(getUserResponse.User.Phone == created.Phone); var user2 = getUserResponse.User; Console.WriteLine("Username: {0}", user2.Username); Console.WriteLine("Firstname: {0}", user2.FirstName); Console.WriteLine("Lastname: {0}", user2.LastName); Console.WriteLine("Email: {0}", user2.Email); Console.WriteLine("Birthdate: {0}", user2.DateOfBirth); Console.WriteLine("Phone: {0}", user2.Phone); }