Пример #1
0
        public async Task Should_be_able_to_change_the_password_of_a_user()
        {
            var userInfo = new UserInfo(testUser, "topSecret").AddTag("monitoring").AddTag("management");
            var user     = await managementClient.CreateUserAsync(userInfo).ConfigureAwait(false);

            var updatedUser = await managementClient.ChangeUserPasswordAsync(testUser, "newPassword").ConfigureAwait(false);

            updatedUser.Name.ShouldEqual(user.Name);
            updatedUser.Tags.ShouldEqual(user.Tags);
            updatedUser.PasswordHash.ShouldNotEqual(user.PasswordHash);
        }
        /// <summary>
        ///     Update the password of an user.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="userName">The name of a user</param>
        /// <param name="newPassword">The new password to set</param>
        /// <param name="cancellationToken"></param>
        public static User ChangeUserPassword(
            [NotNull] this IManagementClient source,
            string userName,
            string newPassword,
            CancellationToken cancellationToken = default
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(source.ChangeUserPasswordAsync(userName, newPassword, cancellationToken)
                   .GetAwaiter()
                   .GetResult());
        }