Example #1
0
        public async Task Test_users_crud_sequence()
        {
            // Get all the users
            var usersBefore = await apiClient.Users.GetAllAsync();

            // Add a new user
            var newUserRequest = new UserCreateRequest
            {
                Connection = connection.Name,
                Email = $"{Guid.NewGuid().ToString("N")}@nonexistingdomain.aaa",
                EmailVerified = true,
                Password = "******"
            };
            var newUserResponse = await apiClient.Users.CreateAsync(newUserRequest);
            newUserResponse.Should().NotBeNull();
            newUserResponse.Email.Should().Be(newUserRequest.Email);

            // Get all the users again. Verify we now have one more
            var usersAfter = await apiClient.Users.GetAllAsync();
            usersAfter.Count.Should().Be(usersBefore.Count + 1);

            // Update the user
            var updateUserRequest = new UserUpdateRequest
            {
                Email = $"{Guid.NewGuid().ToString("N")}@nonexistingdomain.aaa",
                VerifyEmail = false
            };
            var updateUserResponse = await apiClient.Users.UpdateAsync(newUserResponse.UserId, updateUserRequest);
            updateUserResponse.Should().NotBeNull();
            updateUserResponse.Email.Should().Be(updateUserRequest.Email);

            // Get a single user
            var user = await apiClient.Users.GetAsync(newUserResponse.UserId);
            user.Should().NotBeNull();
            user.Email.Should().Be(updateUserResponse.Email);

            // Delete the user and ensure we get an exception when trying to fetch them again
            await apiClient.Users.DeleteAsync(user.UserId);
            Func<Task> getFunc = async () => await apiClient.Users.GetAsync(user.UserId);
            getFunc.ShouldThrow<ApiException>().And.ApiError.ErrorCode.Should().Be("inexistent_user");
        }
Example #2
0
 /// <summary>
 /// Creates a new user.
 /// </summary>
 /// <param name="request">The <see cref="UserCreateRequest" /> containing the properties of the user to create.</param>
 /// <returns>Task&lt;User&gt;.</returns>
 public Task<User> Create(UserCreateRequest request)
 {
     return Connection.PostAsync<User>("users", request, null, null, null, null, null);
 }
Example #3
0
 public Task<User> Create(UserCreateRequest request)
 {
     return CreateAsync(request);
 }
Example #4
0
        public async Task Can_update_user_metadata()
        {
            // Add a new user with metadata
            var newUserRequest = new UserCreateRequest
            {
                Connection = connection.Name,
                Email = $"{Guid.NewGuid().ToString("N")}@nonexistingdomain.aaa",
                EmailVerified = true,
                Password = "******",
                AppMetadata = new
                {
                    a = 1,
                    b = 2
                },
                UserMetadata = new
                {
                    c = 3,
                    d = 4
                }
            };
            var newUserResponse = await apiClient.Users.CreateAsync(newUserRequest);

            // Do some updating
            var updateUserRequest = new UserUpdateRequest();
            updateUserRequest.AppMetadata = new ExpandoObject();
            updateUserRequest.AppMetadata.IsSubscribedTo = "1";
            var updateUserResponse = await apiClient.Users.UpdateAsync(newUserResponse.UserId, updateUserRequest);

            // Get the user to ensure the metadata was set
            var user = await apiClient.Users.GetAsync(newUserResponse.UserId);

            // Delete the user
            await apiClient.Users.DeleteAsync(user.UserId);
        }
Example #5
0
        public async Task Test_user_blocking()
        {
            // Add a new user, and ensure user is not blocked
            var newUserRequest = new UserCreateRequest
            {
                Connection = connection.Name,
                Email = $"{Guid.NewGuid().ToString("N")}@nonexistingdomain.aaa",
                EmailVerified = true,
                Password = "******"
            };
            var newUserResponse = await apiClient.Users.CreateAsync(newUserRequest);
            newUserResponse.Blocked.Should().BeFalse();

            // Ensure the user is not blocked when we select the user individually
            var user = await apiClient.Users.GetAsync(newUserResponse.UserId);
            user.Blocked.Should().BeFalse();

            // Block the user, and ensure returned user is blocked
            var updateUserRequest = new UserUpdateRequest
            {
                Blocked = true
            };
            var updateUserResponse = await apiClient.Users.UpdateAsync(newUserResponse.UserId, updateUserRequest);
            updateUserResponse.Blocked.Should().BeTrue();

            // Ensure the user is not blocked when we select the user individually
            user = await apiClient.Users.GetAsync(newUserResponse.UserId);
            user.Blocked.Should().BeTrue();

            // Delete the user
            await apiClient.Users.DeleteAsync(user.UserId);
        }