public async Task FindByNameAsync_Invalid_ReturnsNull(string roleId) { using var c = new UserManagerContext(_roles); var result = await c.RoleManager.FindByNameAsync(roleId.ToStringInvariant()).ConfigureAwait(false); Assert.Null(result); }
public async Task FindByIdAsync_NoRoleDefined_ReturnsNull() { using var c = new UserManagerContext(null); var result = await c.RoleManager.FindByIdAsync("Admin").ConfigureAwait(false); Assert.Null(result); }
public async Task FindByNameAsync_UpperCaseEmailWithPassword_ReturnsIdentity(string email) { using var c = new UserManagerContext(_roles, _output); var result = await c.UserManager.FindByNameAsync(email.ToUpperInvariant()).ConfigureAwait(false); Assert.NotNull(result); }
public async Task FindByIdAsync_WithPassword_ReturnsIdentity(int contactId) { using var c = new UserManagerContext(_roles, _output); var result = await c.UserManager.FindByIdAsync(contactId.ToStringInvariant()).ConfigureAwait(false); Assert.NotNull(result); }
public async Task FindByNameAsync_EmailNoPassword_ReturnsNull(string email) { using var c = new UserManagerContext(_roles, _output); var result = await c.UserManager.FindByNameAsync(email).ConfigureAwait(false); Assert.Null(result); }
public async Task FindByIdAsync_InvalidInt_ThrowsException(string contactId) { using var c = new UserManagerContext(_roles, _output); Task <OntraportIdentityUser> Act() => c.UserManager.FindByIdAsync(contactId.ToStringInvariant()); await Assert.ThrowsAsync <ArgumentException>(Act); }
public async Task FindByNameAsync_Valid_ReturnsRoleWithProperCase(string roleId, string expected) { using var c = new UserManagerContext(_roles); var result = await c.RoleManager.FindByNameAsync(roleId.ToStringInvariant()).ConfigureAwait(false); Assert.NotNull(result); Assert.Equal(expected, result.Name, StringComparer.InvariantCulture); }
public async Task AddToRoleAsync_Invalid_IsInRole(string role) { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = await c.FindOrCreateUserAsync(NewEmail, Password); Task Act() => c.UserManager.AddToRoleAsync(user, role); await Assert.ThrowsAsync <ArgumentException>(Act); }
public async Task UpdateAsync_ExistingEmail_ReturnsFailure() { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = await c.FindOrCreateUserAsync(NewEmail, Password); await c.UserManager.ChangePasswordAsync(user, Password, Password); var result = await c.UserManager.UpdateAsync(user); Assert.True(result.Succeeded); }
public async Task AddToRoleAsync_Valid_IsInRole(string role) { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = await c.FindOrCreateUserAsync(NewEmail, Password); var result = await c.UserManager.AddToRoleAsync(user, role); Assert.True(await c.UserManager.IsInRoleAsync(user, role)); await c.UserManager.DeleteAsync(user); Assert.True(result.Succeeded); }
public async Task DeleteAsync_ValidId_LeaveContactAndRemovePassword() { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = await c.FindOrCreateUserAsync(NewEmail, Password); var result = await c.UserManager.DeleteAsync(user); Assert.True(result.Succeeded); var exist = await c.OntraportContacts.SelectAsync(user.Id); Assert.NotNull(exist); Assert.Empty(exist.IdentityPasswordHash); }
public async Task CreateAsync_ExistingEmail_ReturnsFailure() { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = new OntraportIdentityUser() { UserName = NewEmail, Email = NewEmail }; var result = await c.UserManager.CreateAsync(user, Password); Assert.False(result.Succeeded); }
public async Task DeleteAsync_InvalidId_ThrowsException() { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = new OntraportIdentityUser() { Id = int.MaxValue, UserName = NewEmail, Email = NewEmail }; Task <IdentityResult> Act() => c.UserManager.DeleteAsync(user); await Assert.ThrowsAsync <HttpRequestException>(Act); }
public async Task GetRolesAsync_TwoRoles_ReturnsBoth() { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var user = await c.FindOrCreateUserAsync(NewEmail, Password); await c.UserManager.AddToRoleAsync(user, _roles[0]); await c.UserManager.AddToRoleAsync(user, _roles[1]); var result = await c.UserManager.GetRolesAsync(user); Assert.Contains(_roles[0], result); Assert.Contains(_roles[1], result); await c.UserManager.DeleteAsync(user); }
public async Task CreateAsync_NewEmail_IdReturned() { const string NewEmail = "*****@*****.**"; using var c = new UserManagerContext(_roles, _output); var exist = await c.UserManager.FindByNameAsync(NewEmail); if (exist != null) { await c.UserManager.DeleteAsync(exist); } var user = new OntraportIdentityUser() { UserName = NewEmail, Email = NewEmail }; var result = await c.UserManager.CreateAsync(user, Password); Assert.True(result.Succeeded); Assert.True(user.Id > 0); }