public static IsSuccess ( Microsoft.AspNet.Identity.IdentityResult result ) : void | ||
result | Microsoft.AspNet.Identity.IdentityResult | |
Résultat | void |
public async Task Create_user_returns_Success() { // arrange var user = new IdentityUser("Create_user_returns_Success"); // act var result = await _userStore.CreateAsync(user); // assert IdentityResultAssert.IsSuccess(result); var userFromDb = await _userCollection.Find(x => x.Id == user.Id).SingleOrDefaultAsync(); IdentityUserAssert.Equal(user, userFromDb); }
public async Task Update_user_that_does_not_already_exists_inserts_new_record_and_returns_Success() { // arrange var user = new IdentityUser("Update_user_that_does_not_already_exists_inserts_new_record_and_returns_Success"); // act var result = await _userStore.UpdateAsync(user); // assert IdentityResultAssert.IsSuccess(result); var userFromDb = await _userCollection.Find(x => x.Id == user.Id).SingleOrDefaultAsync(); IdentityUserAssert.Equal(user, userFromDb); }
public async Task Update_role_that_does_not_already_exists_inserts_and_returns_Success() { // arrange var role = new IdentityRole("Update_role_that_does_not_already_exists_inserts_and_returns_Success"); // act var result = await _roleStore.UpdateAsync(role); // assert IdentityResultAssert.IsSuccess(result); var roleFromDb = await _roleCollection.Find(x => x.Id == role.Id).SingleOrDefaultAsync(); IdentityRoleAssert.Equal(role, roleFromDb); }
public async Task Delete_role_that_does_not_exist_returns_Success() { // arrange var role = new IdentityRole("Delete_role_that_does_not_exist_returns_Success"); // act var result = await _roleStore.DeleteAsync(role); // assert IdentityResultAssert.IsSuccess(result); var roleFromDb = await _roleCollection.Find(x => x.Id == role.Id).SingleOrDefaultAsync(); Assert.Null(roleFromDb); }
public async Task Delete_user_that_does_not_exist_returns_Success() { // arrange var user = new IdentityUser("Delete_user_that_does_not_exist_returns_Success"); // act var result = await _userStore.DeleteAsync(user); // assert IdentityResultAssert.IsSuccess(result); var userFromDb = await _userCollection.Find(x => x.Id == user.Id).SingleOrDefaultAsync(); Assert.Null(userFromDb); }
public async Task Creating_two_different_roles_but_same_Name_returns_DuplicateRoleName_error() { // arrange var role1 = new IdentityRole("Creating_two_different_roles_but_same_Name_returns_DuplicateRoleName_error"); var role2 = new IdentityRole(role1.Name); // act var result1 = await _roleStore.CreateAsync(role1); var result2 = await _roleStore.CreateAsync(role2); // assert IdentityResultAssert.IsSuccess(result1); var expectedError = IdentityResult.Failed(_errorDescriber.DuplicateRoleName(role2.ToString())); IdentityResultAssert.IsFailure(result2, expectedError.Errors.FirstOrDefault()); }
public async Task Creating_two_different_users_but_same_UserName_returns_DuplicateUserName_error() { // arrange var user1 = new IdentityUser("Creating_two_different_users_but_same_UserName_returns_DuplicateUserName_error"); var user2 = new IdentityUser(user1.UserName); // act var result1 = await _userStore.CreateAsync(user1); var result2 = await _userStore.CreateAsync(user2); // assert IdentityResultAssert.IsSuccess(result1); var expectedError = IdentityResult.Failed(_errorDescriber.DuplicateUserName(user2.ToString())); IdentityResultAssert.IsFailure(result2, expectedError.Errors.FirstOrDefault()); }
public async Task Creating_same_user_twice_returns_DuplicateUserName_error() { // arrange var user = new IdentityUser("Creating_same_user_twice_returns_DuplicateUserName_error"); // act var result1 = await _userStore.CreateAsync(user); user.UserName = "******"; var result2 = await _userStore.CreateAsync(user); // assert IdentityResultAssert.IsSuccess(result1); var expectedError = IdentityResult.Failed(_errorDescriber.DuplicateUserName(user.ToString())); IdentityResultAssert.IsFailure(result2, expectedError.Errors.FirstOrDefault()); }
public async Task Create_a_user_without_NormalizedUserName_and_NormalizedEmail_sets_to_UserName_and_Email() { // arrange var user = new IdentityUser { UserName = "******", Email = "*****@*****.**" }; // act var result = await _userStore.CreateAsync(user); // assert IdentityResultAssert.IsSuccess(result); var userFromDb = await _userCollection.Find(x => x.Id == user.Id).SingleOrDefaultAsync(); Assert.Equal(user.UserName.ToLower(), await _userStore.GetNormalizedUserNameAsync(userFromDb)); Assert.Equal(user.Email.ToLower(), await _userStore.GetNormalizedEmailAsync(userFromDb)); }
public async Task Can_update_user_multiple_times() { // arrange var user = new IdentityUser("Can_update_user_multiple_times"); await _userStore.CreateAsync(user); // act user.Claims.Add(_identityClaim1); var result1 = await _userStore.UpdateAsync(user); user.UserName = user.UserName + " different"; var result2 = await _userStore.UpdateAsync(user); // assert IdentityResultAssert.IsSuccess(result1); IdentityResultAssert.IsSuccess(result2); var userFromDb = await _userCollection.Find(x => x.Id == user.Id).SingleOrDefaultAsync(); IdentityUserAssert.Equal(user, userFromDb); }
public async Task Can_update_role_multiple_times() { // arrange var role = new IdentityRole("Can_update_role_multiple_times"); await _roleStore.CreateAsync(role); // act role.Claims.Add(new IdentityClaim { ClaimType = "ClaimType1", ClaimValue = "claim value" }); var result1 = await _roleStore.UpdateAsync(role); role.Name = role.Name + " different"; var result2 = await _roleStore.UpdateAsync(role); // assert IdentityResultAssert.IsSuccess(result1); IdentityResultAssert.IsSuccess(result2); var roleFromDb = await _roleCollection.Find(x => x.Id == role.Id).SingleOrDefaultAsync(); IdentityRoleAssert.Equal(role, roleFromDb); }
public async Task Update_user_returns_Success() { // arrange var user = new IdentityUser("Update_user_returns_Success"); user.Claims.Add(_identityClaim1); // initial user creation await _userStore.CreateAsync(user); user.UserName = user.UserName + " different"; user.Claims.Add(_identityClaim2); // act var result = await _userStore.UpdateAsync(user); // assert IdentityResultAssert.IsSuccess(result); var userFromDb = await _userCollection.Find(x => x.Id == user.Id).SingleOrDefaultAsync(); IdentityUserAssert.Equal(user, userFromDb); }
public async Task Create_role_returns_Success() { // arrange var claim1 = new IdentityClaim { ClaimType = "ClaimType1", ClaimValue = "some value" }; var claim2 = new IdentityClaim { ClaimType = "ClaimType2", ClaimValue = "some other value" }; var role = new IdentityRole("Create_role_returns_Success"); role.Claims.Add(claim1); role.Claims.Add(claim2); // act var result = await _roleStore.CreateAsync(role); // assert IdentityResultAssert.IsSuccess(result); var roleFromDb = await _roleCollection.Find(x => x.Id == role.Id).SingleOrDefaultAsync(); IdentityRoleAssert.Equal(role, roleFromDb); }