public async Task ShouldThrow_WritingTo_Database() { // Creating the user should fail because of a table lock var currentTimeOut = _appDb.DbContext.CommandTimeOut; using (var da = (DataAccessAdapter)_appDb.DbContext.GetNewAdapter()) { //await da.ExecuteSQLAsync(CancellationToken.None, "BEGIN TRAN SELECT 1 FROM [testorg].[User] WITH (TABLOCKX) WAITFOR DELAY '00:00:05' ROLLBACK TRAN"); await da.StartTransactionAsync(IsolationLevel.Serializable, "transaction1"); da.SaveTransaction("transaction1"); // lock the table for completely await da.ExecuteSQLAsync(CancellationToken.None, $"SELECT 1 FROM [{_appDb.DbContext.Schema}].[{da.GetPersistentTableName(new UserEntity())}] WITH (TABLOCKX)"); // Trying to update will fail because the table is locked _appDb.DbContext.CommandTimeOut = 2; Assert.AreNotEqual(IdentityResult.Success, await _store.CreateAsync(new ApplicationUser { Email = "*****@*****.**" }, CancellationToken.None)); Assert.AreNotEqual(IdentityResult.Success, await _store.UpdateAsync(new ApplicationUser { Email = "*****@*****.**" }, CancellationToken.None)); Assert.AreNotEqual(IdentityResult.Success, await _store.DeleteAsync(new ApplicationUser { Email = "*****@*****.**" }, CancellationToken.None)); da.Rollback("transaction1"); } _appDb.DbContext.CommandTimeOut = currentTimeOut; }
public void UserStoreMethodsThrowWhenDisposedTest() { var db = UnitTestHelper.CreateDefaultDb(); var store = new UserStore <IdentityUser>(db); store.Dispose(); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null))); Assert.Throws <ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByIdAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByNameAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.UpdateAsync(null))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.DeleteAsync(null))); Assert.Throws <ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true))); Assert.Throws <ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null))); Assert.Throws <ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true))); Assert.Throws <ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null))); }
public async System.Threading.Tasks.Task DeleteUserAsync() { // Arrange var mock = new Mock <IConfiguration>(); mock.Setup(m => m.GetConnectionString("DefaultConnection")).Returns(_connectionString); var repository = new UserStore(mock.Object); var user = new ApplicationUser { Email = "*****@*****.**", IsDeleted = false, PasswordHash = SecurePasswordHasher.Hash("kekman"), PhoneNumber = "88005553535", UserName = "******" }; var createResponse = await repository.CreateAsync(user, new System.Threading.CancellationToken()); var createdUser = repository.ReturnLastUser(); // Act var result = await repository.DeleteAsync(createdUser, new System.Threading.CancellationToken()); // Assert Assert.True(result.Succeeded); }
public void When_Success_DeleteAsync_Does_Not_Throw_Exception() { var mockBucket = new Mock <IBucket>(); mockBucket.SetupGet(e => e.Name).Returns("default"); var mockResult = new Mock <IOperationResult <IdentityUser> >(); mockResult.SetupGet(x => x.Success).Returns(true); mockBucket.Setup(x => x.RemoveAsync(It.IsAny <string>())) .ReturnsAsync(mockResult.Object); var mockResult2 = new Mock <IOperationResult <string> >(); mockResult2.SetupGet(x => x.Success).Returns(true); mockBucket.Setup(x => x.RemoveAsync(It.IsAny <string>())) .ReturnsAsync(mockResult2.Object); var mockResult3 = new Mock <IOperationResult <string> >(); mockResult3.SetupGet(x => x.Success).Returns(true); mockBucket.Setup(x => x.RemoveAsync(It.IsAny <string>())) .ReturnsAsync(mockResult3.Object); var user = new IdentityUser("foo") { Email = "*****@*****.**" }; var store = new UserStore <IdentityUser>(new ThrowableBucket(mockBucket.Object)); Assert.DoesNotThrow(async() => await store.DeleteAsync(user)); }
public void UserStorePublicNullCheckTest() { var store = new UserStore <IdentityUser>(); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.CreateAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.UpdateAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.DeleteAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetPasswordHashAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetPasswordHashAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetSecurityStampAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetSecurityStampAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.AddClaimAsync(new IdentityUser("fake"), null)), "claim"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.RemoveClaimAsync(new IdentityUser("fake"), null)), "claim"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.AddLoginAsync(new IdentityUser("fake"), null)), "login"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.RemoveLoginAsync(new IdentityUser("fake"), null)), "login"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.FindAsync(null)), "login"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetEmailAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetEmailAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetPhoneNumberAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetPhoneNumberAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetTwoFactorEnabledAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetTwoFactorEnabledAsync(null, true)), "user"); ExceptionHelper.ThrowsArgumentNullOrEmpty( () => AsyncHelper.RunSync(() => store.AddToRoleAsync(new IdentityUser("fake"), null)), "roleName"); ExceptionHelper.ThrowsArgumentNullOrEmpty( () => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(new IdentityUser("fake"), null)), "roleName"); ExceptionHelper.ThrowsArgumentNullOrEmpty( () => AsyncHelper.RunSync(() => store.IsInRoleAsync(new IdentityUser("fake"), null)), "roleName"); }
public async Task <bool> DeleteAsync([FromBody] User user) { var deleteResult = await _userStore.DeleteAsync(user); // будет логирование return(deleteResult.Succeeded); }
public async Task GivenHaveRoles_WhenDeleteUser_ThenDeletingCausesNoCascade() { var user = new IdentityUser("Lukz 04"); var role = new IdentityRole("ADM") { NormalizedName = "ADM" }; var store = new UserStore <IdentityUser>(this._session); var roleStore = new RoleStore <IdentityRole>(this._session); await roleStore.CreateAsync(role); await store.CreateAsync(user); await store.AddToRoleAsync(user, "ADM"); Assert.True(await this._session.Query <IdentityRole>().AnyAsync(x => x.Name == "ADM")); Assert.True(await this._session.Query <IdentityUser>().AnyAsync(x => x.UserName == "Lukz 04")); var result = await store.DeleteAsync(user); Assert.True(result.Succeeded); Assert.Empty(result.Errors); Assert.False(await this._session.Query <IdentityUser>().AnyAsync(x => x.UserName == "Lukz 04")); Assert.True(await this._session.Query <IdentityRole>().AnyAsync(x => x.Name == "ADM")); }
public async Task UpdateAsyncAsyncTest() { var database = CreateDatabase(); var store = new UserStore <ApplicationUser>(database); var user = new ApplicationUser() { UserName = "******" }; await store.CreateAsync(user); var id = user.Id; Assert.IsTrue(id.Length > 0); user.PasswordHash = "testhash"; user.UserName = "******"; await store.UpdateAsync(user); Assert.AreEqual(id, user.Id); var updatedUser = await store.FindByIdAsync(id); Assert.AreEqual("testhash", updatedUser.PasswordHash); Assert.AreEqual("modified user name", updatedUser.UserName); await store.DeleteAsync(user); }
public void ThrowIfDisposed() { var store = new UserStore <ApplicationUser, IdentityRole, IdentityCloudContext>(GetContext(), describer: new IdentityErrorDescriber()); store.Dispose(); GC.Collect(); Assert.IsTrue(Assert.ThrowsException <AggregateException>(() => store.DeleteAsync(new ApplicationUser()).Wait()).InnerException is ObjectDisposedException); }
public async Task UserStoreMethodsThrowWhenDisposedTest() { var db = CreateDb(); var userOnlyStore = new UserOnlyStore(db); var store = new UserStore(db, userOnlyStore); store.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.AddClaimsAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.AddLoginAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.AddToRoleAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetClaimsAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetLoginsAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetRolesAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.IsInRoleAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.RemoveClaimsAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.RemoveLoginAsync(null, null, null)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.RemoveFromRoleAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.RemoveClaimsAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.ReplaceClaimAsync(null, null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.FindByLoginAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.FindByIdAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.FindByNameAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.CreateAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.UpdateAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.DeleteAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.SetEmailConfirmedAsync(null, true)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetEmailConfirmedAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.SetPhoneNumberConfirmedAsync(null, true)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.GetPhoneNumberConfirmedAsync(null)); }
public async Task <OperationalResult> DeleteAsync(Operational <string> operational, CancellationToken cancellationToken = default) { var UserNo = operational.Parameter; Expression <Func <User, bool> > expression = p => p.No == UserNo; var result = await _userStore.DeleteAsync(expression, cancellationToken); return(result ? OperationalResult.Ok() : OperationalResult.Failed("")); }
public async Task SqlUserStoreMethodsThrowWhenDisposedTest() { var store = new UserStore(new IdentityDbContext (TestEnvironment.Config[TestEnvironment.TestIdentityDbConnectionString])); store.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.AddClaimsAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.AddLoginAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.AddToRoleAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetClaimsAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetLoginsAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetRolesAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.IsInRoleAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.RemoveClaimsAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.RemoveLoginAsync(null, null, null)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.RemoveFromRoleAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.RemoveClaimsAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.ReplaceClaimAsync(null, null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.FindByLoginAsync(null, null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.FindByIdAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.FindByNameAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.CreateAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.UpdateAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.DeleteAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.SetEmailConfirmedAsync(null, true)); await Assert.ThrowsAsync <ObjectDisposedException>(async() => await store.GetEmailConfirmedAsync(null)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.SetPhoneNumberConfirmedAsync(null, true)); await Assert.ThrowsAsync <ObjectDisposedException>( async() => await store.GetPhoneNumberConfirmedAsync(null)); }
public async Task DeleteUserTest() { var db = UnitTestHelper.CreateDefaultDb(); var store = new UserStore <IdentityUser>(db); var mgmt = new IdentityUser("deletemgmttest"); await store.CreateAsync(mgmt); Assert.NotNull(await store.FindByIdAsync(mgmt.Id)); await store.DeleteAsync(mgmt); Assert.Null(await store.FindByIdAsync(mgmt.Id)); }
public async Task FindByNameAsyncAsyncTest() { var database = CreateDatabase(); var store = new UserStore<ApplicationUser>(database); var user = new ApplicationUser() { UserName = "******" }; await store.CreateAsync(user); var userFromDb = await store.FindByNameAsync("testuser"); Assert.IsTrue(userFromDb.Id.Length > 0); Assert.AreEqual(user.Id, userFromDb.Id); await store.DeleteAsync(user); }
public async void DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive() { var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration(); var userStore = new UserStore<User>(applicationDatabaseConfiguration); var existingUser = await userStore.FindByNameAsync("UserName"); existingUser.UserName = "******"; await userStore.UpdateAsync(existingUser); await userStore.DeleteAsync(existingUser); existingUser.IsAccountActive.Should().BeFalse(); }
public async Task DeleteAsync_ExistingUser_UserInfoDeleted() { var user = new User(mMembershipFakeFactory.UserDisabledWithEmail); // Ensure that user exists var userInfo = UserInfoProvider.GetUserInfo(user.Id); await mUserStore.DeleteAsync(user); CMSAssert.All( () => Assert.NotNull(userInfo), () => Assert.IsNull(UserInfoProvider.GetUserInfo(userInfo.UserID))); }
public void DeleteUser() { using (UserStore <IdentityUser> store = new UserStore <IdentityUser>()) { using (UserManager <IdentityUser> manager = new UserManager <IdentityUser>(store)) { var user = GenTestUser(); var taskUser = manager.CreateAsync(user, DefaultUserPassword); taskUser.Wait(); Assert.IsTrue(taskUser.Result.Succeeded, string.Concat(taskUser.Result.Errors)); for (int i = 0; i < 5; i++) { AddUserClaimHelper(manager, user, GenAdminClaim()); AddUserLoginHelper(manager, user, GenGoogleLogin()); AddUserRoleHelper(manager, user, string.Format("{0}_{1}", Constants.AccountRoles.AccountTestUserRole, Guid.NewGuid().ToString("N"))); } var findUserTask2 = manager.FindByIdAsync(user.Id); findUserTask2.Wait(); user = findUserTask2.Result; WriteLineObject <IdentityUser>(user); TestContext.WriteLine("User Size in Bytes: {0}", Encoding.UTF8.GetByteCount(JsonConvert.SerializeObject(user))); DateTime start = DateTime.UtcNow; var taskUserDel = manager.DeleteAsync(user); taskUserDel.Wait(); Assert.IsTrue(taskUserDel.Result.Succeeded, string.Concat(taskUser.Result.Errors)); TestContext.WriteLine("DeleteAsync: {0} seconds", (DateTime.UtcNow - start).TotalSeconds); Thread.Sleep(1000); var findUserTask = manager.FindByIdAsync(user.Id); findUserTask.Wait(); Assert.IsNull(findUserTask.Result, "Found user Id, user not deleted."); try { var task = store.DeleteAsync(null); task.Wait(); } catch (AggregateException agg) { agg.ValidateAggregateException <ArgumentException>(); } } } }
public async void DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive() { var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration(); var userStore = new UserStore <User>(applicationDatabaseConfiguration); var existingUser = await userStore.FindByNameAsync("UserName"); existingUser.UserName = "******"; await userStore.UpdateAsync(existingUser); await userStore.DeleteAsync(existingUser); existingUser.IsAccountActive.Should().BeFalse(); }
internal async Task <string> DeleteUserById(int id) { UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(store); ApplicationUser usr = await manager.FindByIdAsync(id.ToString()); if (usr != null) { await store.DeleteAsync(usr); return(usr.UserName); } return(null); }
public async Task <bool> DeleteAsync([FromBody] User user) { var result = await _userStore.DeleteAsync(user); #region Log if (result.Succeeded == false) { _logger.LogError($"Удаление пользователя {user.UserName} завершилось неудачей"); } #endregion return(result.Succeeded); }
public void ThrowIfDisposed() { UserStore <IdentityUser> store = new UserStore <IdentityUser>(); store.Dispose(); GC.Collect(); try { var task = store.DeleteAsync(null); } catch (AggregateException agg) { agg.ValidateAggregateException <ArgumentException>(); } }
public void Should_remove_user_role_record() { var user = new IdentityUser(); user.Id = TestData.John_UserId; var target = new UserStore<IdentityUser>(); var task = target.DeleteAsync(user); task.Wait(); dynamic db = Database.Open(); var userRoles = db.AspNetUserRole.FindAllByUserId(user.Id); Assert.That(userRoles, Is.Empty); }
public async Task DeleteUserAsync() { // Arrange var user = await CreateUserAsync(); var userId = user.Id; // Act await userStore.DeleteAsync(user); await Context.SaveChangesAsync(); var deletedUser = await userStore.FindByIdAsync(userId); // Assert Assert.IsNull(deletedUser); }
public async Task FindByNameAsyncAsyncTest() { var database = CreateDatabase(); var store = new UserStore <ApplicationUser>(database); var user = new ApplicationUser() { UserName = "******" }; await store.CreateAsync(user); var userFromDb = await store.FindByNameAsync("testuser"); Assert.IsTrue(userFromDb.Id.Length > 0); Assert.AreEqual(user.Id, userFromDb.Id); await store.DeleteAsync(user); }
public void Should_remove_user_role_record() { var user = new IdentityUser(); user.Id = TestData.John_UserId; var target = new UserStore <IdentityUser>(); var task = target.DeleteAsync(user); task.Wait(); dynamic db = Database.Open(); var userRoles = db.AspNetUserRole.FindAllByUserId(user.Id); Assert.That(userRoles, Is.Empty); }
public void DeleteUser() { UserStore <ApplicationUser, IdentityRole, IdentityCloudContext> store = CreateUserStore(); UserManager <ApplicationUser> manager = CreateUserManager(); var user = GenTestUser(); var taskUser = manager.CreateAsync(user, DefaultUserPassword); taskUser.Wait(); Assert.IsTrue(taskUser.Result.Succeeded, string.Concat(taskUser.Result.Errors)); user = manager.FindByIdAsync(user.Id).Result; for (int i = 0; i < 7; i++) { AddUserClaimHelper(user, GenAdminClaim()); AddUserLoginHelper(user, GenGoogleLogin()); AddUserRoleHelper(user, string.Format("{0}_{1}", Constants.AccountRoles.AccountTestUserRole, Guid.NewGuid().ToString("N"))); } var findUserTask2 = manager.FindByIdAsync(user.Id); findUserTask2.Wait(); user = findUserTask2.Result; WriteLineObject <IdentityUser>(user); DateTime start = DateTime.UtcNow; var taskUserDel = manager.DeleteAsync(user); taskUserDel.Wait(); Assert.IsTrue(taskUserDel.Result.Succeeded, string.Concat(taskUser.Result.Errors)); Console.WriteLine("DeleteAsync: {0} seconds", (DateTime.UtcNow - start).TotalSeconds); Thread.Sleep(1000); var findUserTask = manager.FindByIdAsync(user.Id); findUserTask.Wait(); Assert.IsNull(findUserTask.Result); AssertInnerExceptionType <AggregateException, ArgumentException>(() => store.DeleteAsync(null).Wait()); }
protected void Delete_Click(object sender, EventArgs e) { //Get the button that raised the event Button btn = (Button)sender; //Get the row that contains this button GridViewRow gvr = (GridViewRow)btn.NamingContainer; string id = gvr.Cells[0].Text; var userStore = new UserStore <IdentityUser>(); var userManager = new UserManager <IdentityUser>(userStore); var user = userManager.FindById(id); if (user != null) { var oldSettings = settingsBLL.getSettingsByUserId(id); if (oldSettings != null) { oldSettings.UserId = null; var oldResult = settingsBLL.update(oldSettings); if (oldResult == null) { lblModal.Text = "Failed to update"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } } userStore.DeleteAsync(user); UsersGV.DataSource = usersBLL.getAllUsers(); UsersGV.DataBind(); Response.Redirect(Request.RawUrl); } else { lblModal.Text = "Failed to delete account"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); } }
public void GivenHaveRoles_WhenDeleteUser_ThenDeletingCausesNoCascade() { var user = new IdentityUser("Lukz 04"); var role = new IdentityRole("ADM"); var store = new UserStore <IdentityUser>(_session); var roleStore = new RoleStore <IdentityRole>(_session); roleStore.CreateAsync(role); store.CreateAsync(user); store.AddToRoleAsync(user, "ADM"); Assert.IsTrue(_session.Query <IdentityRole>().Any(x => x.Name == "ADM")); Assert.IsTrue(_session.Query <IdentityUser>().Any(x => x.UserName == "Lukz 04")); var result = store.DeleteAsync(user); Assert.IsNull(result.Exception); Assert.IsFalse(this._session.Query <IdentityUser>().Any(x => x.UserName == "Lukz 04")); Assert.IsTrue(this._session.Query <IdentityRole>().Any(x => x.Name == "ADM")); }
public async Task CreateLoadDeleteUserTest() { var db = UnitTestHelper.CreateDefaultDb(); var store = new UserStore <IdentityUser>(db); var user = new IdentityUser("Test"); Assert.Null(await store.FindByIdAsync(user.Id)); await store.CreateAsync(user); var loadUser = await store.FindByIdAsync(user.Id); Assert.NotNull(loadUser); Assert.Equal(user.Id, loadUser.Id); await store.DeleteAsync(loadUser); loadUser = await store.FindByIdAsync(user.Id); Assert.Null(loadUser); }
public IHttpActionResult Register(UserInfo user) { var confirmationId = Guid.NewGuid(); using (var userStore = new UserStore()) { userStore.CreateAsync(user, confirmationId).Wait(); try { MailHelper.SendConfirmationEmail("Registration", Properties.Resources.Authentication_Register_Message, "confirmuser", user, confirmationId); } catch { userStore.DeleteAsync(user).Wait(); throw; } } return(Ok()); }
public async Task <bool> DeleteAsync([FromBody] User user) => (await _UserStore.DeleteAsync(user)).Succeeded;
public void When_Not_Success_DeleteAsync_Throws_CouchbaseException() { var mockBucket = new Mock<IBucket>(); mockBucket.SetupGet(e => e.Name).Returns("default"); var mockResult = new Mock<IOperationResult<IdentityUser>>(); mockResult.SetupGet(x => x.Success).Returns(false); mockBucket.Setup(x => x.RemoveAsync(It.IsAny<string>())) .ReturnsAsync(mockResult.Object); var mockResult2 = new Mock<IOperationResult<string>>(); mockResult2.SetupGet(x => x.Success).Returns(false); mockBucket.Setup(x => x.RemoveAsync(It.IsAny<string>())) .ReturnsAsync(mockResult2.Object); var mockResult3 = new Mock<IOperationResult<string>>(); mockResult3.SetupGet(x => x.Success).Returns(false); mockBucket.Setup(x => x.RemoveAsync(It.IsAny<string>())) .ReturnsAsync(mockResult3.Object); var user = new IdentityUser("foo") { Email = "*****@*****.**" }; var store = new UserStore<IdentityUser>(new ThrowableBucket(mockBucket.Object)); Assert.Throws<CouchbaseException>(async () => await store.DeleteAsync(user)); }
public async Task UpdateAsyncAsyncTest() { var database = CreateDatabase(); var store = new UserStore<ApplicationUser>(database); var user = new ApplicationUser() { UserName = "******" }; await store.CreateAsync(user); var id = user.Id; Assert.IsTrue(id.Length > 0); user.PasswordHash = "testhash"; user.UserName = "******"; await store.UpdateAsync(user); Assert.AreEqual(id, user.Id); var updatedUser = await store.FindByIdAsync(id); Assert.AreEqual("testhash", updatedUser.PasswordHash); Assert.AreEqual("modified user name", updatedUser.UserName); await store.DeleteAsync(user); }
public async Task UserStorePublicNullCheckTest() { Assert.Throws <ArgumentNullException>("factory", () => new UserStore <IdentityUser>(null)); var store = new UserStore <IdentityUser>(CreateTestContext()); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetUserIdAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetUserNameAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetUserNameAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.CreateAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.UpdateAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.DeleteAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.AddClaimsAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.ReplaceClaimAsync(null, null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.RemoveClaimsAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetClaimsAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetLoginsAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetRolesAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.AddLoginAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.RemoveLoginAsync(null, null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.AddToRoleAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.RemoveFromRoleAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.IsInRoleAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetPasswordHashAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetPasswordHashAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetSecurityStampAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetSecurityStampAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("login", async() => await store.AddLoginAsync(new IdentityUser("fake"), null)); await Assert.ThrowsAsync <ArgumentNullException>("claims", async() => await store.AddClaimsAsync(new IdentityUser("fake"), null)); await Assert.ThrowsAsync <ArgumentNullException>("claims", async() => await store.RemoveClaimsAsync(new IdentityUser("fake"), null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetEmailConfirmedAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetEmailConfirmedAsync(null, true)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetEmailAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetEmailAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetPhoneNumberAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetPhoneNumberAsync(null, null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetPhoneNumberConfirmedAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetPhoneNumberConfirmedAsync(null, true)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetTwoFactorEnabledAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetTwoFactorEnabledAsync(null, true)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetAccessFailedCountAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetLockoutEnabledAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetLockoutEnabledAsync(null, false)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.GetLockoutEndDateAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.SetLockoutEndDateAsync(null, new DateTimeOffset())); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.ResetAccessFailedCountAsync(null)); await Assert.ThrowsAsync <ArgumentNullException>("user", async() => await store.IncrementAccessFailedCountAsync(null)); await Assert.ThrowsAsync <ArgumentException>("normalizedRoleName", async() => await store.AddToRoleAsync(new IdentityUser("fake"), null)); await Assert.ThrowsAsync <ArgumentException>("normalizedRoleName", async() => await store.RemoveFromRoleAsync(new IdentityUser("fake"), null)); await Assert.ThrowsAsync <ArgumentException>("normalizedRoleName", async() => await store.IsInRoleAsync(new IdentityUser("fake"), null)); await Assert.ThrowsAsync <ArgumentException>("normalizedRoleName", async() => await store.AddToRoleAsync(new IdentityUser("fake"), "")); await Assert.ThrowsAsync <ArgumentException>("normalizedRoleName", async() => await store.RemoveFromRoleAsync(new IdentityUser("fake"), "")); await Assert.ThrowsAsync <ArgumentException>("normalizedRoleName", async() => await store.IsInRoleAsync(new IdentityUser("fake"), "")); }
public void GivenHaveRoles_WhenDeleteUser_ThenDeletingCausesNoCascade() { var user = new IdentityUser("Lukz 04"); var role = new IdentityRole("ADM"); var store = new UserStore<IdentityUser>(_session); var roleStore = new RoleStore<IdentityRole>(_session); roleStore.CreateAsync(role); store.CreateAsync(user); store.AddToRoleAsync(user, "ADM"); Assert.IsTrue(_session.Query<IdentityRole>().Any(x => x.Name == "ADM")); Assert.IsTrue(_session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 04")); var result = store.DeleteAsync(user); Assert.IsNull(result.Exception); Assert.IsFalse(this._session.Query<IdentityUser>().Any(x => x.UserName == "Lukz 04")); Assert.IsTrue(this._session.Query<IdentityRole>().Any(x => x.Name == "ADM")); }
public async Task DeleteUserTest() { var db = UnitTestHelper.CreateDefaultDb(); var store = new UserStore<IdentityUser>(db); var mgmt = new IdentityUser("deletemgmttest"); await store.CreateAsync(mgmt); Assert.NotNull(await store.FindByIdAsync(mgmt.Id)); await store.DeleteAsync(mgmt); Assert.Null(await store.FindByIdAsync(mgmt.Id)); }
public async Task CreateLoadDeleteUserTest() { var db = UnitTestHelper.CreateDefaultDb(); var store = new UserStore<IdentityUser>(db); var user = new IdentityUser("Test"); Assert.Null(await store.FindByIdAsync(user.Id)); await store.CreateAsync(user); var loadUser = await store.FindByIdAsync(user.Id); Assert.NotNull(loadUser); Assert.Equal(user.Id, loadUser.Id); await store.DeleteAsync(loadUser); loadUser = await store.FindByIdAsync(user.Id); Assert.Null(loadUser); }
public void UserStoreMethodsThrowWhenDisposedTest() { var db = UnitTestHelper.CreateDefaultDb(); var store = new UserStore<IdentityUser>(db); store.Dispose(); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null))); Assert.Throws<ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByIdAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByNameAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.UpdateAsync(null))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.DeleteAsync(null))); Assert.Throws<ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true))); Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null))); Assert.Throws<ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true))); Assert.Throws<ObjectDisposedException>( () => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null))); }
public async Task <bool> DeleteAsync([FromBody] User user) { var delete_result = await _UserStore.DeleteAsync(user); return(delete_result.Succeeded); }
public void UserStorePublicNullCheckTest() { var store = new UserStore<IdentityUser>(); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.CreateAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.UpdateAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.DeleteAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetPasswordHashAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetPasswordHashAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetSecurityStampAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetSecurityStampAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.AddClaimAsync(new IdentityUser("fake"), null)), "claim"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.RemoveClaimAsync(new IdentityUser("fake"), null)), "claim"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.AddLoginAsync(new IdentityUser("fake"), null)), "login"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.RemoveLoginAsync(new IdentityUser("fake"), null)), "login"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.FindAsync(null)), "login"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetEmailAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetEmailAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetPhoneNumberAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetPhoneNumberAsync(null, null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true)), "user"); ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetTwoFactorEnabledAsync(null)), "user"); ExceptionHelper.ThrowsArgumentNull( () => AsyncHelper.RunSync(() => store.SetTwoFactorEnabledAsync(null, true)), "user"); ExceptionHelper.ThrowsArgumentNullOrEmpty( () => AsyncHelper.RunSync(() => store.AddToRoleAsync(new IdentityUser("fake"), null)), "roleName"); ExceptionHelper.ThrowsArgumentNullOrEmpty( () => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(new IdentityUser("fake"), null)), "roleName"); ExceptionHelper.ThrowsArgumentNullOrEmpty( () => AsyncHelper.RunSync(() => store.IsInRoleAsync(new IdentityUser("fake"), null)), "roleName"); }