public async Task LinkUnlinkDeletesTest() { var db = UnitTestHelper.CreateDefaultDb(); var mgr = new UserManager<IdentityUser>(new UserStore<IdentityUser>(db)); var user = new IdentityUser("linkunlinktest"); UnitTestHelper.IsSuccess(await mgr.CreateAsync(user)); var userLogin1 = new UserLoginInfo("provider1", "p1-1"); var userLogin2 = new UserLoginInfo("provider2", "p2-1"); Assert.Equal(0, (await mgr.GetLoginsAsync(user.Id)).Count); UnitTestHelper.IsSuccess(await mgr.AddLoginAsync(user.Id, userLogin1)); Assert.Equal(1, user.Logins.Count(l => l.ProviderKey == "p1-1")); Assert.Equal(1, (await mgr.GetLoginsAsync(user.Id)).Count); UnitTestHelper.IsSuccess(await mgr.AddLoginAsync(user.Id, userLogin2)); Assert.Equal(1, user.Logins.Count(l => l.ProviderKey == "p2-1")); Assert.Equal(2, (await mgr.GetLoginsAsync(user.Id)).Count); UnitTestHelper.IsSuccess(await mgr.RemoveLoginAsync(user.Id, userLogin1)); Assert.Equal(0, user.Logins.Count(l => l.ProviderKey == "p1-1")); Assert.Equal(1, user.Logins.Count(l => l.ProviderKey == "p2-1")); Assert.Equal(1, (await mgr.GetLoginsAsync(user.Id)).Count()); UnitTestHelper.IsSuccess(await mgr.RemoveLoginAsync(user.Id, userLogin2)); Assert.Equal(0, (await mgr.GetLoginsAsync(user.Id)).Count); Assert.Equal(0, db.Set<IdentityUserLogin>().Count()); }
public static async Task<IndexViewModel> ToViewModel(this ApplicationUser user, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager) { var result = new IndexViewModel { HasPassword = await userManager.HasPasswordAsync(user), EmailAddress = user.Email, IsEmailAddressConfirmed = user.EmailConfirmed, IsPhoneNumberConfirmed = user.PhoneNumberConfirmed, PhoneNumber = await userManager.GetPhoneNumberAsync(user), TwoFactor = await userManager.GetTwoFactorEnabledAsync(user), Logins = await userManager.GetLoginsAsync(user), BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user), AssociatedSkills = user.AssociatedSkills, TimeZoneId = user.TimeZoneId, Name = user.Name, ProposedNewEmailAddress = user.PendingNewEmail }; return result; }
public static async Task<IndexViewModel> ToViewModel(this ApplicationUser user, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager) { var profileCompletenessWarnings = user.ValidateProfileCompleteness(); var result = new IndexViewModel { HasPassword = await userManager.HasPasswordAsync(user), EmailAddress = user.Email, IsEmailAddressConfirmed = user.EmailConfirmed, IsPhoneNumberConfirmed = user.PhoneNumberConfirmed, PhoneNumber = await userManager.GetPhoneNumberAsync(user), TwoFactor = await userManager.GetTwoFactorEnabledAsync(user), Logins = await userManager.GetLoginsAsync(user), BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user), AssociatedSkills = user.AssociatedSkills, TimeZoneId = user.TimeZoneId, FirstName = user.FirstName, LastName = user.LastName, ProposedNewEmailAddress = user.PendingNewEmail, IsProfileComplete = user.IsProfileComplete(), ProfileCompletenessWarnings = profileCompletenessWarnings.Select(p => p.ErrorMessage) }; return result; }