public async Task GetUserByIdAsyncTest() { // Create the user var created = await UserHelper.CreateNewUserAsync(); // Setup user token string token = await UserHelper.AuthenticateAsync(created.Username, created.Password); // Get the created user GetUserResponse getUserResponse = null; IUserService userService = new UserService(); App.SetLoggedInUser(token); var getUserRequest = new GetUserRequest() { UserId = created.Id }; 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 static async Task<User> GetExistingUserAsync(string id) { Console.WriteLine("Getting existing user with id {0}.", id); IUserService userService = new UserService(); var getRequest = new GetUserRequest() { UserId = id }; var getResponse = await userService.GetUserAsync(getRequest); 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; }
public async Task DeleteUserAsyncTest() { // Create new user var newUser = await UserHelper.CreateNewUserAsync(); // Authenticate the user var token = await UserHelper.AuthenticateAsync(newUser.Username, newUser.Password); App.SetLoggedInUser(token); // Delete the user var request = new DeleteUserRequest() { UserId = newUser.Id }; IUserService userService = new UserService(); var response = await userService.DeleteUserAsync(request); ApiHelper.EnsureValidResponse(response); // Try to get the user var getResponse = await userService.GetUserAsync(new GetUserRequest() { UserId = newUser.Id }); ApiHelper.EnsureValidResponse(getResponse, false); Assert.IsFalse(getResponse.Status.IsSuccessful, "Get for an non-existant user did not fail."); Console.WriteLine("Get user error message: {0}", getResponse.Status.Message); }