public async Task TestUpdateUser() { IDatabaseService provider = UserDatabaseTests.CreateProvider(); using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(600)))) { string host = null; UserName userName = UserDatabaseTests.CreateRandomUserName(host); string password = UserDatabaseTests.CreateRandomPassword(); UserConfiguration userConfiguration = new UserConfiguration(userName, password); await provider.CreateUserAsync(_instance.Id, userConfiguration, cancellationTokenSource.Token); UpdateUserConfiguration updateUserConfiguration = new UpdateUserConfiguration(null, UserDatabaseTests.CreateRandomPassword()); await provider.UpdateUserAsync(_instance.Id, userName, updateUserConfiguration, cancellationTokenSource.Token); await provider.RemoveUserAsync(_instance.Id, userName, cancellationTokenSource.Token); } }
/// <summary> /// Update properties of a database user. /// </summary> /// <param name="service">The database service instance.</param> /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param> /// <param name="userName">A <see cref="UserName"/> object identifying the database user. This is obtained from <see cref="UserConfiguration.UserName">UserConfiguration.UserName</see>.</param> /// <param name="configuration">An <see cref="UpdateUserConfiguration"/> object describing the updates to apply to the user.</param> /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentNullException"> /// If <paramref name="instanceId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="userName"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="configuration"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="WebException">If the REST request does not return successfully.</exception> /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/PUT_modifyUser__version___accountId__instances__instanceId__users__name__.html">Modify User Attributes (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso> public static void UpdateUser(this IDatabaseService service, DatabaseInstanceId instanceId, UserName userName, UpdateUserConfiguration configuration) { if (service == null) throw new ArgumentNullException("service"); try { service.UpdateUserAsync(instanceId, userName, configuration, CancellationToken.None).Wait(); } catch (AggregateException ex) { ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions; if (innerExceptions.Count == 1) throw innerExceptions[0]; throw; } }