public async Task <IdentityResponse> HasClaimAsync(ApplicationUser user, Claim claim) { var claims = await _userManager.GetClaimsAsync(user); return(claims.Any(x => x.Type == claim.Type && x.Value == claim.Value) ? IdentityResponse.Success("Claim Exists") : IdentityResponse.Fail("Claim does not exist")); }
private Mock <IApplicationSignInManager> GetMockApplicationSignInManager() { var applicationSignInManager = new Mock <IApplicationSignInManager>(MockBehavior.Strict); applicationSignInManager.Setup(x => x.PasswordSignInAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); applicationSignInManager.Setup(x => x.SignOutAsync()); return(applicationSignInManager); }
private Mock <IApplicationUserManager> GetMockApplicationUserManager() { var applicationUserManager = new Mock <IApplicationUserManager>(MockBehavior.Strict); applicationUserManager.Setup(x => x.RegisterUserAsync(It.IsAny <ApplicationUser>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); applicationUserManager.Setup(x => x.GetUserByNameAsync(It.IsAny <string>())) .ReturnsAsync(DefaultApplicationUsers.GetSuperUser()); return(applicationUserManager); }
private Mock <IApplicationRoleManager> GetMockApplicationRoleManager() { var applicationRoleManager = new Mock <IApplicationRoleManager>(MockBehavior.Strict); applicationRoleManager.Setup(x => x.Roles()) .Returns(DefaultApplicationRoles.GetDefaultRoles().AsQueryable()); applicationRoleManager.Setup(x => x.GetRoleAsync(It.IsAny <string>())) .ReturnsAsync((ApplicationRole)null); applicationRoleManager.Setup(x => x.AddRoleAsync(It.IsAny <ApplicationRole>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); applicationRoleManager.Setup(x => x.FindByIdAsync(It.IsAny <string>())) .ReturnsAsync(new ApplicationRole(DefaultApplicationRoles.SuperAdmin)); applicationRoleManager.Setup(x => x.GetClaimsAsync(It.IsAny <List <string> >())) .ReturnsAsync(PermissionHelper.GetPermissionClaims()); applicationRoleManager.Setup(x => x.GetClaimsAsync(It.IsAny <ApplicationRole>())) .ReturnsAsync(PermissionHelper.GetPermissionClaims()); applicationRoleManager.Setup(x => x.RemoveClaimAsync(It.IsAny <ApplicationRole>(), It.IsAny <Claim>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); applicationRoleManager.Setup(x => x.AddClaimAsync(It.IsAny <ApplicationRole>(), It.IsAny <Claim>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); return(applicationRoleManager); }
public async Task <IdentityResponse> PasswordSignInAsync(ApplicationUser user, string password, bool isPersistent, bool lockoutOnFailure) { var rs = await _signInManager.PasswordSignInAsync(user, password, isPersistent, lockoutOnFailure); return(rs.Succeeded ? IdentityResponse.Success(rs.ToString()) : IdentityResponse.Fail(rs.ToString())); }
public static IdentityResponse ToIdentityResponse(this IdentityResult identityResult) { return(identityResult.Succeeded ? IdentityResponse.Success(identityResult.ToString()) : IdentityResponse.Fail(identityResult.ToString())); }