From e8d7cf4219f451267821b56f57349884293820ab Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Fri, 4 Apr 2014 13:42:22 -0700 Subject: [PATCH] Asyncify and Userify Add Async suffix to async methods Take TUser instead of userId for Usermanager apis --- .../RoleStore.cs | 20 +- .../UserStore.cs | 114 +-- .../InMemoryRoleStore.cs | 14 +- .../InMemoryUserStore.cs | 88 ++- .../SignInManager.cs | 44 +- .../ClaimsIdentityFactory.cs | 14 +- .../IClaimsIdentityFactory.cs | 4 +- .../IIdentityMessageService.cs | 2 +- .../IPasswordValidator.cs | 4 +- src/Microsoft.AspNet.Identity/IRole.cs | 19 - src/Microsoft.AspNet.Identity/IRoleStore.cs | 20 +- .../IRoleValidator.cs | 4 +- src/Microsoft.AspNet.Identity/IUser.cs | 19 - .../IUserClaimStore.cs | 6 +- .../IUserEmailStore.cs | 10 +- .../IUserLockoutStore.cs | 14 +- .../IUserLoginStore.cs | 8 +- .../IUserNameStore.cs | 37 - .../IUserPasswordStore.cs | 6 +- .../IUserPhoneNumberStore.cs | 8 +- .../IUserRoleStore.cs | 8 +- .../IUserSecurityStampStore.cs | 4 +- src/Microsoft.AspNet.Identity/IUserStore.cs | 27 +- .../IUserTokenProvider.cs | 10 +- .../IUserTwoFactorStore.cs | 4 +- .../IUserValidator.cs | 4 +- .../PasswordValidator.cs | 2 +- src/Microsoft.AspNet.Identity/Resources.resx | 6 +- .../Rfc6238AuthenticationService.cs | 2 +- src/Microsoft.AspNet.Identity/RoleManager.cs | 38 +- .../RoleValidator.cs | 4 +- src/Microsoft.AspNet.Identity/UserManager.cs | 637 +++++++--------- .../UserValidator.cs | 14 +- .../UserStoreTest.cs | 698 ++++++++--------- .../InMemoryStoreTest.cs | 718 +++++++++--------- .../SignInManagerTest.cs | 42 +- .../ClaimsIdentityFactoryTest.cs | 16 +- .../NoopRoleStore.cs | 14 +- .../NoopUserStore.cs | 19 +- .../PasswordValidatorTest.cs | 14 +- .../RoleManagerTest.cs | 32 +- .../RoleValidatorTest.cs | 6 +- .../UserManagerTest.cs | 551 +++++++------- .../UserValidatorTest.cs | 10 +- 44 files changed, 1638 insertions(+), 1697 deletions(-) delete mode 100644 src/Microsoft.AspNet.Identity/IRole.cs delete mode 100644 src/Microsoft.AspNet.Identity/IUser.cs delete mode 100644 src/Microsoft.AspNet.Identity/IUserNameStore.cs diff --git a/src/Microsoft.AspNet.Identity.Entity/RoleStore.cs b/src/Microsoft.AspNet.Identity.Entity/RoleStore.cs index 4813aebf66..853fddb1cb 100644 --- a/src/Microsoft.AspNet.Identity.Entity/RoleStore.cs +++ b/src/Microsoft.AspNet.Identity.Entity/RoleStore.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity.Entity public EntityContext Context { get; private set; } /// - /// If true will call SaveChanges after Create/Update/Delete + /// If true will call SaveChanges after CreateAsync/UpdateAsync/DeleteAsync /// public bool AutoSaveChanges { get; set; } @@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Identity.Entity return Roles.SingleOrDefaultAsync(filter, cancellationToken); } - public async virtual Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Identity.Entity await SaveChanges(cancellationToken); } - public async virtual Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Identity.Entity await SaveChanges(cancellationToken); } - public async virtual Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -80,12 +80,12 @@ namespace Microsoft.AspNet.Identity.Entity await SaveChanges(cancellationToken); } - public Task GetRoleId(TRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleIdAsync(TRole role, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(role.Id); } - public Task GetRoleName(TRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleNameAsync(TRole role, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(role.Name); } @@ -97,12 +97,12 @@ namespace Microsoft.AspNet.Identity.Entity } /// - /// Find a role by id + /// FindByLoginAsync a role by id /// /// /// /// - public virtual Task FindById(string id, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -112,12 +112,12 @@ namespace Microsoft.AspNet.Identity.Entity } /// - /// Find a role by name + /// FindByLoginAsync a role by name /// /// /// /// - public virtual Task FindByName(string name, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); diff --git a/src/Microsoft.AspNet.Identity.Entity/UserStore.cs b/src/Microsoft.AspNet.Identity.Entity/UserStore.cs index 217074c2b8..b20e9fbad8 100644 --- a/src/Microsoft.AspNet.Identity.Entity/UserStore.cs +++ b/src/Microsoft.AspNet.Identity.Entity/UserStore.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Identity.Entity public EntityContext Context { get; private set; } /// - /// If true will call SaveChanges after Create/Update/Delete + /// If true will call SaveChanges after CreateAsync/UpdateAsync/DeleteAsync /// public bool AutoSaveChanges { get; set; } @@ -66,17 +66,41 @@ namespace Microsoft.AspNet.Identity.Entity //.Include(u => u.Logins) } - public Task GetUserId(TUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserIdAsync(TUser user, CancellationToken cancellationToken = new CancellationToken()) { + cancellationToken.ThrowIfCancellationRequested(); + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } return Task.FromResult(Convert.ToString(user.Id, CultureInfo.InvariantCulture)); } - public Task GetUserName(TUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserNameAsync(TUser user, CancellationToken cancellationToken = new CancellationToken()) { + cancellationToken.ThrowIfCancellationRequested(); + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } return Task.FromResult(user.UserName); } - public async virtual Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = new CancellationToken()) + { + cancellationToken.ThrowIfCancellationRequested(); + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + user.UserName = userName; + return Task.FromResult(0); + } + + public async virtual Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -88,7 +112,7 @@ namespace Microsoft.AspNet.Identity.Entity await SaveChanges(cancellationToken); } - public async virtual Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -100,7 +124,7 @@ namespace Microsoft.AspNet.Identity.Entity await SaveChanges(cancellationToken); } - public async virtual Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -118,12 +142,12 @@ namespace Microsoft.AspNet.Identity.Entity } /// - /// Find a user by id + /// FindByLoginAsync a user by id /// /// /// /// - public virtual Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -133,12 +157,12 @@ namespace Microsoft.AspNet.Identity.Entity } /// - /// Find a user by name + /// FindByLoginAsync a user by name /// /// /// /// - public virtual Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -151,7 +175,7 @@ namespace Microsoft.AspNet.Identity.Entity get { return Context.Set(); } } - public async virtual Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -173,7 +197,7 @@ namespace Microsoft.AspNet.Identity.Entity user.Logins.Add(l); } - public virtual Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task RemoveLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -184,7 +208,7 @@ namespace Microsoft.AspNet.Identity.Entity throw new NotImplementedException(); } - public virtual Task> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -197,7 +221,7 @@ namespace Microsoft.AspNet.Identity.Entity return Task.FromResult(result); } - public async virtual Task Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public async virtual Task FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -224,7 +248,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetPasswordHash(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -242,7 +266,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetPasswordHash(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetPasswordHashAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -259,7 +283,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task HasPassword(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); return Task.FromResult(user.PasswordHash != null); @@ -271,7 +295,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task> GetClaims(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -290,7 +314,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task AddClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -313,7 +337,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task RemoveClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -348,7 +372,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetEmailConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -366,7 +390,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetEmailConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -385,7 +409,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetEmail(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -403,7 +427,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetEmail(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -415,12 +439,12 @@ namespace Microsoft.AspNet.Identity.Entity } /// - /// Find a user by email + /// FindByLoginAsync a user by email /// /// /// /// - public virtual Task FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -435,7 +459,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -456,7 +480,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -474,7 +498,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task IncrementAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -492,7 +516,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task ResetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -511,7 +535,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -528,7 +552,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetLockoutEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -546,7 +570,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetLockoutEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -565,7 +589,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetPhoneNumber(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -583,7 +607,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetPhoneNumber(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -600,7 +624,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetPhoneNumberConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -618,7 +642,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetPhoneNumberConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -637,7 +661,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task AddToRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -669,7 +693,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task RemoveFromRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -690,7 +714,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task> GetRoles(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -708,7 +732,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task IsInRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -730,7 +754,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetSecurityStamp(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -748,7 +772,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetSecurityStamp(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -766,7 +790,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task SetTwoFactorEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); @@ -784,7 +808,7 @@ namespace Microsoft.AspNet.Identity.Entity /// /// /// - public virtual Task GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); diff --git a/src/Microsoft.AspNet.Identity.InMemory/InMemoryRoleStore.cs b/src/Microsoft.AspNet.Identity.InMemory/InMemoryRoleStore.cs index 0ff53eb7f9..65745ca9bb 100644 --- a/src/Microsoft.AspNet.Identity.InMemory/InMemoryRoleStore.cs +++ b/src/Microsoft.AspNet.Identity.InMemory/InMemoryRoleStore.cs @@ -11,13 +11,13 @@ namespace Microsoft.AspNet.Identity.InMemory { private readonly Dictionary _roles = new Dictionary(); - public Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { _roles[role.Id] = role; return Task.FromResult(0); } - public Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { if (role == null || !_roles.ContainsKey(role.Id)) { @@ -27,23 +27,23 @@ namespace Microsoft.AspNet.Identity.InMemory return Task.FromResult(0); } - public Task GetRoleId(TRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleIdAsync(TRole role, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(role.Id); } - public Task GetRoleName(TRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleNameAsync(TRole role, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(role.Name); } - public Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { _roles[role.Id] = role; return Task.FromResult(0); } - public Task FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken)) { if (_roles.ContainsKey(roleId)) { @@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Identity.InMemory return Task.FromResult(null); } - public Task FindByName(string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult( diff --git a/src/Microsoft.AspNet.Identity.InMemory/InMemoryUserStore.cs b/src/Microsoft.AspNet.Identity.InMemory/InMemoryUserStore.cs index f343799506..a3914ab559 100644 --- a/src/Microsoft.AspNet.Identity.InMemory/InMemoryUserStore.cs +++ b/src/Microsoft.AspNet.Identity.InMemory/InMemoryUserStore.cs @@ -30,99 +30,99 @@ namespace Microsoft.AspNet.Identity.InMemory get { return _users.Values.AsQueryable(); } } - public Task> GetClaims(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.Claims); } - public Task AddClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { user.Claims.Add(claim); return Task.FromResult(0); } - public Task RemoveClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { user.Claims.Remove(claim); return Task.FromResult(0); } - public Task SetEmail(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) { user.Email = email; return Task.FromResult(0); } - public Task GetEmail(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.Email); } - public Task GetEmailConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.EmailConfirmed); } - public Task SetEmailConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { user.EmailConfirmed = confirmed; return Task.FromResult(0); } - public Task FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult( Users.FirstOrDefault(u => String.Equals(u.Email, email, StringComparison.OrdinalIgnoreCase))); } - public Task GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.LockoutEnd); } - public Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) { user.LockoutEnd = lockoutEnd; return Task.FromResult(0); } - public Task IncrementAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { user.AccessFailedCount++; return Task.FromResult(user.AccessFailedCount); } - public Task ResetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { user.AccessFailedCount = 0; return Task.FromResult(0); } - public Task GetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.AccessFailedCount); } - public Task GetLockoutEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.LockoutEnabled); } - public Task SetLockoutEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { user.LockoutEnabled = enabled; return Task.FromResult(0); } - public Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { user.Logins.Add(login); _logins[login] = user; return Task.FromResult(0); } - public Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { var logs = user.Logins.Where(l => l.ProviderKey == login.ProviderKey && l.LoginProvider == login.LoginProvider) @@ -135,12 +135,12 @@ namespace Microsoft.AspNet.Identity.InMemory return Task.FromResult(0); } - public Task> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.Logins); } - public Task Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { if (_logins.ContainsKey(login)) { @@ -149,29 +149,35 @@ namespace Microsoft.AspNet.Identity.InMemory return Task.FromResult(null); } - public Task GetUserId(TUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserIdAsync(TUser user, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(user.Id); } - public Task GetUserName(TUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserNameAsync(TUser user, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(user.UserName); } - public Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = new CancellationToken()) + { + user.UserName = userName; + return Task.FromResult(0); + } + + public Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { _users[user.Id] = user; return Task.FromResult(0); } - public Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { _users[user.Id] = user; return Task.FromResult(0); } - public Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { if (_users.ContainsKey(userId)) { @@ -184,14 +190,14 @@ namespace Microsoft.AspNet.Identity.InMemory { } - public Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult( Users.FirstOrDefault(u => String.Equals(u.UserName, userName, StringComparison.OrdinalIgnoreCase))); } - public Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null || !_users.ContainsKey(user.Id)) { @@ -201,84 +207,84 @@ namespace Microsoft.AspNet.Identity.InMemory return Task.FromResult(0); } - public Task SetPasswordHash(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) { user.PasswordHash = passwordHash; return Task.FromResult(0); } - public Task GetPasswordHash(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPasswordHashAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.PasswordHash); } - public Task HasPassword(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.PasswordHash != null); } - public Task SetPhoneNumber(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) { user.PhoneNumber = phoneNumber; return Task.FromResult(0); } - public Task GetPhoneNumber(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.PhoneNumber); } - public Task GetPhoneNumberConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.PhoneNumberConfirmed); } - public Task SetPhoneNumberConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { user.PhoneNumberConfirmed = confirmed; return Task.FromResult(0); } - public Task AddToRole(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddToRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) { user.Roles.Add(role); return Task.FromResult(0); } - public Task RemoveFromRole(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveFromRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) { user.Roles.Remove(role); return Task.FromResult(0); } - public Task> GetRoles(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.Roles); } - public Task IsInRole(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) + public Task IsInRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.Roles.Contains(role)); } - public Task SetSecurityStamp(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)) { user.SecurityStamp = stamp; return Task.FromResult(0); } - public Task GetSecurityStamp(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.SecurityStamp); } - public Task SetTwoFactorEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { user.TwoFactorEnabled = enabled; return Task.FromResult(0); } - public Task GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(user.TwoFactorEnabled); } diff --git a/src/Microsoft.AspNet.Identity.Security/SignInManager.cs b/src/Microsoft.AspNet.Identity.Security/SignInManager.cs index b4e0e9cfec..fac5469cc9 100644 --- a/src/Microsoft.AspNet.Identity.Security/SignInManager.cs +++ b/src/Microsoft.AspNet.Identity.Security/SignInManager.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Identity.Security public HttpContext Context { get; set; } - public virtual async Task CreateUserIdentity(TUser user) + public virtual async Task CreateUserIdentityAsync(TUser user) { if (UserManager == null) { @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Identity.Security } // TODO: all the two factor logic/external/rememberBrowser - var userIdentity = await CreateUserIdentity(user); + var userIdentity = await CreateUserIdentityAsync(user); Context.Response.SignIn(userIdentity, new AuthenticationProperties { IsPersistent = isPersistent }); } @@ -49,18 +49,18 @@ namespace Microsoft.AspNet.Identity.Security // return false; // } - // var token = await UserManager.GenerateTwoFactorToken(userId, provider); + // var token = await UserManager.GenerateTwoFactorTokenAsync(userId, provider); // // See IdentityConfig.cs to plug in Email/SMS services to actually send the code - // await UserManager.NotifyTwoFactorToken(userId, provider, token); + // await UserManager.NotifyTwoFactorTokenAsync(userId, provider, token); // return true; //} //public Task GetVerifiedUserId() //{ // //var result = await AuthenticationManager.Authenticate(DefaultAuthenticationTypes.TwoFactorCookie); - // //if (result != null && result.Identity != null && !String.IsNullOrEmpty(result.Identity.GetUserId())) + // //if (result != null && result.Identity != null && !String.IsNullOrEmpty(result.Identity.GetUserIdAsync())) // //{ - // // return result.Identity.GetUserId(); + // // return result.Identity.GetUserIdAsync(); // //} // return Task.FromResult(default(TKey)); //} @@ -77,35 +77,35 @@ namespace Microsoft.AspNet.Identity.Security // { // return SignInStatus.Failure; // } - // var user = await UserManager.FindById(userId); + // var user = await UserManager.FindByIdAsync(userId); // if (user == null) // { // return SignInStatus.Failure; // } - // if (await UserManager.IsLockedOut(user.Id)) + // if (await UserManager.IsLockedOutAsync(user.Id)) // { // return SignInStatus.LockedOut; // } - // if (await UserManager.VerifyTwoFactorToken(user.Id, provider, code)) + // if (await UserManager.VerifyTwoFactorTokenAsync(user.Id, provider, code)) // { // // When token is verified correctly, clear the access failed count used for lockout - // await UserManager.ResetAccessFailedCount(user.Id); + // await UserManager.ResetAccessFailedCountAsync(user.Id); // await SignIn(user, isPersistent, rememberBrowser); // return SignInStatus.Success; // } // // If the token is incorrect, record the failure which also may cause the user to be locked out - // await UserManager.AccessFailed(user.Id); + // await UserManager.AccessFailedAsync(user.Id); // return SignInStatus.Failure; //} //public async Task ExternalSignIn(ExternalLoginInfo loginInfo, bool isPersistent) //{ - // var user = await UserManager.Find(loginInfo.Login); + // var user = await UserManager.FindByLoginAsync(loginInfo.Login); // if (user == null) // { // return SignInStatus.Failure; // } - // if (await UserManager.IsLockedOut(user.Id)) + // if (await UserManager.IsLockedOutAsync(user.Id)) // { // return SignInStatus.LockedOut; // } @@ -114,11 +114,11 @@ namespace Microsoft.AspNet.Identity.Security //private async Task SignInOrTwoFactor(TUser user, bool isPersistent) //{ - // if (await UserManager.GetTwoFactorEnabled(user.Id)) + // if (await UserManager.GetTwoFactorEnabledAsync(user.Id)) // //&& !await AuthenticationManager.TwoFactorBrowserRemembered(user.Id)) // { // //var identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie); - // //identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); + // //identity.AddClaimAsync(new Claim(ClaimTypes.NameIdentifier, user.Id)); // //AuthenticationManager.SignIn(identity); // return SignInStatus.RequiresTwoFactorAuthentication; // } @@ -126,24 +126,22 @@ namespace Microsoft.AspNet.Identity.Security // return SignInStatus.Success; //} - public virtual async Task PasswordSignIn(string userName, string password, bool isPersistent, bool shouldLockout) + public virtual async Task PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout) { if (UserManager == null) { return SignInStatus.Failure; } - var user = await UserManager.FindByName(userName); + var user = await UserManager.FindByNameAsync(userName); if (user == null) { return SignInStatus.Failure; } - // TODO: overloads taking TUser? - var userId = await UserManager.GetUserId(user); - if (await UserManager.IsLockedOut(userId)) + if (await UserManager.IsLockedOutAsync(user)) { return SignInStatus.LockedOut; } - if (await UserManager.CheckPassword(user, password)) + if (await UserManager.CheckPasswordAsync(user, password)) { await SignIn(user, isPersistent, false); return SignInStatus.Success; @@ -152,8 +150,8 @@ namespace Microsoft.AspNet.Identity.Security if (shouldLockout) { // If lockout is requested, increment access failed count which might lock out the user - await UserManager.AccessFailed(userId); - if (await UserManager.IsLockedOut(userId)) + await UserManager.AccessFailedAsync(user); + if (await UserManager.IsLockedOutAsync(user)) { return SignInStatus.LockedOut; } diff --git a/src/Microsoft.AspNet.Identity/ClaimsIdentityFactory.cs b/src/Microsoft.AspNet.Identity/ClaimsIdentityFactory.cs index 37f5d892dc..5181f879dc 100644 --- a/src/Microsoft.AspNet.Identity/ClaimsIdentityFactory.cs +++ b/src/Microsoft.AspNet.Identity/ClaimsIdentityFactory.cs @@ -50,14 +50,14 @@ namespace Microsoft.AspNet.Identity public string SecurityStampClaimType { get; set; } /// - /// Create a ClaimsIdentity from a user + /// CreateAsync a ClaimsIdentity from a user /// /// /// /// /// /// - public virtual async Task Create(UserManager manager, TUser user, + public virtual async Task CreateAsync(UserManager manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken)) { if (manager == null) @@ -68,18 +68,18 @@ namespace Microsoft.AspNet.Identity { throw new ArgumentNullException("user"); } - var userId = await manager.GetUserId(user, cancellationToken); - var userName = await manager.GetUserName(user, cancellationToken); + var userId = await manager.GetUserIdAsync(user, cancellationToken); + var userName = await manager.GetUserNameAsync(user, cancellationToken); var id = new ClaimsIdentity(authenticationType, UserNameClaimType, RoleClaimType); id.AddClaim(new Claim(UserIdClaimType, userId)); id.AddClaim(new Claim(UserNameClaimType, userName, ClaimValueTypes.String)); if (manager.SupportsUserSecurityStamp) { - id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStamp(userId, cancellationToken))); + id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStampAsync(user, cancellationToken))); } if (manager.SupportsUserRole) { - var roles = await manager.GetRoles(userId, cancellationToken); + var roles = await manager.GetRolesAsync(user, cancellationToken); foreach (var roleName in roles) { id.AddClaim(new Claim(RoleClaimType, roleName, ClaimValueTypes.String)); @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Identity } if (manager.SupportsUserClaim) { - id.AddClaims(await manager.GetClaims(userId, cancellationToken)); + id.AddClaims(await manager.GetClaimsAsync(user, cancellationToken)); } return id; } diff --git a/src/Microsoft.AspNet.Identity/IClaimsIdentityFactory.cs b/src/Microsoft.AspNet.Identity/IClaimsIdentityFactory.cs index 6e8f15ce4b..9dd3c6b0cd 100644 --- a/src/Microsoft.AspNet.Identity/IClaimsIdentityFactory.cs +++ b/src/Microsoft.AspNet.Identity/IClaimsIdentityFactory.cs @@ -13,13 +13,13 @@ namespace Microsoft.AspNet.Identity where TUser : class { /// - /// Create a ClaimsIdentity from an user using a UserManager + /// CreateAsync a ClaimsIdentity from an user using a UserManager /// /// /// /// /// /// - Task Create(UserManager manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateAsync(UserManager manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IIdentityMessageService.cs b/src/Microsoft.AspNet.Identity/IIdentityMessageService.cs index 884ba15444..317179fff5 100644 --- a/src/Microsoft.AspNet.Identity/IIdentityMessageService.cs +++ b/src/Microsoft.AspNet.Identity/IIdentityMessageService.cs @@ -14,6 +14,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Send(IdentityMessage message, CancellationToken cancellationToken = default(CancellationToken)); + Task SendAsync(IdentityMessage message, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IPasswordValidator.cs b/src/Microsoft.AspNet.Identity/IPasswordValidator.cs index 0b4cd3fa23..21bff33261 100644 --- a/src/Microsoft.AspNet.Identity/IPasswordValidator.cs +++ b/src/Microsoft.AspNet.Identity/IPasswordValidator.cs @@ -9,9 +9,9 @@ namespace Microsoft.AspNet.Identity public interface IPasswordValidator { /// - /// Validate the item + /// ValidateAsync the item /// /// - Task Validate(string password, CancellationToken cancellationToken = default(CancellationToken)); + Task ValidateAsync(string password, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IRole.cs b/src/Microsoft.AspNet.Identity/IRole.cs deleted file mode 100644 index 01b724ccac..0000000000 --- a/src/Microsoft.AspNet.Identity/IRole.cs +++ /dev/null @@ -1,19 +0,0 @@ -//namespace Microsoft.AspNet.Identity -//{ -// /// -// /// Mimimal set of data needed to persist role data -// /// -// /// -// public interface IRole -// { -// /// -// /// Id of the role -// /// -// TKey Id { get; } - -// /// -// /// Name of the role -// /// -// string Name { get; set; } -// } -//} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IRoleStore.cs b/src/Microsoft.AspNet.Identity/IRoleStore.cs index 04e9a600e6..91449f0c05 100644 --- a/src/Microsoft.AspNet.Identity/IRoleStore.cs +++ b/src/Microsoft.AspNet.Identity/IRoleStore.cs @@ -16,23 +16,23 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Update a role + /// UpdateAsync a role /// /// /// /// - Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken)); + Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Delete a role + /// DeleteAsync a role /// /// /// /// - Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken)); + Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns a role's id @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetRoleId(TRole role, CancellationToken cancellationToken = default(CancellationToken)); + Task GetRoleIdAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns a role's name @@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetRoleName(TRole role, CancellationToken cancellationToken = default(CancellationToken)); + Task GetRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)); /// /// Finds a role by id @@ -56,14 +56,14 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken)); + Task FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Find a role by name + /// FindByLoginAsync a role by name /// /// /// /// - Task FindByName(string roleName, CancellationToken cancellationToken = default(CancellationToken)); + Task FindByNameAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IRoleValidator.cs b/src/Microsoft.AspNet.Identity/IRoleValidator.cs index 71bdef4d66..ba42d3861a 100644 --- a/src/Microsoft.AspNet.Identity/IRoleValidator.cs +++ b/src/Microsoft.AspNet.Identity/IRoleValidator.cs @@ -12,12 +12,12 @@ namespace Microsoft.AspNet.Identity public interface IRoleValidator where TRole : class { /// - /// Validate the user + /// ValidateAsync the user /// /// /// /// /// - Task Validate(RoleManager manager, TRole role, CancellationToken cancellationToken = default(CancellationToken)); + Task ValidateAsync(RoleManager manager, TRole role, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUser.cs b/src/Microsoft.AspNet.Identity/IUser.cs deleted file mode 100644 index 81030f66b8..0000000000 --- a/src/Microsoft.AspNet.Identity/IUser.cs +++ /dev/null @@ -1,19 +0,0 @@ -//namespace Microsoft.AspNet.Identity -//{ -// /// -// /// Minimal interface for a user with id and username -// /// -// /// -// public interface IUser -// { -// /// -// /// Unique key for the user -// /// -// TKey Id { get; } - -// /// -// /// Unique username -// /// -// string UserName { get; set; } -// } -//} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserClaimStore.cs b/src/Microsoft.AspNet.Identity/IUserClaimStore.cs index af914c2b36..a9ff3a9a0e 100644 --- a/src/Microsoft.AspNet.Identity/IUserClaimStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserClaimStore.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task> GetClaims(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Add a new user claim @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task AddClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)); + Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)); /// /// Remove a user claim @@ -35,6 +35,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task RemoveClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserEmailStore.cs b/src/Microsoft.AspNet.Identity/IUserEmailStore.cs index 50671587c6..0ae911658c 100644 --- a/src/Microsoft.AspNet.Identity/IUserEmailStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserEmailStore.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetEmail(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)); + Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)); /// /// Get the user email @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetEmail(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns true if the user email is confirmed @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetEmailConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Sets whether the user email is confirmed @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetEmailConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)); + Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the user associated with this email @@ -49,6 +49,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken)); + Task FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserLockoutStore.cs b/src/Microsoft.AspNet.Identity/IUserLockoutStore.cs index 93bd3cd20d..592d839edb 100644 --- a/src/Microsoft.AspNet.Identity/IUserLockoutStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserLockoutStore.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Locks a user out until the specified end date (set to a past date, to unlock a user) @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)); + Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)); /// /// Used to record when an attempt to access the user has failed @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task IncrementAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Used to reset the account access count, typically after the account is successfully accessed @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task ResetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the current number of failed access attempts. This number usually will be reset whenever the password is @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns whether the user can be locked out. @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetLockoutEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Sets whether the user can be locked out. @@ -68,6 +68,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetLockoutEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)); + Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserLoginStore.cs b/src/Microsoft.AspNet.Identity/IUserLoginStore.cs index b38c490507..3281a1436a 100644 --- a/src/Microsoft.AspNet.Identity/IUserLoginStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserLoginStore.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)); + Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)); /// /// Removes the user login with the specified combination if it exists, returns true if found and removed @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the linked accounts for this user @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the user associated with this login @@ -42,6 +42,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)); + Task FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserNameStore.cs b/src/Microsoft.AspNet.Identity/IUserNameStore.cs deleted file mode 100644 index 885198b37c..0000000000 --- a/src/Microsoft.AspNet.Identity/IUserNameStore.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.AspNet.Identity -{ - /// - /// Stores a user's email - /// - /// - public interface IUserNameStore : IUserStore where TUser : class - { - /// - /// Set the user name - /// - /// - /// - /// - /// - Task SetUserName(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken)); - - /// - /// Get the user name - /// - /// - /// - /// - Task GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken)); - - /// - /// Returns the user associated with this name - /// - /// - /// - /// - Task FindByName(string name, CancellationToken cancellationToken = default(CancellationToken)); - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserPasswordStore.cs b/src/Microsoft.AspNet.Identity/IUserPasswordStore.cs index 48f6a694ce..dbd8095242 100644 --- a/src/Microsoft.AspNet.Identity/IUserPasswordStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserPasswordStore.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetPasswordHash(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)); + Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)); /// /// Get the user password hash @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetPasswordHash(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetPasswordHashAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns true if a user has a password set @@ -32,6 +32,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task HasPassword(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserPhoneNumberStore.cs b/src/Microsoft.AspNet.Identity/IUserPhoneNumberStore.cs index 4246136693..16e8d8f600 100644 --- a/src/Microsoft.AspNet.Identity/IUserPhoneNumberStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserPhoneNumberStore.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetPhoneNumber(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)); + Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)); /// /// Get the user phoneNumber @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetPhoneNumber(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns true if the user phone number is confirmed @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetPhoneNumberConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Sets whether the user phone number is confirmed @@ -41,6 +41,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetPhoneNumberConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)); + Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserRoleStore.cs b/src/Microsoft.AspNet.Identity/IUserRoleStore.cs index 7e135f3699..9145c052a5 100644 --- a/src/Microsoft.AspNet.Identity/IUserRoleStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserRoleStore.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task AddToRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)); + Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)); /// /// Removes the role for the user @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task RemoveFromRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)); + Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the roles for this user @@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task> GetRoles(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns true if a user is in a role @@ -43,6 +43,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task IsInRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)); + Task IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserSecurityStampStore.cs b/src/Microsoft.AspNet.Identity/IUserSecurityStampStore.cs index 5f7596a02b..86f10dc751 100644 --- a/src/Microsoft.AspNet.Identity/IUserSecurityStampStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserSecurityStampStore.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetSecurityStamp(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)); + Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)); /// /// Get the user security stamp @@ -24,6 +24,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetSecurityStamp(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserStore.cs b/src/Microsoft.AspNet.Identity/IUserStore.cs index a030602824..fff2177af6 100644 --- a/src/Microsoft.AspNet.Identity/IUserStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserStore.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetUserId(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetUserIdAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the user's name @@ -25,7 +25,16 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetUserNameAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + + /// + /// Set the user name + /// + /// + /// + /// + /// + Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken)); /// /// Insert a new user @@ -33,23 +42,23 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Update a user + /// UpdateAsync a user /// /// /// /// - Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Delete a user + /// DeleteAsync a user /// /// /// /// - Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Finds a user @@ -57,7 +66,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)); + Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns the user associated with this name @@ -65,7 +74,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task FindByName(string name, CancellationToken cancellationToken = default(CancellationToken)); + Task FindByNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs b/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs index 27ef69fa94..f5971ac498 100644 --- a/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs +++ b/src/Microsoft.AspNet.Identity/IUserTokenProvider.cs @@ -17,10 +17,10 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Generate(string purpose, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GenerateAsync(string purpose, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// - /// Validate and unprotect a token, returns null if invalid + /// ValidateAsync and unprotect a token, returns null if invalid /// /// /// @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Validate(string purpose, string token, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task ValidateAsync(string purpose, string token, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Notifies the user that a token has been generated, i.e. via email or sms, or can no-op @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task Notify(string token, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task NotifyAsync(string token, UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns true if provider can be used for this user, i.e. could require a user to have an email @@ -47,6 +47,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task IsValidProviderForUser(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task IsValidProviderForUserAsync(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserTwoFactorStore.cs b/src/Microsoft.AspNet.Identity/IUserTwoFactorStore.cs index 8f85a62ed3..7e0d799868 100644 --- a/src/Microsoft.AspNet.Identity/IUserTwoFactorStore.cs +++ b/src/Microsoft.AspNet.Identity/IUserTwoFactorStore.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task SetTwoFactorEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)); + Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)); /// /// Returns whether two factor is enabled for the user @@ -24,6 +24,6 @@ namespace Microsoft.AspNet.Identity /// /// /// - Task GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/IUserValidator.cs b/src/Microsoft.AspNet.Identity/IUserValidator.cs index e4d64da6c3..0f16e28ed0 100644 --- a/src/Microsoft.AspNet.Identity/IUserValidator.cs +++ b/src/Microsoft.AspNet.Identity/IUserValidator.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNet.Identity public interface IUserValidator where TUser : class { /// - /// Validate the user + /// ValidateAsync the user /// /// /// /// /// - Task Validate(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); + Task ValidateAsync(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Identity/PasswordValidator.cs b/src/Microsoft.AspNet.Identity/PasswordValidator.cs index 8668991f46..c6770cbff1 100644 --- a/src/Microsoft.AspNet.Identity/PasswordValidator.cs +++ b/src/Microsoft.AspNet.Identity/PasswordValidator.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual Task Validate(string item, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task ValidateAsync(string item, CancellationToken cancellationToken = default(CancellationToken)) { if (item == null) { diff --git a/src/Microsoft.AspNet.Identity/Resources.resx b/src/Microsoft.AspNet.Identity/Resources.resx index c9b40f983d..a78553d9dc 100644 --- a/src/Microsoft.AspNet.Identity/Resources.resx +++ b/src/Microsoft.AspNet.Identity/Resources.resx @@ -239,16 +239,12 @@ User already has a password set. - error when AddPassword called when a user already has a password + error when AddPasswordAsync called when a user already has a password User already in role. Error when a user is already in a role - - UserId not found. - No user with this id found - User {0} does not exist. error when a user does not exist diff --git a/src/Microsoft.AspNet.Identity/Rfc6238AuthenticationService.cs b/src/Microsoft.AspNet.Identity/Rfc6238AuthenticationService.cs index 3f24a25a45..091bc2247f 100644 --- a/src/Microsoft.AspNet.Identity/Rfc6238AuthenticationService.cs +++ b/src/Microsoft.AspNet.Identity/Rfc6238AuthenticationService.cs @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity var timestepAsBytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((long) timestepNumber)); var hash = hashAlgorithm.ComputeHash(ApplyModifier(timestepAsBytes, modifier)); - // Generate DT string + // GenerateAsync DT string var offset = hash[hash.Length - 1] & 0xf; Debug.Assert(offset + 4 < hash.Length); var binaryCode = (hash[offset] & 0x7f) << 24 diff --git a/src/Microsoft.AspNet.Identity/RoleManager.cs b/src/Microsoft.AspNet.Identity/RoleManager.cs index 909c2030a8..0a9b00cfa2 100644 --- a/src/Microsoft.AspNet.Identity/RoleManager.cs +++ b/src/Microsoft.AspNet.Identity/RoleManager.cs @@ -76,16 +76,16 @@ namespace Microsoft.AspNet.Identity private async Task ValidateRoleInternal(TRole role, CancellationToken cancellationToken) { - return (RoleValidator == null) ? IdentityResult.Success : await RoleValidator.Validate(this, role, cancellationToken); + return (RoleValidator == null) ? IdentityResult.Success : await RoleValidator.ValidateAsync(this, role, cancellationToken); } /// - /// Create a role + /// CreateAsync a role /// /// /// /// - public virtual async Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (role == null) @@ -98,17 +98,17 @@ namespace Microsoft.AspNet.Identity { return result; } - await Store.Create(role, cancellationToken); + await Store.CreateAsync(role, cancellationToken); return IdentityResult.Success; } /// - /// Update an existing role + /// UpdateAsync an existing role /// /// /// /// - public virtual async Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (role == null) @@ -121,17 +121,17 @@ namespace Microsoft.AspNet.Identity { return result; } - await Store.Update(role, cancellationToken); + await Store.UpdateAsync(role, cancellationToken); return IdentityResult.Success; } /// - /// Delete a role + /// DeleteAsync a role /// /// /// /// - public virtual async Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (role == null) @@ -139,7 +139,7 @@ namespace Microsoft.AspNet.Identity throw new ArgumentNullException("role"); } - await Store.Delete(role, cancellationToken); + await Store.DeleteAsync(role, cancellationToken); return IdentityResult.Success; } @@ -149,7 +149,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task RoleExists(string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task RoleExistsAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (roleName == null) @@ -161,15 +161,15 @@ namespace Microsoft.AspNet.Identity } /// - /// Find a role by id + /// FindByLoginAsync a role by id /// /// /// /// - public virtual async Task FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return await Store.FindById(roleId, cancellationToken); + return await Store.FindByIdAsync(roleId, cancellationToken); } /// @@ -178,10 +178,10 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task GetRoleName(TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return await Store.GetRoleName(role, cancellationToken); + return await Store.GetRoleNameAsync(role, cancellationToken); } /// @@ -193,11 +193,11 @@ namespace Microsoft.AspNet.Identity public virtual async Task GetRoleId(TRole role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return await Store.GetRoleId(role, cancellationToken); + return await Store.GetRoleIdAsync(role, cancellationToken); } /// - /// Find a role by name + /// FindByLoginAsync a role by name /// /// /// @@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Identity throw new ArgumentNullException("roleName"); } - return await Store.FindByName(roleName, cancellationToken); + return await Store.FindByNameAsync(roleName, cancellationToken); } private void ThrowIfDisposed() diff --git a/src/Microsoft.AspNet.Identity/RoleValidator.cs b/src/Microsoft.AspNet.Identity/RoleValidator.cs index 1992bdb51c..afb547b0eb 100644 --- a/src/Microsoft.AspNet.Identity/RoleValidator.cs +++ b/src/Microsoft.AspNet.Identity/RoleValidator.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task Validate(RoleManager manager, TRole role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task ValidateAsync(RoleManager manager, TRole role, CancellationToken cancellationToken = default(CancellationToken)) { if (manager == null) { @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity private static async Task ValidateRoleName(RoleManager manager, TRole role, ICollection errors) { - var roleName = await manager.GetRoleName(role); + var roleName = await manager.GetRoleNameAsync(role); if (string.IsNullOrWhiteSpace(roleName)) { errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Name")); diff --git a/src/Microsoft.AspNet.Identity/UserManager.cs b/src/Microsoft.AspNet.Identity/UserManager.cs index ae0b96b264..3b005bf6c1 100644 --- a/src/Microsoft.AspNet.Identity/UserManager.cs +++ b/src/Microsoft.AspNet.Identity/UserManager.cs @@ -318,23 +318,23 @@ namespace Microsoft.AspNet.Identity { throw new ArgumentNullException("user"); } - return ClaimsIdentityFactory.Create(this, user, authenticationType, cancellationToken); + return ClaimsIdentityFactory.CreateAsync(this, user, authenticationType, cancellationToken); } private async Task ValidateUserInternal(TUser user, CancellationToken cancellationToken) { return (UserValidator == null) ? IdentityResult.Success - : await UserValidator.Validate(this, user, cancellationToken); + : await UserValidator.ValidateAsync(this, user, cancellationToken); } /// - /// Create a user with no password + /// CreateAsync a user with no password /// /// /// /// - public virtual async Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); await UpdateSecurityStampInternal(user, cancellationToken); @@ -345,19 +345,19 @@ namespace Microsoft.AspNet.Identity } if (UserLockoutEnabledByDefault && SupportsUserLockout) { - await GetUserLockoutStore().SetLockoutEnabled(user, true, cancellationToken); + await GetUserLockoutStore().SetLockoutEnabledAsync(user, true, cancellationToken); } - await Store.Create(user, cancellationToken); + await Store.CreateAsync(user, cancellationToken); return IdentityResult.Success; } /// - /// Update a user + /// UpdateAsync a user /// /// /// /// - public virtual async Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (user == null) @@ -369,53 +369,53 @@ namespace Microsoft.AspNet.Identity { return result; } - await Store.Update(user, cancellationToken); + await Store.UpdateAsync(user, cancellationToken); return IdentityResult.Success; } /// - /// Delete a user + /// DeleteAsync a user /// /// /// /// - public virtual async Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } - await Store.Delete(user, cancellationToken); + await Store.DeleteAsync(user, cancellationToken); return IdentityResult.Success; } /// - /// Find a user by id + /// FindByLoginAsync a user by id /// /// /// /// - public virtual Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return Store.FindById(userId, cancellationToken); + return Store.FindByIdAsync(userId, cancellationToken); } /// - /// Find a user by name + /// FindByLoginAsync a user by name /// /// /// /// - public virtual Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (userName == null) { throw new ArgumentNullException("userName"); } - return Store.FindByName(userName, cancellationToken); + return Store.FindByNameAsync(userName, cancellationToken); } // IUserPasswordStore methods @@ -430,12 +430,12 @@ namespace Microsoft.AspNet.Identity } /// - /// Create a user and associates it with the given password (if one is provided) + /// CreateAsync a user and associates it with the given password (if one is provided) /// /// /// /// - public virtual async Task Create(TUser user, string password, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task CreateAsync(TUser user, string password, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var passwordStore = GetPasswordStore(); @@ -452,7 +452,7 @@ namespace Microsoft.AspNet.Identity { return result; } - return await Create(user, cancellationToken); + return await CreateAsync(user, cancellationToken); } /// @@ -461,10 +461,32 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetUserNameAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return await Store.GetUserName(user, cancellationToken); + if (user == null) + { + throw new ArgumentNullException("user"); + } + return await Store.GetUserNameAsync(user, cancellationToken); + } + + /// + /// Set the user's name + /// + /// + /// + /// + /// + public virtual async Task SetUserName(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken)) + { + ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } + await Store.SetUserNameAsync(user, userName, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// @@ -473,10 +495,10 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task GetUserId(TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetUserIdAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return await Store.GetUserId(user, cancellationToken); + return await Store.GetUserIdAsync(user, cancellationToken); } /// @@ -486,15 +508,15 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task Find(string userName, string password, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task FindByUserNamePassword(string userName, string password, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - var user = await FindByName(userName, cancellationToken); + var user = await FindByNameAsync(userName, cancellationToken); if (user == null) { return null; } - return await CheckPassword(user, password, cancellationToken) ? user : null; + return await CheckPasswordAsync(user, password, cancellationToken) ? user : null; } /// @@ -504,7 +526,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task CheckPassword(TUser user, string password, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task CheckPasswordAsync(TUser user, string password, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var passwordStore = GetPasswordStore(); @@ -512,46 +534,42 @@ namespace Microsoft.AspNet.Identity { return false; } - return await VerifyPassword(passwordStore, user, password, cancellationToken); + return await VerifyPasswordAsync(passwordStore, user, password, cancellationToken); } /// /// Returns true if the user has a password /// - /// + /// /// /// - public virtual async Task HasPassword(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var passwordStore = GetPasswordStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await passwordStore.HasPassword(user, cancellationToken); + return await passwordStore.HasPasswordAsync(user, cancellationToken); } /// /// Add a user password only if one does not already exist /// - /// + /// /// /// /// - public virtual async Task AddPassword(string userId, string password, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task AddPasswordAsync(TUser user, string password, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var passwordStore = GetPasswordStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - var hash = await passwordStore.GetPasswordHash(user, cancellationToken); + var hash = await passwordStore.GetPasswordHashAsync(user, cancellationToken); if (hash != null) { return new IdentityResult(Resources.UserAlreadyHasPassword); @@ -561,36 +579,34 @@ namespace Microsoft.AspNet.Identity { return result; } - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Change a user password /// - /// + /// /// /// /// /// - public virtual async Task ChangePassword(string userId, string currentPassword, + public virtual async Task ChangePasswordAsync(TUser user, string currentPassword, string newPassword, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var passwordStore = GetPasswordStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - if (await VerifyPassword(passwordStore, user, currentPassword, cancellationToken)) + if (await VerifyPasswordAsync(passwordStore, user, currentPassword, cancellationToken)) { var result = await UpdatePasswordInternal(passwordStore, user, newPassword, cancellationToken); if (!result.Succeeded) { return result; } - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } return IdentityResult.Failed(Resources.PasswordMismatch); } @@ -598,22 +614,20 @@ namespace Microsoft.AspNet.Identity /// /// Remove a user's password /// - /// + /// /// /// - public virtual async Task RemovePassword(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task RemovePasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var passwordStore = GetPasswordStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await passwordStore.SetPasswordHash(user, null, cancellationToken); + await passwordStore.SetPasswordHashAsync(user, null, cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } internal async Task UpdatePasswordInternal(IUserPasswordStore passwordStore, @@ -621,14 +635,14 @@ namespace Microsoft.AspNet.Identity { if (PasswordValidator != null) { - var result = await PasswordValidator.Validate(newPassword, cancellationToken); + var result = await PasswordValidator.ValidateAsync(newPassword, cancellationToken); if (!result.Succeeded) { return result; } } await - passwordStore.SetPasswordHash(user, PasswordHasher.HashPassword(newPassword), cancellationToken); + passwordStore.SetPasswordHashAsync(user, PasswordHasher.HashPassword(newPassword), cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); return IdentityResult.Success; } @@ -641,10 +655,10 @@ namespace Microsoft.AspNet.Identity /// /// /// - protected virtual async Task VerifyPassword(IUserPasswordStore store, TUser user, + protected virtual async Task VerifyPasswordAsync(IUserPasswordStore store, TUser user, string password, CancellationToken cancellationToken = default(CancellationToken)) { - var hash = await store.GetPasswordHash(user, cancellationToken); + var hash = await store.GetPasswordHashAsync(user, cancellationToken); return PasswordHasher.VerifyHashedPassword(hash, password) != PasswordVerificationResult.Failed; } @@ -662,73 +676,67 @@ namespace Microsoft.AspNet.Identity /// /// Returns the current security stamp for a user /// - /// + /// /// /// - public virtual async Task GetSecurityStamp(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var securityStore = GetSecurityStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await securityStore.GetSecurityStamp(user, cancellationToken); + return await securityStore.GetSecurityStampAsync(user, cancellationToken); } /// - /// Generate a new security stamp for a user, used for SignOutEverywhere functionality + /// GenerateAsync a new security stamp for a user, used for SignOutEverywhere functionality /// - /// + /// /// /// - public virtual async Task UpdateSecurityStamp(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task UpdateSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var securityStore = GetSecurityStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// - /// Generate a password reset token for the user using the UserTokenProvider + /// GenerateAsync a password reset token for the user using the UserTokenProvider /// - /// + /// /// /// - public virtual async Task GeneratePasswordResetToken(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GeneratePasswordResetTokenAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return await GenerateUserToken("ResetPassword", userId, cancellationToken); + return await GenerateUserTokenAsync("ResetPassword", user, cancellationToken); } /// /// Reset a user's password using a reset password token /// - /// + /// /// /// /// /// - public virtual async Task ResetPassword(string userId, string token, string newPassword, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task ResetPassword(TUser user, string token, string newPassword, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } // Make sure the token is valid and the stamp matches - if (!await VerifyUserToken(userId, "ResetPassword", token, cancellationToken)) + if (!await VerifyUserTokenAsync(user, "ResetPassword", token, cancellationToken)) { return IdentityResult.Failed(Resources.InvalidToken); } @@ -738,15 +746,15 @@ namespace Microsoft.AspNet.Identity { return result; } - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } - // Update the security stamp if the store supports it + // UpdateAsync the security stamp if the store supports it internal async Task UpdateSecurityStampInternal(TUser user, CancellationToken cancellationToken) { if (SupportsUserSecurityStamp) { - await GetSecurityStore().SetSecurityStamp(user, NewSecurityStamp(), cancellationToken); + await GetSecurityStore().SetSecurityStampAsync(user, NewSecurityStamp(), cancellationToken); } } @@ -770,20 +778,20 @@ namespace Microsoft.AspNet.Identity /// Returns the user associated with this login /// /// - public virtual Task Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return GetLoginStore().Find(login, cancellationToken); + return GetLoginStore().FindByLoginAsync(login, cancellationToken); } /// /// Remove a user login /// - /// + /// /// /// /// - public virtual async Task RemoveLogin(string userId, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var loginStore = GetLoginStore(); @@ -791,15 +799,13 @@ namespace Microsoft.AspNet.Identity { throw new ArgumentNullException("login"); } - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await loginStore.RemoveLogin(user, login, cancellationToken); + await loginStore.RemoveLoginAsync(user, login, cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// @@ -809,7 +815,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task AddLogin(string userId, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var loginStore = GetLoginStore(); @@ -817,38 +823,34 @@ namespace Microsoft.AspNet.Identity { throw new ArgumentNullException("login"); } - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - var existingUser = await Find(login, cancellationToken); + var existingUser = await FindByLoginAsync(login, cancellationToken); if (existingUser != null) { return IdentityResult.Failed(Resources.ExternalLoginExists); } - await loginStore.AddLogin(user, login, cancellationToken); - return await Update(user, cancellationToken); + await loginStore.AddLoginAsync(user, login, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Gets the logins for a user. /// - /// + /// /// /// - public virtual async Task> GetLogins(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var loginStore = GetLoginStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await loginStore.GetLogins(user, cancellationToken); + return await loginStore.GetLoginsAsync(user, cancellationToken); } // IUserClaimStore methods @@ -865,11 +867,11 @@ namespace Microsoft.AspNet.Identity /// /// Add a user claim /// - /// + /// /// /// /// - public virtual async Task AddClaim(string userId, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var claimStore = GetClaimStore(); @@ -877,54 +879,48 @@ namespace Microsoft.AspNet.Identity { throw new ArgumentNullException("claim"); } - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await claimStore.AddClaim(user, claim, cancellationToken); - return await Update(user, cancellationToken); + await claimStore.AddClaimAsync(user, claim, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Remove a user claim /// - /// + /// /// /// /// - public virtual async Task RemoveClaim(string userId, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var claimStore = GetClaimStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await claimStore.RemoveClaim(user, claim, cancellationToken); - return await Update(user, cancellationToken); + await claimStore.RemoveClaimAsync(user, claim, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Get a users's claims /// - /// + /// /// /// - public virtual async Task> GetClaims(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var claimStore = GetClaimStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await claimStore.GetClaims(user, cancellationToken); + return await claimStore.GetClaimsAsync(user, cancellationToken); } private IUserRoleStore GetUserRoleStore() @@ -940,91 +936,83 @@ namespace Microsoft.AspNet.Identity /// /// Add a user to a role /// - /// + /// /// /// /// - public virtual async Task AddToRole(string userId, string role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task AddToRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var userRoleStore = GetUserRoleStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - var userRoles = await userRoleStore.GetRoles(user, cancellationToken); + var userRoles = await userRoleStore.GetRolesAsync(user, cancellationToken); if (userRoles.Contains(role)) { return new IdentityResult(Resources.UserAlreadyInRole); } - await userRoleStore.AddToRole(user, role, cancellationToken); - return await Update(user, cancellationToken); + await userRoleStore.AddToRoleAsync(user, role, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Remove a user from a role. /// - /// + /// /// /// /// - public virtual async Task RemoveFromRole(string userId, string role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task RemoveFromRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var userRoleStore = GetUserRoleStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - if (!await userRoleStore.IsInRole(user, role, cancellationToken)) + if (!await userRoleStore.IsInRoleAsync(user, role, cancellationToken)) { return new IdentityResult(Resources.UserNotInRole); } - await userRoleStore.RemoveFromRole(user, role, cancellationToken); - return await Update(user, cancellationToken); + await userRoleStore.RemoveFromRoleAsync(user, role, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Returns the roles for the user /// - /// + /// /// /// - public virtual async Task> GetRoles(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var userRoleStore = GetUserRoleStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await userRoleStore.GetRoles(user, cancellationToken); + return await userRoleStore.GetRolesAsync(user, cancellationToken); } /// /// Returns true if the user is in the specified role /// - /// + /// /// /// /// - public virtual async Task IsInRole(string userId, string role, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task IsInRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var userRoleStore = GetUserRoleStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await userRoleStore.IsInRole(user, role); + return await userRoleStore.IsInRoleAsync(user, role, cancellationToken); } // IUserEmailStore methods @@ -1041,49 +1029,45 @@ namespace Microsoft.AspNet.Identity /// /// Get a user's email /// - /// + /// /// - public virtual async Task GetEmail(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetEmailStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetEmail(user, cancellationToken); + return await store.GetEmailAsync(user, cancellationToken); } /// /// Set a user's email /// - /// + /// /// /// - public virtual async Task SetEmail(string userId, string email, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetEmailStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await store.SetEmail(user, email, cancellationToken); - await store.SetEmailConfirmed(user, false, cancellationToken); + await store.SetEmailAsync(user, email, cancellationToken); + await store.SetEmailConfirmedAsync(user, false, cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// - /// Find a user by his email + /// FindByLoginAsync a user by his email /// /// /// - public virtual Task FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetEmailStore(); @@ -1091,62 +1075,59 @@ namespace Microsoft.AspNet.Identity { throw new ArgumentNullException("email"); } - return store.FindByEmail(email, cancellationToken); + return store.FindByEmailAsync(email, cancellationToken); } /// /// Get the confirmation token for the user /// - /// + /// + /// /// - public virtual Task GenerateEmailConfirmationToken(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual Task GenerateEmailConfirmationTokenAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - return GenerateUserToken("Confirmation", userId, cancellationToken); + return GenerateUserTokenAsync("Confirmation", user, cancellationToken); } /// /// Confirm the user with confirmation token /// - /// + /// /// /// /// - public virtual async Task ConfirmEmail(string userId, string token, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task ConfirmEmailAsync(TUser user, string token, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetEmailStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - if (!await VerifyUserToken(userId, "Confirmation", token, cancellationToken)) + if (!await VerifyUserTokenAsync(user, "Confirmation", token, cancellationToken)) { return IdentityResult.Failed(Resources.InvalidToken); } - await store.SetEmailConfirmed(user, true, cancellationToken); - return await Update(user, cancellationToken); + await store.SetEmailConfirmedAsync(user, true, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Returns true if the user's email has been confirmed /// - /// + /// /// /// - public virtual async Task IsEmailConfirmed(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task IsEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetEmailStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetEmailConfirmed(user, cancellationToken); + return await store.GetEmailConfirmedAsync(user, cancellationToken); } // IUserPhoneNumberStore methods @@ -1163,112 +1144,104 @@ namespace Microsoft.AspNet.Identity /// /// Get a user's phoneNumber /// - /// + /// /// /// - public virtual async Task GetPhoneNumber(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetPhoneNumberStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetPhoneNumber(user, cancellationToken); + return await store.GetPhoneNumberAsync(user, cancellationToken); } /// /// Set a user's phoneNumber /// - /// + /// /// /// /// - public virtual async Task SetPhoneNumber(string userId, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetPhoneNumberStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await store.SetPhoneNumber(user, phoneNumber, cancellationToken); - await store.SetPhoneNumberConfirmed(user, false, cancellationToken); + await store.SetPhoneNumberAsync(user, phoneNumber, cancellationToken); + await store.SetPhoneNumberConfirmedAsync(user, false, cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Set a user's phoneNumber with the verification token /// - /// + /// /// /// /// /// - public virtual async Task ChangePhoneNumber(string userId, string phoneNumber, string token, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task ChangePhoneNumberAsync(TUser user, string phoneNumber, string token, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetPhoneNumberStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - if (!await VerifyChangePhoneNumberToken(userId, token, phoneNumber)) + if (!await VerifyChangePhoneNumberTokenAsync(user, token, phoneNumber)) { return IdentityResult.Failed(Resources.InvalidToken); } - await store.SetPhoneNumber(user, phoneNumber, cancellationToken); - await store.SetPhoneNumberConfirmed(user, true, cancellationToken); + await store.SetPhoneNumberAsync(user, phoneNumber, cancellationToken); + await store.SetPhoneNumberConfirmedAsync(user, true, cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Returns true if the user's phone number has been confirmed /// - /// + /// /// /// - public virtual async Task IsPhoneNumberConfirmed(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task IsPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetPhoneNumberStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetPhoneNumberConfirmed(user, cancellationToken); + return await store.GetPhoneNumberConfirmedAsync(user, cancellationToken); } // Two factor APIS #if NET45 - internal async Task CreateSecurityToken(string userId) + internal async Task CreateSecurityToken(TUser user) { return - new SecurityToken(Encoding.Unicode.GetBytes(await GetSecurityStamp(userId))); + new SecurityToken(Encoding.Unicode.GetBytes(await GetSecurityStampAsync(user))); } /// /// Get a phone number code for a user and phone number /// - /// + /// /// /// - public virtual async Task GenerateChangePhoneNumberToken(string userId, string phoneNumber) + public virtual async Task GenerateChangePhoneNumberToken(TUser user, string phoneNumber) { ThrowIfDisposed(); return - Rfc6238AuthenticationService.GenerateCode(await CreateSecurityToken(userId), phoneNumber) + Rfc6238AuthenticationService.GenerateCode(await CreateSecurityToken(user), phoneNumber) .ToString(CultureInfo.InvariantCulture); } #endif @@ -1276,15 +1249,15 @@ namespace Microsoft.AspNet.Identity /// /// Verify a phone number code for a specific user and phone number /// - /// + /// /// /// /// - public virtual async Task VerifyChangePhoneNumberToken(string userId, string token, string phoneNumber) + public virtual async Task VerifyChangePhoneNumberTokenAsync(TUser user, string token, string phoneNumber) { ThrowIfDisposed(); #if NET45 - var securityToken = await CreateSecurityToken(userId); + var securityToken = await CreateSecurityToken(user); int code; if (securityToken != null && Int32.TryParse(token, out code)) { @@ -1297,49 +1270,45 @@ namespace Microsoft.AspNet.Identity /// /// Verify a user token with the specified purpose /// - /// + /// /// /// /// /// - public virtual async Task VerifyUserToken(string userId, string purpose, string token, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task VerifyUserTokenAsync(TUser user, string purpose, string token, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (UserTokenProvider == null) { throw new NotSupportedException(Resources.NoTokenProvider); } - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } // Make sure the token is valid - return await UserTokenProvider.Validate(purpose, token, this, user, cancellationToken); + return await UserTokenProvider.ValidateAsync(purpose, token, this, user, cancellationToken); } /// /// Get a user token for a specific purpose /// /// - /// + /// /// /// - public virtual async Task GenerateUserToken(string purpose, string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GenerateUserTokenAsync(string purpose, TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); if (UserTokenProvider == null) { throw new NotSupportedException(Resources.NoTokenProvider); } - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await UserTokenProvider.Generate(purpose, this, user, cancellationToken); + return await UserTokenProvider.GenerateAsync(purpose, this, user, cancellationToken); } /// @@ -1364,22 +1333,20 @@ namespace Microsoft.AspNet.Identity /// /// Returns a list of valid two factor providers for a user /// - /// + /// /// /// - public virtual async Task> GetValidTwoFactorProviders(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task> GetValidTwoFactorProviders(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } var results = new List(); foreach (var f in TwoFactorProviders) { - if (await f.Value.IsValidProviderForUser(this, user, cancellationToken)) + if (await f.Value.IsValidProviderForUserAsync(this, user, cancellationToken)) { results.Add(f.Key); } @@ -1390,19 +1357,17 @@ namespace Microsoft.AspNet.Identity /// /// Verify a user token with the specified provider /// - /// + /// /// /// /// /// - public virtual async Task VerifyTwoFactorToken(string userId, string twoFactorProvider, string token, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task VerifyTwoFactorTokenAsync(TUser user, string twoFactorProvider, string token, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } if (!_factors.ContainsKey(twoFactorProvider)) { @@ -1411,57 +1376,53 @@ namespace Microsoft.AspNet.Identity } // Make sure the token is valid var provider = _factors[twoFactorProvider]; - return await provider.Validate(twoFactorProvider, token, this, user, cancellationToken); + return await provider.ValidateAsync(twoFactorProvider, token, this, user, cancellationToken); } /// /// Get a user token for a specific user factor provider /// - /// + /// /// /// /// - public virtual async Task GenerateTwoFactorToken(string userId, string twoFactorProvider, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GenerateTwoFactorTokenAsync(TUser user, string twoFactorProvider, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } if (!_factors.ContainsKey(twoFactorProvider)) { throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Resources.NoTwoFactorProvider, twoFactorProvider)); } - return await _factors[twoFactorProvider].Generate(twoFactorProvider, this, user, cancellationToken); + return await _factors[twoFactorProvider].GenerateAsync(twoFactorProvider, this, user, cancellationToken); } /// /// Notify a user with a token from a specific user factor provider /// - /// + /// /// /// /// /// - public virtual async Task NotifyTwoFactorToken(string userId, string twoFactorProvider, + public virtual async Task NotifyTwoFactorTokenAsync(TUser user, string twoFactorProvider, string token, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } if (!_factors.ContainsKey(twoFactorProvider)) { throw new NotSupportedException(String.Format(CultureInfo.CurrentCulture, Resources.NoTwoFactorProvider, twoFactorProvider)); } - await _factors[twoFactorProvider].Notify(token, this, user, cancellationToken); + await _factors[twoFactorProvider].NotifyAsync(token, this, user, cancellationToken); return IdentityResult.Success; } @@ -1479,87 +1440,91 @@ namespace Microsoft.AspNet.Identity /// /// Get a user's two factor provider /// - /// + /// /// /// - public virtual async Task GetTwoFactorEnabled(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserTwoFactorStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetTwoFactorEnabled(user, cancellationToken); + return await store.GetTwoFactorEnabledAsync(user, cancellationToken); } /// /// Set whether a user has two factor enabled or not /// - /// + /// /// /// /// - public virtual async Task SetTwoFactorEnabled(string userId, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserTwoFactorStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await store.SetTwoFactorEnabled(user, enabled, cancellationToken); + await store.SetTwoFactorEnabledAsync(user, enabled, cancellationToken); await UpdateSecurityStampInternal(user, cancellationToken); - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } // SMS/Email methods /// - /// Send an email to the user + /// SendAsync an email to the user /// - /// + /// /// /// /// /// - public virtual async Task SendEmail(string userId, string subject, string body, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SendEmail(TUser user, string subject, string body, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } if (EmailService != null) { var msg = new IdentityMessage { - Destination = await GetEmail(userId, cancellationToken), + Destination = await GetEmailAsync(user, cancellationToken), Subject = subject, Body = body, }; - await EmailService.Send(msg, cancellationToken); + await EmailService.SendAsync(msg, cancellationToken); } } /// - /// Send a user a sms message + /// SendAsync a user a sms message /// - /// + /// /// /// /// - public virtual async Task SendSms(string userId, string message, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SendSms(TUser user, string message, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); + if (user == null) + { + throw new ArgumentNullException("user"); + } if (SmsService != null) { var msg = new IdentityMessage { - Destination = await GetPhoneNumber(userId, cancellationToken), + Destination = await GetPhoneNumberAsync(user, cancellationToken), Body = message }; - await SmsService.Send(msg, cancellationToken); + await SmsService.SendAsync(msg, cancellationToken); } } @@ -1577,107 +1542,97 @@ namespace Microsoft.AspNet.Identity /// /// Returns true if the user is locked out /// - /// + /// /// /// - public virtual async Task IsLockedOut(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task IsLockedOutAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - if (!await store.GetLockoutEnabled(user, cancellationToken)) + if (!await store.GetLockoutEnabledAsync(user, cancellationToken)) { return false; } - var lockoutTime = await store.GetLockoutEndDate(user, cancellationToken).ConfigureAwait((false)); + var lockoutTime = await store.GetLockoutEndDateAsync(user, cancellationToken).ConfigureAwait((false)); return lockoutTime >= DateTimeOffset.UtcNow; } /// /// Sets whether the user allows lockout /// - /// + /// /// /// - public virtual async Task SetLockoutEnabled(string userId, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await store.SetLockoutEnabled(user, enabled, cancellationToken); - return await Update(user, cancellationToken); + await store.SetLockoutEnabledAsync(user, enabled, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Returns whether the user allows lockout /// - /// + /// /// - public virtual async Task GetLockoutEnabled(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetLockoutEnabled(user, cancellationToken); + return await store.GetLockoutEnabledAsync(user, cancellationToken); } /// /// Returns the user lockout end date /// - /// + /// /// /// - public virtual async Task GetLockoutEndDate(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetLockoutEndDate(user); + return await store.GetLockoutEndDateAsync(user); } /// /// Sets the user lockout end date /// - /// + /// /// /// /// - public virtual async Task SetLockoutEndDate(string userId, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - if (!await store.GetLockoutEnabled(user, cancellationToken).ConfigureAwait((false))) + if (!await store.GetLockoutEnabledAsync(user, cancellationToken).ConfigureAwait((false))) { return IdentityResult.Failed(Resources.LockoutNotEnabled); } - await store.SetLockoutEndDate(user, lockoutEnd, cancellationToken); - return await Update(user, cancellationToken); + await store.SetLockoutEndDateAsync(user, lockoutEnd, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// @@ -1685,67 +1640,61 @@ namespace Microsoft.AspNet.Identity /// to the MaxFailedAccessAttempsBeforeLockout, the user will be locked out for the next DefaultAccountLockoutTimeSpan /// and the AccessFailedCount will be reset to 0. /// - /// + /// /// /// - public virtual async Task AccessFailed(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task AccessFailedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } // If this puts the user over the threshold for lockout, lock them out and reset the access failed count - var count = await store.IncrementAccessFailedCount(user, cancellationToken); + var count = await store.IncrementAccessFailedCountAsync(user, cancellationToken); if (count < MaxFailedAccessAttemptsBeforeLockout) { - return await Update(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } await - store.SetLockoutEndDate(user, DateTimeOffset.UtcNow.Add(DefaultAccountLockoutTimeSpan), cancellationToken); - await store.ResetAccessFailedCount(user, cancellationToken); - return await Update(user, cancellationToken); + store.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow.Add(DefaultAccountLockoutTimeSpan), cancellationToken); + await store.ResetAccessFailedCountAsync(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Resets the access failed count for the user to 0 /// - /// + /// /// /// - public virtual async Task ResetAccessFailedCount(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - await store.ResetAccessFailedCount(user); - return await Update(user, cancellationToken); + await store.ResetAccessFailedCountAsync(user, cancellationToken); + return await UpdateAsync(user, cancellationToken); } /// /// Returns the number of failed access attempts for the user /// - /// + /// /// - public virtual async Task GetAccessFailedCount(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); var store = GetUserLockoutStore(); - var user = await FindById(userId, cancellationToken); if (user == null) { - throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound, - userId)); + throw new ArgumentNullException("user"); } - return await store.GetAccessFailedCount(user, cancellationToken); + return await store.GetAccessFailedCountAsync(user, cancellationToken); } private void ThrowIfDisposed() diff --git a/src/Microsoft.AspNet.Identity/UserValidator.cs b/src/Microsoft.AspNet.Identity/UserValidator.cs index 70eaf6d055..3a2bbb64d1 100644 --- a/src/Microsoft.AspNet.Identity/UserValidator.cs +++ b/src/Microsoft.AspNet.Identity/UserValidator.cs @@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity /// /// /// - public virtual async Task Validate(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task ValidateAsync(UserManager manager, TUser user, CancellationToken cancellationToken = default(CancellationToken)) { if (manager == null) { @@ -104,7 +104,7 @@ namespace Microsoft.AspNet.Identity private async Task ValidateUserName(UserManager manager, TUser user, ICollection errors) { - var userName = await manager.GetUserName(user); + var userName = await manager.GetUserNameAsync(user); if (string.IsNullOrWhiteSpace(userName)) { errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "UserName")); @@ -116,8 +116,8 @@ namespace Microsoft.AspNet.Identity } else { - var owner = await manager.FindByName(userName); - if (owner != null && !string.Equals(await manager.GetUserId(owner), await manager.GetUserId(user))) + var owner = await manager.FindByNameAsync(userName); + if (owner != null && !string.Equals(await manager.GetUserIdAsync(owner), await manager.GetUserIdAsync(user))) { errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, userName)); } @@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Identity // make sure email is not empty, valid, and unique private static async Task ValidateEmail(UserManager manager, TUser user, List errors) { - var email = await manager.GetEmailStore().GetEmail(user); + var email = await manager.GetEmailAsync(user); if (string.IsNullOrWhiteSpace(email)) { errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Email")); @@ -144,8 +144,8 @@ namespace Microsoft.AspNet.Identity return; } #endif - var owner = await manager.FindByEmail(email); - if (owner != null && !string.Equals(await manager.GetUserId(owner), await manager.GetUserId(user))) + var owner = await manager.FindByEmailAsync(email); + if (owner != null && !string.Equals(await manager.GetUserIdAsync(owner), await manager.GetUserIdAsync(user))) { errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateEmail, email)); } diff --git a/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs b/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs index e862296872..d921752c1a 100644 --- a/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs +++ b/test/Microsoft.AspNet.Identity.Entity.Test/UserStoreTest.cs @@ -109,23 +109,23 @@ // public async Task CanDeleteUser() // { // var manager = CreateManager(); -// var user = new IdentityUser("Delete"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsSuccess(await manager.Delete(user)); -// Assert.Null(await manager.FindById(user.Id)); +// var user = new IdentityUser("DeleteAsync"); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await manager.DeleteAsync(user)); +// Assert.Null(await manager.FindByIdAsync(user.Id)); // } // //[Fact] // //public async Task CanUpdateUserName() // //{ // // var manager = CreateManager(); -// // var user = new IdentityUser("Update"); -// // IdentityResultAssert.IsSuccess(await manager.Create(user)); -// // Assert.Null(await manager.FindByName("New")); +// // var user = new IdentityUser("UpdateAsync"); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// // Assert.Null(await manager.FindByNameAsync("New")); // // user.UserName = "New"; -// // IdentityResultAssert.IsSuccess(await manager.Update(user)); -// // Assert.NotNull(await manager.FindByName("New")); -// // Assert.Null(await manager.FindByName("Update")); +// // IdentityResultAssert.IsSuccess(await manager.UpdateAsync(user)); +// // Assert.NotNull(await manager.FindByNameAsync("New")); +// // Assert.Null(await manager.FindByNameAsync("UpdateAsync")); // //} // [Fact] @@ -134,7 +134,7 @@ // var manager = CreateManager(); // var user = new IdentityUser("CreateBlocked"); // manager.UserValidator = new AlwaysBadValidator(); -// IdentityResultAssert.IsFailure(await manager.Create(user), AlwaysBadValidator.ErrorMessage); +// IdentityResultAssert.IsFailure(await manager.CreateAsync(user), AlwaysBadValidator.ErrorMessage); // } // //[Fact] @@ -142,9 +142,9 @@ // //{ // // var manager = CreateManager(); // // var user = new IdentityUser("UpdateBlocked"); -// // IdentityResultAssert.IsSuccess(await manager.Create(user)); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // // manager.UserValidator = new AlwaysBadValidator(); -// // IdentityResultAssert.IsFailure(await manager.Update(user), AlwaysBadValidator.ErrorMessage); +// // IdentityResultAssert.IsFailure(await manager.UpdateAsync(user), AlwaysBadValidator.ErrorMessage); // //} // // [Theory] @@ -155,7 +155,7 @@ // // var manager = CreateManager(); // // var user = new IdentityUser("UpdateBlocked") {Email = email}; // // manager.UserValidator = new UserValidator {RequireUniqueEmail = true}; -// // IdentityResultAssert.IsFailure(await manager.Create(user), "Email cannot be null or empty."); +// // IdentityResultAssert.IsFailure(await manager.CreateAsync(user), "Email cannot be null or empty."); // // } // //#if NET45 @@ -167,7 +167,7 @@ // // var manager = CreateManager(); // // var user = new IdentityUser("UpdateBlocked") {Email = email}; // // manager.UserValidator = new UserValidator {RequireUniqueEmail = true}; -// // IdentityResultAssert.IsFailure(await manager.Create(user), "Email '" + email + "' is invalid."); +// // IdentityResultAssert.IsFailure(await manager.CreateAsync(user), "Email '" + email + "' is invalid."); // // } // //#endif @@ -176,9 +176,9 @@ // // { // // var manager = CreateManager(); // // var user = new IdentityUser("AddPasswordBlocked"); -// // IdentityResultAssert.IsSuccess(await manager.Create(user)); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // // manager.PasswordValidator = new AlwaysBadValidator(); -// // IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), +// // IdentityResultAssert.IsFailure(await manager.AddPasswordAsync(user.Id, "password"), // // AlwaysBadValidator.ErrorMessage); // // } @@ -187,9 +187,9 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("ChangePasswordBlocked"); -// IdentityResultAssert.IsSuccess(await manager.Create(user, "password")); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "password")); // manager.PasswordValidator = new AlwaysBadValidator(); -// IdentityResultAssert.IsFailure(await manager.ChangePassword(user.Id, "password", "new"), +// IdentityResultAssert.IsFailure(await manager.ChangePasswordAsync(user.Id, "password", "new"), // AlwaysBadValidator.ErrorMessage); // } @@ -197,11 +197,11 @@ // public async Task CanCreateUserNoPassword() // { // var manager = CreateManager(); -// IdentityResultAssert.IsSuccess(await manager.Create(new IdentityUser("CreateUserTest"))); -// var user = await manager.FindByName("CreateUserTest"); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(new IdentityUser("CreateUserTest"))); +// var user = await manager.FindByNameAsync("CreateUserTest"); // Assert.NotNull(user); // Assert.Null(user.PasswordHash); -// var logins = await manager.GetLogins(user.Id); +// var logins = await manager.GetLoginsAsync(user.Id); // Assert.NotNull(logins); // Assert.Equal(0, logins.Count()); // } @@ -213,12 +213,12 @@ // const string userName = "CreateExternalUserTest"; // const string provider = "ZzAuth"; // const string providerKey = "HaoKey"; -// IdentityResultAssert.IsSuccess(await manager.Create(new IdentityUser(userName))); -// var user = await manager.FindByName(userName); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(new IdentityUser(userName))); +// var user = await manager.FindByNameAsync(userName); // Assert.NotNull(user); // var login = new UserLoginInfo(provider, providerKey); -// IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); -// var logins = await manager.GetLogins(user.Id); +// IdentityResultAssert.IsSuccess(await manager.AddLoginAsync(user.Id, login)); +// var logins = await manager.GetLoginsAsync(user.Id); // Assert.NotNull(logins); // Assert.Equal(1, logins.Count()); // Assert.Equal(provider, logins.First().LoginProvider); @@ -231,16 +231,16 @@ // var manager = CreateManager(); // var login = new UserLoginInfo("Provider", "key"); // var user = new IdentityUser("CreateUserLoginAddPasswordTest"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); -// Assert.False(await manager.HasPassword(user.Id)); -// IdentityResultAssert.IsSuccess(await manager.AddPassword(user.Id, "password")); -// Assert.True(await manager.HasPassword(user.Id)); -// var logins = await manager.GetLogins(user.Id); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await manager.AddLoginAsync(user.Id, login)); +// Assert.False(await manager.HasPasswordAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.AddPasswordAsync(user.Id, "password")); +// Assert.True(await manager.HasPasswordAsync(user.Id)); +// var logins = await manager.GetLoginsAsync(user.Id); // Assert.NotNull(logins); // Assert.Equal(1, logins.Count()); -// Assert.Equal(user, await manager.Find(login)); -// Assert.Equal(user, await manager.Find(user.UserName, "password")); +// Assert.Equal(user, await manager.FindByLoginAsync(login)); +// Assert.Equal(user, await manager.FindByLoginAsync(user.UserName, "password")); // } // [Fact] @@ -248,9 +248,9 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("CannotAddAnotherPassword"); -// IdentityResultAssert.IsSuccess(await manager.Create(user, "Password")); -// Assert.True(await manager.HasPassword(user.Id)); -// IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "Password")); +// Assert.True(await manager.HasPasswordAsync(user.Id)); +// IdentityResultAssert.IsFailure(await manager.AddPasswordAsync(user.Id, "password"), // "User already has a password set."); // } @@ -260,20 +260,20 @@ // var manager = CreateManager(); // var user = new IdentityUser("CreateUserAddRemoveLoginTest"); // var login = new UserLoginInfo("Provider", "key"); -// var result = await manager.Create(user); +// var result = await manager.CreateAsync(user); // Assert.NotNull(user); // IdentityResultAssert.IsSuccess(result); -// IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); -// Assert.Equal(user, await manager.Find(login)); -// var logins = await manager.GetLogins(user.Id); +// IdentityResultAssert.IsSuccess(await manager.AddLoginAsync(user.Id, login)); +// Assert.Equal(user, await manager.FindByLoginAsync(login)); +// var logins = await manager.GetLoginsAsync(user.Id); // Assert.NotNull(logins); // Assert.Equal(1, logins.Count()); // Assert.Equal(login.LoginProvider, logins.Last().LoginProvider); // Assert.Equal(login.ProviderKey, logins.Last().ProviderKey); // var stamp = user.SecurityStamp; -// IdentityResultAssert.IsSuccess(await manager.RemoveLogin(user.Id, login)); -// Assert.Null(await manager.Find(login)); -// logins = await manager.GetLogins(user.Id); +// IdentityResultAssert.IsSuccess(await manager.RemoveLoginAsync(user.Id, login)); +// Assert.Null(await manager.FindByLoginAsync(login)); +// logins = await manager.GetLoginsAsync(user.Id); // Assert.NotNull(logins); // Assert.Equal(0, logins.Count()); // Assert.NotEqual(stamp, user.SecurityStamp); @@ -285,10 +285,10 @@ // var manager = CreateManager(); // var user = new IdentityUser("RemovePasswordTest"); // const string password = "password"; -// IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // var stamp = user.SecurityStamp; -// IdentityResultAssert.IsSuccess(await manager.RemovePassword(user.Id)); -// var u = await manager.FindByName(user.UserName); +// IdentityResultAssert.IsSuccess(await manager.RemovePasswordAsync(user.Id)); +// var u = await manager.FindByNameAsync(user.UserName); // Assert.NotNull(u); // Assert.Null(u.PasswordHash); // Assert.NotEqual(stamp, user.SecurityStamp); @@ -301,13 +301,13 @@ // var user = new IdentityUser("ChangePasswordTest"); // const string password = "password"; // const string newPassword = "newpassword"; -// IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // Assert.Equal(manager.Users.Count(), 1); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// IdentityResultAssert.IsSuccess(await manager.ChangePassword(user.Id, password, newPassword)); -// Assert.Null(await manager.Find(user.UserName, password)); -// Assert.Equal(user, await manager.Find(user.UserName, newPassword)); +// IdentityResultAssert.IsSuccess(await manager.ChangePasswordAsync(user.Id, password, newPassword)); +// Assert.Null(await manager.FindByLoginAsync(user.UserName, password)); +// Assert.Equal(user, await manager.FindByLoginAsync(user.UserName, newPassword)); // Assert.NotEqual(stamp, user.SecurityStamp); // } @@ -316,22 +316,22 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("ClaimsAddRemove"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // Claim[] claims = { new Claim("c", "v"), new Claim("c2", "v2"), new Claim("c2", "v3") }; // foreach (var c in claims) // { -// IdentityResultAssert.IsSuccess(await manager.AddClaim(user.Id, c)); +// IdentityResultAssert.IsSuccess(await manager.AddClaimAsync(user.Id, c)); // } -// var userClaims = await manager.GetClaims(user.Id); +// var userClaims = await manager.GetClaimsAsync(user.Id); // Assert.Equal(3, userClaims.Count); -// IdentityResultAssert.IsSuccess(await manager.RemoveClaim(user.Id, claims[0])); -// userClaims = await manager.GetClaims(user.Id); +// IdentityResultAssert.IsSuccess(await manager.RemoveClaimAsync(user.Id, claims[0])); +// userClaims = await manager.GetClaimsAsync(user.Id); // Assert.Equal(2, userClaims.Count); -// IdentityResultAssert.IsSuccess(await manager.RemoveClaim(user.Id, claims[1])); -// userClaims = await manager.GetClaims(user.Id); +// IdentityResultAssert.IsSuccess(await manager.RemoveClaimAsync(user.Id, claims[1])); +// userClaims = await manager.GetClaimsAsync(user.Id); // Assert.Equal(1, userClaims.Count); -// IdentityResultAssert.IsSuccess(await manager.RemoveClaim(user.Id, claims[2])); -// userClaims = await manager.GetClaims(user.Id); +// IdentityResultAssert.IsSuccess(await manager.RemoveClaimAsync(user.Id, claims[2])); +// userClaims = await manager.GetClaimsAsync(user.Id); // Assert.Equal(0, userClaims.Count); // } @@ -340,8 +340,8 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("user"); -// IdentityResultAssert.IsSuccess(await manager.Create(user, "password")); -// var result = await manager.ChangePassword(user.Id, "bogus", "newpassword"); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "password")); +// var result = await manager.ChangePasswordAsync(user.Id, "bogus", "newpassword"); // IdentityResultAssert.IsFailure(result, "Incorrect password."); // } @@ -351,8 +351,8 @@ // var manager = CreateManager(); // var user = new IdentityUser("dupe"); // var user2 = new IdentityUser("dupe"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsFailure(await manager.Create(user2), "Name dupe is already taken."); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsFailure(await manager.CreateAsync(user2), "Name dupe is already taken."); // } // [Fact] @@ -361,8 +361,8 @@ // var manager = CreateManager(); // var user = new IdentityUser("dupe") { Email = "yup@yup.com" }; // var user2 = new IdentityUser("dupeEmail") { Email = "yup@yup.com" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsSuccess(await manager.Create(user2)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user2)); // } // [Fact] @@ -372,8 +372,8 @@ // manager.UserValidator = new UserValidator { RequireUniqueEmail = true }; // var user = new IdentityUser("dupe") { Email = "yup@yup.com" }; // var user2 = new IdentityUser("dupeEmail") { Email = "yup@yup.com" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsFailure(await manager.Create(user2), "Email 'yup@yup.com' is already taken."); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsFailure(await manager.CreateAsync(user2), "Email 'yup@yup.com' is already taken."); // } // [Fact] @@ -382,10 +382,10 @@ // var manager = CreateManager(); // var user = new IdentityUser("stampMe"); // Assert.Null(user.SecurityStamp); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStamp(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStampAsync(user.Id)); // Assert.NotEqual(stamp, user.SecurityStamp); // } @@ -395,9 +395,9 @@ // var manager = CreateManager(); // var user = new IdentityUser("DupeLogin"); // var login = new UserLoginInfo("provder", "key"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); -// var result = await manager.AddLogin(user.Id, login); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await manager.AddLoginAsync(user.Id, login)); +// var result = await manager.AddLoginAsync(user.Id, login); // IdentityResultAssert.IsFailure(result, "A user with that external login already exists."); // } @@ -409,8 +409,8 @@ // const string userName = "EmailTest"; // const string email = "email@test.com"; // var user = new IdentityUser(userName) { Email = email }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// var fetch = await manager.FindByEmail(email); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// var fetch = await manager.FindByEmailAsync(email); // Assert.Equal(user, fetch); // } @@ -426,7 +426,7 @@ // }; // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await mgr.Create(u)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(u)); // } // var usersQ = mgr.Users; // Assert.Equal(3, usersQ.Count()); @@ -443,11 +443,11 @@ // var manager = CreateManager(context); // var role = CreateRoleManager(context); // var user = new IdentityUser("Hao"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsSuccess(await role.Create(new IdentityRole("Admin"))); -// IdentityResultAssert.IsSuccess(await role.Create(new IdentityRole("Local"))); -// IdentityResultAssert.IsSuccess(await manager.AddToRole(user.Id, "Admin")); -// IdentityResultAssert.IsSuccess(await manager.AddToRole(user.Id, "Local")); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await role.CreateAsync(new IdentityRole("Admin"))); +// IdentityResultAssert.IsSuccess(await role.CreateAsync(new IdentityRole("Local"))); +// IdentityResultAssert.IsSuccess(await manager.AddToRoleAsync(user.Id, "Admin")); +// IdentityResultAssert.IsSuccess(await manager.AddToRoleAsync(user.Id, "Local")); // Claim[] userClaims = // { // new Claim("Whatever", "Value"), @@ -455,7 +455,7 @@ // }; // foreach (var c in userClaims) // { -// IdentityResultAssert.IsSuccess(await manager.AddClaim(user.Id, c)); +// IdentityResultAssert.IsSuccess(await manager.AddClaimAsync(user.Id, c)); // } // var identity = await manager.CreateIdentity(user, "test"); @@ -479,31 +479,31 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("test"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// Assert.False(await manager.IsEmailConfirmed(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// Assert.False(await manager.IsEmailConfirmedAsync(user.Id)); // } // // TODO: No token provider implementations yet // private class StaticTokenProvider : IUserTokenProvider // { -// public Task Generate(string purpose, UserManager manager, +// public Task GenerateAsync(string purpose, UserManager manager, // IdentityUser user, CancellationToken token) // { // return Task.FromResult(MakeToken(purpose, user)); // } -// public Task Validate(string purpose, string token, UserManager manager, +// public Task ValidateAsync(string purpose, string token, UserManager manager, // IdentityUser user, CancellationToken cancellationToken) // { // return Task.FromResult(token == MakeToken(purpose, user)); // } -// public Task Notify(string token, UserManager manager, IdentityUser user, CancellationToken cancellationToken) +// public Task NotifyAsync(string token, UserManager manager, IdentityUser user, CancellationToken cancellationToken) // { // return Task.FromResult(0); // } -// public Task IsValidProviderForUser(UserManager manager, IdentityUser user, CancellationToken token) +// public Task IsValidProviderForUserAsync(UserManager manager, IdentityUser user, CancellationToken token) // { // return Task.FromResult(true); // } @@ -522,14 +522,14 @@ // var user = new IdentityUser("ResetPasswordTest"); // const string password = "password"; // const string newPassword = "newpassword"; -// IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// var token = await manager.GeneratePasswordResetToken(user.Id); +// var token = await manager.GeneratePasswordResetTokenAsync(user.Id); // Assert.NotNull(token); // IdentityResultAssert.IsSuccess(await manager.ResetPassword(user.Id, token, newPassword)); -// Assert.Null(await manager.Find(user.UserName, password)); -// Assert.Equal(user, await manager.Find(user.UserName, newPassword)); +// Assert.Null(await manager.FindByLoginAsync(user.UserName, password)); +// Assert.Equal(user, await manager.FindByLoginAsync(user.UserName, newPassword)); // Assert.NotEqual(stamp, user.SecurityStamp); // } @@ -541,16 +541,16 @@ // var user = new IdentityUser("ResetPasswordTest"); // const string password = "password"; // const string newPassword = "newpassword"; -// IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// var token = await manager.GeneratePasswordResetToken(user.Id); +// var token = await manager.GeneratePasswordResetTokenAsync(user.Id); // Assert.NotNull(token); // manager.PasswordValidator = new AlwaysBadValidator(); // IdentityResultAssert.IsFailure(await manager.ResetPassword(user.Id, token, newPassword), // AlwaysBadValidator.ErrorMessage); -// Assert.NotNull(await manager.Find(user.UserName, password)); -// Assert.Equal(user, await manager.Find(user.UserName, password)); +// Assert.NotNull(await manager.FindByLoginAsync(user.UserName, password)); +// Assert.Equal(user, await manager.FindByLoginAsync(user.UserName, password)); // Assert.Equal(stamp, user.SecurityStamp); // } @@ -562,12 +562,12 @@ // var user = new IdentityUser("ResetPasswordTest"); // const string password = "password"; // const string newPassword = "newpassword"; -// IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); // IdentityResultAssert.IsFailure(await manager.ResetPassword(user.Id, "bogus", newPassword), "Invalid token."); -// Assert.NotNull(await manager.Find(user.UserName, password)); -// Assert.Equal(user, await manager.Find(user.UserName, password)); +// Assert.NotNull(await manager.FindByLoginAsync(user.UserName, password)); +// Assert.Equal(user, await manager.FindByLoginAsync(user.UserName, password)); // Assert.Equal(stamp, user.SecurityStamp); // } @@ -578,13 +578,13 @@ // manager.UserTokenProvider = new StaticTokenProvider(); // var user = new IdentityUser("UserTokenTest"); // var user2 = new IdentityUser("UserTokenTest2"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsSuccess(await manager.Create(user2)); -// var token = await manager.GenerateUserToken("test", user.Id); -// Assert.True(await manager.VerifyUserToken(user.Id, "test", token)); -// Assert.False(await manager.VerifyUserToken(user.Id, "test2", token)); -// Assert.False(await manager.VerifyUserToken(user.Id, "test", token + "a")); -// Assert.False(await manager.VerifyUserToken(user2.Id, "test", token)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user2)); +// var token = await manager.GenerateUserTokenAsync("test", user.Id); +// Assert.True(await manager.VerifyUserTokenAsync(user.Id, "test", token)); +// Assert.False(await manager.VerifyUserTokenAsync(user.Id, "test2", token)); +// Assert.False(await manager.VerifyUserTokenAsync(user.Id, "test", token + "a")); +// Assert.False(await manager.VerifyUserTokenAsync(user2.Id, "test", token)); // } // [Fact] @@ -594,13 +594,13 @@ // manager.UserTokenProvider = new StaticTokenProvider(); // var user = new IdentityUser("test"); // Assert.False(user.EmailConfirmed); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// var token = await manager.GenerateEmailConfirmationToken(user.Id); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// var token = await manager.GenerateEmailConfirmationTokenAsync(user.Id); // Assert.NotNull(token); -// IdentityResultAssert.IsSuccess(await manager.ConfirmEmail(user.Id, token)); -// Assert.True(await manager.IsEmailConfirmed(user.Id)); -// IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, null)); -// Assert.False(await manager.IsEmailConfirmed(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.ConfirmEmailAsync(user.Id, token)); +// Assert.True(await manager.IsEmailConfirmedAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user.Id, null)); +// Assert.False(await manager.IsEmailConfirmedAsync(user.Id)); // } // [Fact] @@ -610,9 +610,9 @@ // manager.UserTokenProvider = new StaticTokenProvider(); // var user = new IdentityUser("test"); // Assert.False(user.EmailConfirmed); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// IdentityResultAssert.IsFailure(await manager.ConfirmEmail(user.Id, "bogus"), "Invalid token."); -// Assert.False(await manager.IsEmailConfirmed(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// IdentityResultAssert.IsFailure(await manager.ConfirmEmailAsync(user.Id, "bogus"), "Invalid token."); +// Assert.False(await manager.IsEmailConfirmedAsync(user.Id)); // } // // TODO: Can't reenable til we have a SecurityStamp linked token provider @@ -622,12 +622,12 @@ // // var manager = CreateManager(); // // var user = new IdentityUser("test"); // // Assert.False(user.EmailConfirmed); -// // IdentityResultAssert.IsSuccess(await manager.Create(user, "password")); -// // var token = await manager.GenerateEmailConfirmationToken(user.Id); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "password")); +// // var token = await manager.GenerateEmailConfirmationTokenAsync(user.Id); // // Assert.NotNull(token); -// // IdentityResultAssert.IsSuccess(await manager.ChangePassword(user.Id, "password", "newpassword")); -// // IdentityResultAssert.IsFailure(await manager.ConfirmEmail(user.Id, token), "Invalid token."); -// // Assert.False(await manager.IsEmailConfirmed(user.Id)); +// // IdentityResultAssert.IsSuccess(await manager.ChangePasswordAsync(user.Id, "password", "newpassword")); +// // IdentityResultAssert.IsFailure(await manager.ConfirmEmailAsync(user.Id, token), "Invalid token."); +// // Assert.False(await manager.IsEmailConfirmedAsync(user.Id)); // //} // // Lockout tests @@ -639,14 +639,14 @@ // mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1); // mgr.UserLockoutEnabledByDefault = true; // var user = new IdentityUser("fastLockout"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.True(await mgr.IsLockedOut(user.Id)); -// Assert.True(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.True(await mgr.IsLockedOutAsync(user.Id)); +// Assert.True(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user.Id)); // } // [Fact] @@ -657,18 +657,18 @@ // mgr.UserLockoutEnabledByDefault = true; // mgr.MaxFailedAccessAttemptsBeforeLockout = 2; // var user = new IdentityUser("twoFailureLockout"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.True(await mgr.IsLockedOut(user.Id)); -// Assert.True(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// Assert.False(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.True(await mgr.IsLockedOutAsync(user.Id)); +// Assert.True(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user.Id)); // } // [Fact] @@ -679,22 +679,22 @@ // mgr.UserLockoutEnabledByDefault = true; // mgr.MaxFailedAccessAttemptsBeforeLockout = 2; // var user = new IdentityUser("resetLockout"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.ResetAccessFailedCount(user.Id)); -// Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// Assert.False(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.ResetAccessFailedCountAsync(user.Id)); +// Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// Assert.False(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// Assert.False(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user.Id)); // } // [Fact] @@ -704,21 +704,21 @@ // mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1); // mgr.MaxFailedAccessAttemptsBeforeLockout = 2; // var user = new IdentityUser("manualLockout"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.False(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.False(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.False(user.LockoutEnabled); -// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEnabled(user.Id, true)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEnabledAsync(user.Id, true)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); -// IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); -// Assert.True(await mgr.IsLockedOut(user.Id)); -// Assert.True(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); -// Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// Assert.False(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user.Id)); +// Assert.True(await mgr.IsLockedOutAsync(user.Id)); +// Assert.True(await mgr.GetLockoutEndDateAsync(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); +// Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user.Id)); // } // [Fact] @@ -727,12 +727,12 @@ // var mgr = CreateManager(); // mgr.UserLockoutEnabledByDefault = true; // var user = new IdentityUser("LockoutTest"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user.Id, new DateTimeOffset())); -// Assert.False(await mgr.IsLockedOut(user.Id)); -// Assert.Equal(new DateTimeOffset(), await mgr.GetLockoutEndDate(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDateAsync(user.Id, new DateTimeOffset())); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); +// Assert.Equal(new DateTimeOffset(), await mgr.GetLockoutEndDateAsync(user.Id)); // Assert.Null(user.LockoutEndDateUtc); // } @@ -741,12 +741,12 @@ // { // var mgr = CreateManager(); // var user = new IdentityUser("LockoutNotEnabledTest"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.False(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.False(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.False(user.LockoutEnabled); -// IdentityResultAssert.IsFailure(await mgr.SetLockoutEndDate(user.Id, new DateTimeOffset()), +// IdentityResultAssert.IsFailure(await mgr.SetLockoutEndDateAsync(user.Id, new DateTimeOffset()), // "Lockout is not enabled for this user."); -// Assert.False(await mgr.IsLockedOut(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); // } // [Fact] @@ -755,10 +755,10 @@ // var mgr = CreateManager(); // mgr.UserLockoutEnabledByDefault = true; // var user = new IdentityUser("LockoutUtcNowTest") { LockoutEndDateUtc = DateTime.UtcNow.AddSeconds(-1) }; -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// Assert.False(await mgr.IsLockedOut(user.Id)); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); // } // [Fact] @@ -767,11 +767,11 @@ // var mgr = CreateManager(); // mgr.UserLockoutEnabledByDefault = true; // var user = new IdentityUser("LockoutUtcNowTest"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user.Id, DateTimeOffset.UtcNow.AddSeconds(-1))); -// Assert.False(await mgr.IsLockedOut(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDateAsync(user.Id, DateTimeOffset.UtcNow.AddSeconds(-1))); +// Assert.False(await mgr.IsLockedOutAsync(user.Id)); // } // [Fact] @@ -780,10 +780,10 @@ // var mgr = CreateManager(); // mgr.UserLockoutEnabledByDefault = true; // var user = new IdentityUser("LockoutUtcNowTest") { LockoutEndDateUtc = DateTime.UtcNow.AddMinutes(5) }; -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); -// Assert.True(await mgr.IsLockedOut(user.Id)); +// Assert.True(await mgr.IsLockedOutAsync(user.Id)); // } // [Fact] @@ -792,13 +792,13 @@ // var mgr = CreateManager(); // mgr.UserLockoutEnabledByDefault = true; // var user = new IdentityUser("LockoutTest"); -// IdentityResultAssert.IsSuccess(await mgr.Create(user)); -// Assert.True(await mgr.GetLockoutEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); +// Assert.True(await mgr.GetLockoutEnabledAsync(user.Id)); // Assert.True(user.LockoutEnabled); // var lockoutEnd = new DateTimeOffset(DateTime.Now.AddMinutes(30).ToLocalTime()); -// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user.Id, lockoutEnd)); -// Assert.True(await mgr.IsLockedOut(user.Id)); -// var end = await mgr.GetLockoutEndDate(user.Id); +// IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDateAsync(user.Id, lockoutEnd)); +// Assert.True(await mgr.IsLockedOutAsync(user.Id)); +// var end = await mgr.GetLockoutEndDateAsync(user.Id); // Assert.Equal(lockoutEnd, end); // } @@ -808,9 +808,9 @@ // { // var manager = CreateRoleManager(); // var role = new IdentityRole("create"); -// Assert.False(await manager.RoleExists(role.Name)); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); -// Assert.True(await manager.RoleExists(role.Name)); +// Assert.False(await manager.RoleExistsAsync(role.Name)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); +// Assert.True(await manager.RoleExistsAsync(role.Name)); // } // private class AlwaysBadValidator : IUserValidator, IRoleValidator, @@ -818,17 +818,17 @@ // { // public const string ErrorMessage = "I'm Bad."; -// public Task Validate(string password, CancellationToken token) +// public Task ValidateAsync(string password, CancellationToken token) // { // return Task.FromResult(IdentityResult.Failed(ErrorMessage)); // } -// public Task Validate(RoleManager manager, IdentityRole role, CancellationToken token) +// public Task ValidateAsync(RoleManager manager, IdentityRole role, CancellationToken token) // { // return Task.FromResult(IdentityResult.Failed(ErrorMessage)); // } -// public Task Validate(UserManager manager, IdentityUser user, CancellationToken token) +// public Task ValidateAsync(UserManager manager, IdentityUser user, CancellationToken token) // { // return Task.FromResult(IdentityResult.Failed(ErrorMessage)); // } @@ -839,7 +839,7 @@ // { // var manager = CreateRoleManager(); // manager.RoleValidator = new AlwaysBadValidator(); -// IdentityResultAssert.IsFailure(await manager.Create(new IdentityRole("blocked")), +// IdentityResultAssert.IsFailure(await manager.CreateAsync(new IdentityRole("blocked")), // AlwaysBadValidator.ErrorMessage); // } @@ -848,10 +848,10 @@ // { // var manager = CreateRoleManager(); // var role = new IdentityRole("poorguy"); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); // var error = AlwaysBadValidator.ErrorMessage; // manager.RoleValidator = new AlwaysBadValidator(); -// IdentityResultAssert.IsFailure(await manager.Update(role), error); +// IdentityResultAssert.IsFailure(await manager.UpdateAsync(role), error); // } // [Fact] @@ -859,31 +859,31 @@ // { // var manager = CreateRoleManager(); // var role = new IdentityRole("delete"); -// Assert.False(await manager.RoleExists(role.Name)); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); -// IdentityResultAssert.IsSuccess(await manager.Delete(role)); -// Assert.False(await manager.RoleExists(role.Name)); +// Assert.False(await manager.RoleExistsAsync(role.Name)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); +// IdentityResultAssert.IsSuccess(await manager.DeleteAsync(role)); +// Assert.False(await manager.RoleExistsAsync(role.Name)); // } // [Fact] // public async Task CanRoleFindByIdTest() // { // var manager = CreateRoleManager(); -// var role = new IdentityRole("FindById"); -// Assert.Null(await manager.FindById(role.Id)); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); -// Assert.Equal(role, await manager.FindById(role.Id)); +// var role = new IdentityRole("FindByIdAsync"); +// Assert.Null(await manager.FindByIdAsync(role.Id)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); +// Assert.Equal(role, await manager.FindByIdAsync(role.Id)); // } // [Fact] // public async Task CanRoleFindByName() // { // var manager = CreateRoleManager(); -// var role = new IdentityRole("FindByName"); -// Assert.Null(await manager.FindByName(role.Name)); -// Assert.False(await manager.RoleExists(role.Name)); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); -// Assert.Equal(role, await manager.FindByName(role.Name)); +// var role = new IdentityRole("FindByNameAsync"); +// Assert.Null(await manager.FindByNameAsync(role.Name)); +// Assert.False(await manager.RoleExistsAsync(role.Name)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); +// Assert.Equal(role, await manager.FindByNameAsync(role.Name)); // } // [Fact] @@ -891,13 +891,13 @@ // { // var manager = CreateRoleManager(); // var role = new IdentityRole("update"); -// Assert.False(await manager.RoleExists(role.Name)); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); -// Assert.True(await manager.RoleExists(role.Name)); +// Assert.False(await manager.RoleExistsAsync(role.Name)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); +// Assert.True(await manager.RoleExistsAsync(role.Name)); // role.Name = "Changed"; -// IdentityResultAssert.IsSuccess(await manager.Update(role)); -// Assert.False(await manager.RoleExists("update")); -// Assert.Equal(role, await manager.FindByName(role.Name)); +// IdentityResultAssert.IsSuccess(await manager.UpdateAsync(role)); +// Assert.False(await manager.RoleExistsAsync("update")); +// Assert.Equal(role, await manager.FindByNameAsync(role.Name)); // } // [Fact] @@ -911,7 +911,7 @@ // }; // foreach (var r in roles) // { -// IdentityResultAssert.IsSuccess(await manager.Create(r)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(r)); // } // Assert.Equal(roles.Length, manager.Roles.Count()); // var r1 = manager.Roles.FirstOrDefault(r => r.Name == "r1"); @@ -925,16 +925,16 @@ // // var userMgr = CreateManager(); // // var roleMgr = CreateRoleManager(); // // var role = new IdentityRole("deleteNonEmpty"); -// // Assert.False(await roleMgr.RoleExists(role.Name)); -// // IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); +// // Assert.False(await roleMgr.RoleExistsAsync(role.Name)); +// // IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); // // var user = new IdentityUser("t"); -// // IdentityResultAssert.IsSuccess(await userMgr.Create(user)); -// // IdentityResultAssert.IsSuccess(await userMgr.AddToRole(user.Id, role.Name)); -// // IdentityResultAssert.IsSuccess(await roleMgr.Delete(role)); -// // Assert.Null(await roleMgr.FindByName(role.Name)); -// // Assert.False(await roleMgr.RoleExists(role.Name)); +// // IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); +// // IdentityResultAssert.IsSuccess(await userMgr.AddToRoleAsync(user.Id, role.Name)); +// // IdentityResultAssert.IsSuccess(await roleMgr.DeleteAsync(role)); +// // Assert.Null(await roleMgr.FindByNameAsync(role.Name)); +// // Assert.False(await roleMgr.RoleExistsAsync(role.Name)); // // // REVIEW: We should throw if deleteing a non empty role? -// // var roles = await userMgr.GetRoles(user.Id); +// // var roles = await userMgr.GetRolesAsync(user.Id); // // // In memory this doesn't work since there's no concept of cascading deletes // // //Assert.Equal(0, roles.Count()); @@ -947,13 +947,13 @@ // //// var userMgr = CreateManager(); // //// var roleMgr = CreateRoleManager(); // //// var role = new IdentityRole("deleteNonEmpty"); -// //// Assert.False(await roleMgr.RoleExists(role.Name)); -// //// IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); +// //// Assert.False(await roleMgr.RoleExistsAsync(role.Name)); +// //// IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); // //// var user = new IdentityUser("t"); -// //// IdentityResultAssert.IsSuccess(await userMgr.Create(user)); -// //// IdentityResultAssert.IsSuccess(await userMgr.AddToRole(user.Id, role.Name)); -// //// IdentityResultAssert.IsSuccess(await userMgr.Delete(user)); -// //// role = roleMgr.FindById(role.Id); +// //// IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); +// //// IdentityResultAssert.IsSuccess(await userMgr.AddToRoleAsync(user.Id, role.Name)); +// //// IdentityResultAssert.IsSuccess(await userMgr.DeleteAsync(user)); +// //// role = roleMgr.FindByIdAsync(role.Id); // ////} // [Fact] @@ -961,11 +961,11 @@ // { // var manager = CreateRoleManager(); // var role = new IdentityRole("dupeRole"); -// Assert.False(await manager.RoleExists(role.Name)); -// IdentityResultAssert.IsSuccess(await manager.Create(role)); -// Assert.True(await manager.RoleExists(role.Name)); +// Assert.False(await manager.RoleExistsAsync(role.Name)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); +// Assert.True(await manager.RoleExistsAsync(role.Name)); // var role2 = new IdentityRole("dupeRole"); -// IdentityResultAssert.IsFailure(await manager.Create(role2)); +// IdentityResultAssert.IsFailure(await manager.CreateAsync(role2)); // } // [Fact] @@ -975,7 +975,7 @@ // var manager = CreateManager(context); // var roleManager = CreateRoleManager(context); // var role = new IdentityRole("addUserTest"); -// IdentityResultAssert.IsSuccess(await roleManager.Create(role)); +// IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(role)); // IdentityUser[] users = // { // new IdentityUser("1"), new IdentityUser("2"), new IdentityUser("3"), @@ -983,9 +983,9 @@ // }; // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await manager.Create(u)); -// IdentityResultAssert.IsSuccess(await manager.AddToRole(u.Id, role.Name)); -// Assert.True(await manager.IsInRole(u.Id, role.Name)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(u)); +// IdentityResultAssert.IsSuccess(await manager.AddToRoleAsync(u.Id, role.Name)); +// Assert.True(await manager.IsInRoleAsync(u.Id, role.Name)); // } // } @@ -1007,21 +1007,21 @@ // }; // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await userManager.Create(u)); +// IdentityResultAssert.IsSuccess(await userManager.CreateAsync(u)); // } // foreach (var r in roles) // { -// IdentityResultAssert.IsSuccess(await roleManager.Create(r)); +// IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(r)); // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await userManager.AddToRole(u.Id, r.Name)); -// Assert.True(await userManager.IsInRole(u.Id, r.Name)); +// IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(u.Id, r.Name)); +// Assert.True(await userManager.IsInRoleAsync(u.Id, r.Name)); // } // } // foreach (var u in users) // { -// var rs = await userManager.GetRoles(u.Id); +// var rs = await userManager.GetRolesAsync(u.Id); // Assert.Equal(roles.Length, rs.Count); // foreach (var r in roles) // { @@ -1038,7 +1038,7 @@ // var userManager = CreateManager(context); // var roleManager = CreateRoleManager(context); // var user = new IdentityUser("MultiRoleUser"); -// IdentityResultAssert.IsSuccess(await userManager.Create(user)); +// IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user)); // IdentityRole[] roles = // { // new IdentityRole("r1"), new IdentityRole("r2"), new IdentityRole("r3"), @@ -1046,12 +1046,12 @@ // }; // foreach (var r in roles) // { -// IdentityResultAssert.IsSuccess(await roleManager.Create(r)); -// IdentityResultAssert.IsSuccess(await userManager.AddToRole(user.Id, r.Name)); -// Assert.True(await userManager.IsInRole(user.Id, r.Name)); +// IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(r)); +// IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(user.Id, r.Name)); +// Assert.True(await userManager.IsInRoleAsync(user.Id, r.Name)); // } -// IdentityResultAssert.IsSuccess(await userManager.RemoveFromRole(user.Id, roles[2].Name)); -// Assert.False(await userManager.IsInRole(user.Id, roles[2].Name)); +// IdentityResultAssert.IsSuccess(await userManager.RemoveFromRoleAsync(user.Id, roles[2].Name)); +// Assert.False(await userManager.IsInRoleAsync(user.Id, roles[2].Name)); // } // [Fact] @@ -1067,19 +1067,19 @@ // }; // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await userManager.Create(u)); +// IdentityResultAssert.IsSuccess(await userManager.CreateAsync(u)); // } // var r = new IdentityRole("r1"); -// IdentityResultAssert.IsSuccess(await roleManager.Create(r)); +// IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(r)); // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await userManager.AddToRole(u.Id, r.Name)); -// Assert.True(await userManager.IsInRole(u.Id, r.Name)); +// IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(u.Id, r.Name)); +// Assert.True(await userManager.IsInRoleAsync(u.Id, r.Name)); // } // foreach (var u in users) // { -// IdentityResultAssert.IsSuccess(await userManager.RemoveFromRole(u.Id, r.Name)); -// Assert.False(await userManager.IsInRole(u.Id, r.Name)); +// IdentityResultAssert.IsSuccess(await userManager.RemoveFromRoleAsync(u.Id, r.Name)); +// Assert.False(await userManager.IsInRoleAsync(u.Id, r.Name)); // } // } @@ -1091,9 +1091,9 @@ // var roleMgr = CreateRoleManager(context); // var role = new IdentityRole("addUserDupeTest"); // var user = new IdentityUser("user1"); -// IdentityResultAssert.IsSuccess(await userMgr.Create(user)); -// IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); -// var result = await userMgr.RemoveFromRole(user.Id, role.Name); +// IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); +// var result = await userMgr.RemoveFromRoleAsync(user.Id, role.Name); // IdentityResultAssert.IsFailure(result, "User is not in role."); // } @@ -1105,11 +1105,11 @@ // var roleMgr = CreateRoleManager(context); // var role = new IdentityRole("addUserDupeTest"); // var user = new IdentityUser("user1"); -// IdentityResultAssert.IsSuccess(await userMgr.Create(user)); -// IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); -// IdentityResultAssert.IsSuccess(await userMgr.AddToRole(user.Id, role.Name)); -// Assert.True(await userMgr.IsInRole(user.Id, role.Name)); -// IdentityResultAssert.IsFailure(await userMgr.AddToRole(user.Id, role.Name), "User already in role."); +// IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); +// IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); +// IdentityResultAssert.IsSuccess(await userMgr.AddToRoleAsync(user.Id, role.Name)); +// Assert.True(await userMgr.IsInRoleAsync(user.Id, role.Name)); +// IdentityResultAssert.IsFailure(await userMgr.AddToRoleAsync(user.Id, role.Name), "User already in role."); // } // [Fact] @@ -1117,8 +1117,8 @@ // { // var roleMgr = CreateRoleManager(); // var role = new IdentityRole("findRoleByNameTest"); -// IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); -// Assert.Equal(role.Id, (await roleMgr.FindByName(role.Name)).Id); +// IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); +// Assert.Equal(role.Id, (await roleMgr.FindByNameAsync(role.Name)).Id); // } // [Fact] @@ -1126,8 +1126,8 @@ // { // var roleMgr = CreateRoleManager(); // var role = new IdentityRole("findRoleTest"); -// IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); -// Assert.Equal(role, await roleMgr.FindById(role.Id)); +// IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); +// Assert.Equal(role, await roleMgr.FindByIdAsync(role.Id)); // } // [Fact] @@ -1137,11 +1137,11 @@ // var userName = "PhoneTest"; // var user = new IdentityUser(userName); // user.PhoneNumber = "123-456-7890"; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// var stamp = await manager.GetSecurityStamp(user.Id); -// Assert.Equal(await manager.GetPhoneNumber(user.Id), "123-456-7890"); -// IdentityResultAssert.IsSuccess(await manager.SetPhoneNumber(user.Id, "111-111-1111")); -// Assert.Equal(await manager.GetPhoneNumber(user.Id), "111-111-1111"); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// var stamp = await manager.GetSecurityStampAsync(user.Id); +// Assert.Equal(await manager.GetPhoneNumberAsync(user.Id), "123-456-7890"); +// IdentityResultAssert.IsSuccess(await manager.SetPhoneNumberAsync(user.Id, "111-111-1111")); +// Assert.Equal(await manager.GetPhoneNumberAsync(user.Id), "111-111-1111"); // Assert.NotEqual(stamp, user.SecurityStamp); // } @@ -1151,13 +1151,13 @@ // var manager = CreateManager(); // const string userName = "PhoneTest"; // var user = new IdentityUser(userName) { PhoneNumber = "123-456-7890" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// Assert.False(await manager.IsPhoneNumberConfirmed(user.Id)); -// var stamp = await manager.GetSecurityStamp(user.Id); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// Assert.False(await manager.IsPhoneNumberConfirmedAsync(user.Id)); +// var stamp = await manager.GetSecurityStampAsync(user.Id); // var token1 = await manager.GenerateChangePhoneNumberToken(user.Id, "111-111-1111"); -// IdentityResultAssert.IsSuccess(await manager.ChangePhoneNumber(user.Id, "111-111-1111", token1)); -// Assert.True(await manager.IsPhoneNumberConfirmed(user.Id)); -// Assert.Equal(await manager.GetPhoneNumber(user.Id), "111-111-1111"); +// IdentityResultAssert.IsSuccess(await manager.ChangePhoneNumberAsync(user.Id, "111-111-1111", token1)); +// Assert.True(await manager.IsPhoneNumberConfirmedAsync(user.Id)); +// Assert.Equal(await manager.GetPhoneNumberAsync(user.Id), "111-111-1111"); // Assert.NotEqual(stamp, user.SecurityStamp); // } @@ -1167,13 +1167,13 @@ // var manager = CreateManager(); // const string userName = "PhoneTest"; // var user = new IdentityUser(userName) { PhoneNumber = "123-456-7890" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// Assert.False(await manager.IsPhoneNumberConfirmed(user.Id)); -// var stamp = await manager.GetSecurityStamp(user.Id); -// IdentityResultAssert.IsFailure(await manager.ChangePhoneNumber(user.Id, "111-111-1111", "bogus"), +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// Assert.False(await manager.IsPhoneNumberConfirmedAsync(user.Id)); +// var stamp = await manager.GetSecurityStampAsync(user.Id); +// IdentityResultAssert.IsFailure(await manager.ChangePhoneNumberAsync(user.Id, "111-111-1111", "bogus"), // "Invalid token."); -// Assert.False(await manager.IsPhoneNumberConfirmed(user.Id)); -// Assert.Equal(await manager.GetPhoneNumber(user.Id), "123-456-7890"); +// Assert.False(await manager.IsPhoneNumberConfirmedAsync(user.Id)); +// Assert.Equal(await manager.GetPhoneNumberAsync(user.Id), "123-456-7890"); // Assert.Equal(stamp, user.SecurityStamp); // } @@ -1183,39 +1183,39 @@ // var manager = CreateManager(); // const string userName = "VerifyPhoneTest"; // var user = new IdentityUser(userName); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // const string num1 = "111-123-4567"; // const string num2 = "111-111-1111"; // var token1 = await manager.GenerateChangePhoneNumberToken(user.Id, num1); // var token2 = await manager.GenerateChangePhoneNumberToken(user.Id, num2); // Assert.NotEqual(token1, token2); -// Assert.True(await manager.VerifyChangePhoneNumberToken(user.Id, token1, num1)); -// Assert.True(await manager.VerifyChangePhoneNumberToken(user.Id, token2, num2)); -// Assert.False(await manager.VerifyChangePhoneNumberToken(user.Id, token2, num1)); -// Assert.False(await manager.VerifyChangePhoneNumberToken(user.Id, token1, num2)); +// Assert.True(await manager.VerifyChangePhoneNumberTokenAsync(user.Id, token1, num1)); +// Assert.True(await manager.VerifyChangePhoneNumberTokenAsync(user.Id, token2, num2)); +// Assert.False(await manager.VerifyChangePhoneNumberTokenAsync(user.Id, token2, num1)); +// Assert.False(await manager.VerifyChangePhoneNumberTokenAsync(user.Id, token1, num2)); // } // private class EmailTokenProvider : IUserTokenProvider // { -// public Task Generate(string purpose, UserManager manager, IdentityUser user, CancellationToken token) +// public Task GenerateAsync(string purpose, UserManager manager, IdentityUser user, CancellationToken token) // { // return Task.FromResult(MakeToken(purpose)); // } -// public Task Validate(string purpose, string token, UserManager manager, +// public Task ValidateAsync(string purpose, string token, UserManager manager, // IdentityUser user, CancellationToken cancellationToken) // { // return Task.FromResult(token == MakeToken(purpose)); // } -// public Task Notify(string token, UserManager manager, IdentityUser user, CancellationToken cancellationToken) +// public Task NotifyAsync(string token, UserManager manager, IdentityUser user, CancellationToken cancellationToken) // { // return manager.SendEmail(user.Id, token, token); // } -// public async Task IsValidProviderForUser(UserManager manager, IdentityUser user, CancellationToken token) +// public async Task IsValidProviderForUserAsync(UserManager manager, IdentityUser user, CancellationToken token) // { -// return !string.IsNullOrEmpty(await manager.GetEmail(user.Id)); +// return !string.IsNullOrEmpty(await manager.GetEmailAsync(user.Id)); // } // private static string MakeToken(string purpose) @@ -1226,25 +1226,25 @@ // private class SmsTokenProvider : IUserTokenProvider // { -// public Task Generate(string purpose, UserManager manager, IdentityUser user, CancellationToken token) +// public Task GenerateAsync(string purpose, UserManager manager, IdentityUser user, CancellationToken token) // { // return Task.FromResult(MakeToken(purpose)); // } -// public Task Validate(string purpose, string token, UserManager manager, +// public Task ValidateAsync(string purpose, string token, UserManager manager, // IdentityUser user, CancellationToken cancellationToken) // { // return Task.FromResult(token == MakeToken(purpose)); // } -// public Task Notify(string token, UserManager manager, IdentityUser user, CancellationToken cancellationToken) +// public Task NotifyAsync(string token, UserManager manager, IdentityUser user, CancellationToken cancellationToken) // { // return manager.SendSms(user.Id, token); // } -// public async Task IsValidProviderForUser(UserManager manager, IdentityUser user, CancellationToken token) +// public async Task IsValidProviderForUserAsync(UserManager manager, IdentityUser user, CancellationToken token) // { -// return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id)); +// return !string.IsNullOrEmpty(await manager.GetPhoneNumberAsync(user.Id)); // } // private static string MakeToken(string purpose) @@ -1263,17 +1263,17 @@ // manager.RegisterTwoFactorProvider(factorId, new EmailTokenProvider()); // var user = new IdentityUser("EmailCodeTest") { Email = "foo@foo.com" }; // const string password = "password"; -// IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// var token = await manager.GenerateTwoFactorToken(user.Id, factorId); +// var token = await manager.GenerateTwoFactorTokenAsync(user.Id, factorId); // Assert.NotNull(token); // Assert.Null(messageService.Message); -// IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); +// IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user.Id, factorId, token)); // Assert.NotNull(messageService.Message); // Assert.Equal(token, messageService.Message.Subject); // Assert.Equal(token, messageService.Message.Body); -// Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); +// Assert.True(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, token)); // } // [Fact] @@ -1281,10 +1281,10 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("NotifyFail"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // await // ExceptionAssert.ThrowsAsync( -// async () => await manager.NotifyTwoFactorToken(user.Id, "Bogus", "token"), +// async () => await manager.NotifyTwoFactorTokenAsync(user.Id, "Bogus", "token"), // "No IUserTwoFactorProvider for 'Bogus' is registered."); // } @@ -1303,17 +1303,17 @@ // // }); // // var user = new IdentityUser("EmailCodeTest") { Email = "foo@foo.com" }; // // const string password = "password"; -// // IdentityResultAssert.IsSuccess(await manager.Create(user, password)); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // // var stamp = user.SecurityStamp; // // Assert.NotNull(stamp); -// // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); +// // var token = await manager.GenerateTwoFactorTokenAsync(user.Id, factorId); // // Assert.NotNull(token); // // Assert.Null(messageService.Message); -// // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); +// // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user.Id, factorId, token)); // // Assert.NotNull(messageService.Message); // // Assert.Equal("Security Code", messageService.Message.Subject); // // Assert.Equal("Your code is: " + token, messageService.Message.Body); -// // Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); +// // Assert.True(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, token)); // //} // //[Fact] @@ -1323,13 +1323,13 @@ // // const string factorId = "EmailCode"; // // manager.RegisterTwoFactorProvider(factorId, new EmailTokenProvider()); // // var user = new IdentityUser("EmailCodeTest") { Email = "foo@foo.com" }; -// // IdentityResultAssert.IsSuccess(await manager.Create(user)); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // // var stamp = user.SecurityStamp; // // Assert.NotNull(stamp); -// // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); +// // var token = await manager.GenerateTwoFactorTokenAsync(user.Id, factorId); // // Assert.NotNull(token); -// // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStamp(user.Id)); -// // Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); +// // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStampAsync(user.Id)); +// // Assert.False(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, token)); // //} // [Fact] @@ -1337,12 +1337,12 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("TwoFactorEnabledTest"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// IdentityResultAssert.IsSuccess(await manager.SetTwoFactorEnabled(user.Id, true)); -// Assert.NotEqual(stamp, await manager.GetSecurityStamp(user.Id)); -// Assert.True(await manager.GetTwoFactorEnabled(user.Id)); +// IdentityResultAssert.IsSuccess(await manager.SetTwoFactorEnabledAsync(user.Id, true)); +// Assert.NotEqual(stamp, await manager.GetSecurityStampAsync(user.Id)); +// Assert.True(await manager.GetTwoFactorEnabledAsync(user.Id)); // } // [Fact] @@ -1352,7 +1352,7 @@ // var messageService = new TestMessageService(); // manager.SmsService = messageService; // var user = new IdentityUser("SmsTest") { PhoneNumber = "4251234567" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // await manager.SendSms(user.Id, "Hi"); // Assert.NotNull(messageService.Message); // Assert.Equal("Hi", messageService.Message.Body); @@ -1365,7 +1365,7 @@ // var messageService = new TestMessageService(); // manager.EmailService = messageService; // var user = new IdentityUser("EmailTest") { Email = "foo@foo.com" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // await manager.SendEmail(user.Id, "Hi", "Body"); // Assert.NotNull(messageService.Message); // Assert.Equal("Hi", messageService.Message.Subject); @@ -1381,16 +1381,16 @@ // const string factorId = "PhoneCode"; // manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider()); // var user = new IdentityUser("PhoneCodeTest") { PhoneNumber = "4251234567" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); -// var token = await manager.GenerateTwoFactorToken(user.Id, factorId); +// var token = await manager.GenerateTwoFactorTokenAsync(user.Id, factorId); // Assert.NotNull(token); // Assert.Null(messageService.Message); -// IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); +// IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user.Id, factorId, token)); // Assert.NotNull(messageService.Message); // Assert.Equal(token, messageService.Message.Body); -// Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); +// Assert.True(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, token)); // } // //[Fact] @@ -1405,16 +1405,16 @@ // // MessageFormat = "Your code is: {0}" // // }); // // var user = new IdentityUser("PhoneCodeTest") { PhoneNumber = "4251234567" }; -// // IdentityResultAssert.IsSuccess(await manager.Create(user)); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // // var stamp = user.SecurityStamp; // // Assert.NotNull(stamp); -// // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); +// // var token = await manager.GenerateTwoFactorTokenAsync(user.Id, factorId); // // Assert.NotNull(token); // // Assert.Null(messageService.Message); -// // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); +// // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user.Id, factorId, token)); // // Assert.NotNull(messageService.Message); // // Assert.Equal("Your code is: " + token, messageService.Message.Body); -// // Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); +// // Assert.True(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, token)); // //} // [Fact] @@ -1422,13 +1422,13 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("PhoneCodeTest"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // const string error = "No IUserTwoFactorProvider for 'bogus' is registered."; // await // ExceptionAssert.ThrowsAsync( -// () => manager.GenerateTwoFactorToken(user.Id, "bogus"), error); +// () => manager.GenerateTwoFactorTokenAsync(user.Id, "bogus"), error); // await ExceptionAssert.ThrowsAsync( -// () => manager.VerifyTwoFactorToken(user.Id, "bogus", "bogus"), error); +// () => manager.VerifyTwoFactorTokenAsync(user.Id, "bogus", "bogus"), error); // } // [Fact] @@ -1436,7 +1436,7 @@ // { // var manager = CreateManager(); // var user = new IdentityUser("test"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var factors = await manager.GetValidTwoFactorProviders(user.Id); // Assert.NotNull(factors); // Assert.True(!factors.Any()); @@ -1449,20 +1449,20 @@ // manager.RegisterTwoFactorProvider("phone", new SmsTokenProvider()); // manager.RegisterTwoFactorProvider("email", new EmailTokenProvider()); // var user = new IdentityUser("test"); -// IdentityResultAssert.IsSuccess(await manager.Create(user)); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var factors = await manager.GetValidTwoFactorProviders(user.Id); // Assert.NotNull(factors); // Assert.True(!factors.Any()); -// IdentityResultAssert.IsSuccess(await manager.SetPhoneNumber(user.Id, "111-111-1111")); +// IdentityResultAssert.IsSuccess(await manager.SetPhoneNumberAsync(user.Id, "111-111-1111")); // factors = await manager.GetValidTwoFactorProviders(user.Id); // Assert.NotNull(factors); // Assert.True(factors.Count() == 1); // Assert.Equal("phone", factors[0]); -// IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, "test@test.com")); +// IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user.Id, "test@test.com")); // factors = await manager.GetValidTwoFactorProviders(user.Id); // Assert.NotNull(factors); // Assert.True(factors.Count() == 2); -// IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, null)); +// IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user.Id, null)); // factors = await manager.GetValidTwoFactorProviders(user.Id); // Assert.NotNull(factors); // Assert.True(factors.Count() == 1); @@ -1477,13 +1477,13 @@ // // manager.RegisterTwoFactorProvider(factorId, new PhoneNumberTokenProvider()); // // var user = new IdentityUser("PhoneCodeTest"); // // user.PhoneNumber = "4251234567"; -// // IdentityResultAssert.IsSuccess(await manager.Create(user)); +// // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // // var stamp = user.SecurityStamp; // // Assert.NotNull(stamp); -// // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); +// // var token = await manager.GenerateTwoFactorTokenAsync(user.Id, factorId); // // Assert.NotNull(token); -// // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStamp(user.Id)); -// // Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); +// // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStampAsync(user.Id)); +// // Assert.False(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, token)); // //} // [Fact] @@ -1493,10 +1493,10 @@ // manager.RegisterTwoFactorProvider("PhoneCode", new SmsTokenProvider()); // manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider()); // var user = new IdentityUser("WrongTokenProviderTest") { PhoneNumber = "4251234567" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// var token = await manager.GenerateTwoFactorToken(user.Id, "PhoneCode"); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// var token = await manager.GenerateTwoFactorTokenAsync(user.Id, "PhoneCode"); // Assert.NotNull(token); -// Assert.False(await manager.VerifyTwoFactorToken(user.Id, "EmailCode", token)); +// Assert.False(await manager.VerifyTwoFactorTokenAsync(user.Id, "EmailCode", token)); // } // [Fact] @@ -1506,8 +1506,8 @@ // const string factorId = "PhoneCode"; // manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider()); // var user = new IdentityUser("PhoneCodeTest") { PhoneNumber = "4251234567" }; -// IdentityResultAssert.IsSuccess(await manager.Create(user)); -// Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, "bogus")); +// IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); +// Assert.False(await manager.VerifyTwoFactorTokenAsync(user.Id, factorId, "bogus")); // } // private class DataStoreConfig : ContextConfiguration @@ -1585,7 +1585,7 @@ // //} -// // TODO: Create DB? +// // TODO: CreateAsync DB? // return db; // } @@ -1614,7 +1614,7 @@ // { // public IdentityMessage Message { get; set; } -// public Task Send(IdentityMessage message, CancellationToken token) +// public Task SendAsync(IdentityMessage message, CancellationToken token) // { // Message = message; // return Task.FromResult(0); diff --git a/test/Microsoft.AspNet.Identity.InMemory.Test/InMemoryStoreTest.cs b/test/Microsoft.AspNet.Identity.InMemory.Test/InMemoryStoreTest.cs index 19f3b82850..6e55f782b1 100644 --- a/test/Microsoft.AspNet.Identity.InMemory.Test/InMemoryStoreTest.cs +++ b/test/Microsoft.AspNet.Identity.InMemory.Test/InMemoryStoreTest.cs @@ -14,23 +14,23 @@ namespace Microsoft.AspNet.Identity.InMemory.Test public async Task CanDeleteUser() { var manager = CreateManager(); - var user = new InMemoryUser("Delete"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsSuccess(await manager.Delete(user)); - Assert.Null(await manager.FindById(user.Id)); + var user = new InMemoryUser("DeleteAsync"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await manager.DeleteAsync(user)); + Assert.Null(await manager.FindByIdAsync(user.Id)); } [Fact] public async Task CanUpdateUserName() { var manager = CreateManager(); - var user = new InMemoryUser("Update"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - Assert.Null(await manager.FindByName("New")); + var user = new InMemoryUser("UpdateAsync"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + Assert.Null(await manager.FindByNameAsync("New")); user.UserName = "New"; - IdentityResultAssert.IsSuccess(await manager.Update(user)); - Assert.NotNull(await manager.FindByName("New")); - Assert.Null(await manager.FindByName("Update")); + IdentityResultAssert.IsSuccess(await manager.UpdateAsync(user)); + Assert.NotNull(await manager.FindByNameAsync("New")); + Assert.Null(await manager.FindByNameAsync("UpdateAsync")); } [Fact] @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("CreateBlocked"); manager.UserValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.Create(user), AlwaysBadValidator.ErrorMessage); + IdentityResultAssert.IsFailure(await manager.CreateAsync(user), AlwaysBadValidator.ErrorMessage); } [Fact] @@ -47,9 +47,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("UpdateBlocked"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); manager.UserValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.Update(user), AlwaysBadValidator.ErrorMessage); + IdentityResultAssert.IsFailure(await manager.UpdateAsync(user), AlwaysBadValidator.ErrorMessage); } [Theory] @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("UpdateBlocked") {Email = email}; manager.UserValidator = new UserValidator {RequireUniqueEmail = true}; - IdentityResultAssert.IsFailure(await manager.Create(user), "Email cannot be null or empty."); + IdentityResultAssert.IsFailure(await manager.CreateAsync(user), "Email cannot be null or empty."); } #if NET45 @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("UpdateBlocked") {Email = email}; manager.UserValidator = new UserValidator {RequireUniqueEmail = true}; - IdentityResultAssert.IsFailure(await manager.Create(user), "Email '" + email + "' is invalid."); + IdentityResultAssert.IsFailure(await manager.CreateAsync(user), "Email '" + email + "' is invalid."); } #endif @@ -81,9 +81,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("AddPasswordBlocked"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); manager.PasswordValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), + IdentityResultAssert.IsFailure(await manager.AddPasswordAsync(user, "password"), AlwaysBadValidator.ErrorMessage); } @@ -92,9 +92,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("ChangePasswordBlocked"); - IdentityResultAssert.IsSuccess(await manager.Create(user, "password")); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "password")); manager.PasswordValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.ChangePassword(user.Id, "password", "new"), + IdentityResultAssert.IsFailure(await manager.ChangePasswordAsync(user, "password", "new"), AlwaysBadValidator.ErrorMessage); } @@ -102,11 +102,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test public async Task CanCreateUserNoPassword() { var manager = CreateManager(); - IdentityResultAssert.IsSuccess(await manager.Create(new InMemoryUser("CreateUserTest"))); - var user = await manager.FindByName("CreateUserTest"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(new InMemoryUser("CreateUserTest"))); + var user = await manager.FindByNameAsync("CreateUserTest"); Assert.NotNull(user); Assert.Null(user.PasswordHash); - var logins = await manager.GetLogins(user.Id); + var logins = await manager.GetLogins(user); Assert.NotNull(logins); Assert.Equal(0, logins.Count()); } @@ -118,11 +118,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test const string userName = "CreateExternalUserTest"; const string provider = "ZzAuth"; const string providerKey = "HaoKey"; - IdentityResultAssert.IsSuccess(await manager.Create(new InMemoryUser(userName))); - var user = await manager.FindByName(userName); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(new InMemoryUser(userName))); + var user = await manager.FindByNameAsync(userName); var login = new UserLoginInfo(provider, providerKey); - IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); - var logins = await manager.GetLogins(user.Id); + IdentityResultAssert.IsSuccess(await manager.AddLogin(user, login)); + var logins = await manager.GetLogins(user); Assert.NotNull(logins); Assert.Equal(1, logins.Count()); Assert.Equal(provider, logins.First().LoginProvider); @@ -135,16 +135,16 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var login = new UserLoginInfo("Provider", "key"); var user = new InMemoryUser("CreateUserLoginAddPasswordTest"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); - Assert.False(await manager.HasPassword(user.Id)); - IdentityResultAssert.IsSuccess(await manager.AddPassword(user.Id, "password")); - Assert.True(await manager.HasPassword(user.Id)); - var logins = await manager.GetLogins(user.Id); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await manager.AddLogin(user, login)); + Assert.False(await manager.HasPasswordAsync(user)); + IdentityResultAssert.IsSuccess(await manager.AddPasswordAsync(user, "password")); + Assert.True(await manager.HasPasswordAsync(user)); + var logins = await manager.GetLogins(user); Assert.NotNull(logins); Assert.Equal(1, logins.Count()); - Assert.Equal(user, await manager.Find(login)); - Assert.Equal(user, await manager.Find(user.UserName, "password")); + Assert.Equal(user, await manager.FindByLoginAsync(login)); + Assert.Equal(user, await manager.FindByUserNamePassword(user.UserName, "password")); } [Fact] @@ -152,9 +152,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("CannotAddAnotherPassword"); - IdentityResultAssert.IsSuccess(await manager.Create(user, "Password")); - Assert.True(await manager.HasPassword(user.Id)); - IdentityResultAssert.IsFailure(await manager.AddPassword(user.Id, "password"), + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "Password")); + Assert.True(await manager.HasPasswordAsync(user)); + IdentityResultAssert.IsFailure(await manager.AddPasswordAsync(user, "password"), "User already has a password set."); } @@ -164,20 +164,20 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("CreateUserAddRemoveLoginTest"); var login = new UserLoginInfo("Provider", "key"); - var result = await manager.Create(user); + var result = await manager.CreateAsync(user); Assert.NotNull(user); IdentityResultAssert.IsSuccess(result); - IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); - Assert.Equal(user, await manager.Find(login)); - var logins = await manager.GetLogins(user.Id); + IdentityResultAssert.IsSuccess(await manager.AddLogin(user, login)); + Assert.Equal(user, await manager.FindByLoginAsync(login)); + var logins = await manager.GetLogins(user); Assert.NotNull(logins); Assert.Equal(1, logins.Count()); Assert.Equal(login.LoginProvider, logins.Last().LoginProvider); Assert.Equal(login.ProviderKey, logins.Last().ProviderKey); var stamp = user.SecurityStamp; - IdentityResultAssert.IsSuccess(await manager.RemoveLogin(user.Id, login)); - Assert.Null(await manager.Find(login)); - logins = await manager.GetLogins(user.Id); + IdentityResultAssert.IsSuccess(await manager.RemoveLogin(user, login)); + Assert.Null(await manager.FindByLoginAsync(login)); + logins = await manager.GetLogins(user); Assert.NotNull(logins); Assert.Equal(0, logins.Count()); Assert.NotEqual(stamp, user.SecurityStamp); @@ -189,10 +189,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("RemovePasswordTest"); const string password = "password"; - IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); var stamp = user.SecurityStamp; - IdentityResultAssert.IsSuccess(await manager.RemovePassword(user.Id)); - var u = await manager.FindByName(user.UserName); + IdentityResultAssert.IsSuccess(await manager.RemovePasswordAsync(user)); + var u = await manager.FindByNameAsync(user.UserName); Assert.NotNull(u); Assert.Null(u.PasswordHash); Assert.NotEqual(stamp, user.SecurityStamp); @@ -205,12 +205,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var user = new InMemoryUser("ChangePasswordTest"); const string password = "password"; const string newPassword = "newpassword"; - IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - IdentityResultAssert.IsSuccess(await manager.ChangePassword(user.Id, password, newPassword)); - Assert.Null(await manager.Find(user.UserName, password)); - Assert.Equal(user, await manager.Find(user.UserName, newPassword)); + IdentityResultAssert.IsSuccess(await manager.ChangePasswordAsync(user, password, newPassword)); + Assert.Null(await manager.FindByUserNamePassword(user.UserName, password)); + Assert.Equal(user, await manager.FindByUserNamePassword(user.UserName, newPassword)); Assert.NotEqual(stamp, user.SecurityStamp); } @@ -219,22 +219,22 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("ClaimsAddRemove"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); Claim[] claims = {new Claim("c", "v"), new Claim("c2", "v2"), new Claim("c2", "v3")}; foreach (Claim c in claims) { - IdentityResultAssert.IsSuccess(await manager.AddClaim(user.Id, c)); + IdentityResultAssert.IsSuccess(await manager.AddClaimAsync(user, c)); } - var userClaims = await manager.GetClaims(user.Id); + var userClaims = await manager.GetClaimsAsync(user); Assert.Equal(3, userClaims.Count); - IdentityResultAssert.IsSuccess(await manager.RemoveClaim(user.Id, claims[0])); - userClaims = await manager.GetClaims(user.Id); + IdentityResultAssert.IsSuccess(await manager.RemoveClaimAsync(user, claims[0])); + userClaims = await manager.GetClaimsAsync(user); Assert.Equal(2, userClaims.Count); - IdentityResultAssert.IsSuccess(await manager.RemoveClaim(user.Id, claims[1])); - userClaims = await manager.GetClaims(user.Id); + IdentityResultAssert.IsSuccess(await manager.RemoveClaimAsync(user, claims[1])); + userClaims = await manager.GetClaimsAsync(user); Assert.Equal(1, userClaims.Count); - IdentityResultAssert.IsSuccess(await manager.RemoveClaim(user.Id, claims[2])); - userClaims = await manager.GetClaims(user.Id); + IdentityResultAssert.IsSuccess(await manager.RemoveClaimAsync(user, claims[2])); + userClaims = await manager.GetClaimsAsync(user); Assert.Equal(0, userClaims.Count); } @@ -243,8 +243,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("user"); - IdentityResultAssert.IsSuccess(await manager.Create(user, "password")); - var result = await manager.ChangePassword(user.Id, "bogus", "newpassword"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "password")); + var result = await manager.ChangePasswordAsync(user, "bogus", "newpassword"); IdentityResultAssert.IsFailure(result, "Incorrect password."); } @@ -254,8 +254,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("dupe"); var user2 = new InMemoryUser("dupe"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsFailure(await manager.Create(user2), "Name dupe is already taken."); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsFailure(await manager.CreateAsync(user2), "Name dupe is already taken."); } [Fact] @@ -264,8 +264,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("dupe") {Email = "yup@yup.com"}; var user2 = new InMemoryUser("dupeEmail") {Email = "yup@yup.com"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsSuccess(await manager.Create(user2)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user2)); } [Fact] @@ -275,8 +275,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.UserValidator = new UserValidator {RequireUniqueEmail = true}; var user = new InMemoryUser("dupe") {Email = "yup@yup.com"}; var user2 = new InMemoryUser("dupeEmail") {Email = "yup@yup.com"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsFailure(await manager.Create(user2), "Email 'yup@yup.com' is already taken."); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsFailure(await manager.CreateAsync(user2), "Email 'yup@yup.com' is already taken."); } [Fact] @@ -285,10 +285,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("stampMe"); Assert.Null(user.SecurityStamp); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStamp(user.Id)); + IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStampAsync(user)); Assert.NotEqual(stamp, user.SecurityStamp); } @@ -298,9 +298,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var user = new InMemoryUser("DupeLogin"); var login = new UserLoginInfo("provder", "key"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsSuccess(await manager.AddLogin(user.Id, login)); - var result = await manager.AddLogin(user.Id, login); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await manager.AddLogin(user, login)); + var result = await manager.AddLogin(user, login); IdentityResultAssert.IsFailure(result, "A user with that external login already exists."); } @@ -312,8 +312,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test const string userName = "EmailTest"; const string email = "email@test.com"; var user = new InMemoryUser(userName) {Email = email}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - var fetch = await manager.FindByEmail(email); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + var fetch = await manager.FindByEmailAsync(email); Assert.Equal(user, fetch); } @@ -329,7 +329,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (InMemoryUser u in users) { - IdentityResultAssert.IsSuccess(await mgr.Create(u)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(u)); } var usersQ = mgr.Users; Assert.Equal(3, usersQ.Count()); @@ -345,11 +345,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var role = CreateRoleManager(); var user = new InMemoryUser("Hao"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsSuccess(await role.Create(new InMemoryRole("Admin"))); - IdentityResultAssert.IsSuccess(await role.Create(new InMemoryRole("Local"))); - IdentityResultAssert.IsSuccess(await manager.AddToRole(user.Id, "Admin")); - IdentityResultAssert.IsSuccess(await manager.AddToRole(user.Id, "Local")); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await role.CreateAsync(new InMemoryRole("Admin"))); + IdentityResultAssert.IsSuccess(await role.CreateAsync(new InMemoryRole("Local"))); + IdentityResultAssert.IsSuccess(await manager.AddToRoleAsync(user, "Admin")); + IdentityResultAssert.IsSuccess(await manager.AddToRoleAsync(user, "Local")); Claim[] userClaims = { new Claim("Whatever", "Value"), @@ -357,7 +357,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (var c in userClaims) { - IdentityResultAssert.IsSuccess(await manager.AddClaim(user.Id, c)); + IdentityResultAssert.IsSuccess(await manager.AddClaimAsync(user, c)); } var identity = await manager.CreateIdentity(user, "test"); @@ -381,31 +381,31 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("test"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - Assert.False(await manager.IsEmailConfirmed(user.Id)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + Assert.False(await manager.IsEmailConfirmedAsync(user)); } // TODO: No token provider implementations yet private class StaticTokenProvider : IUserTokenProvider { - public Task Generate(string purpose, UserManager manager, + public Task GenerateAsync(string purpose, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(MakeToken(purpose, user)); } - public Task Validate(string purpose, string token, UserManager manager, + public Task ValidateAsync(string purpose, string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(token == MakeToken(purpose, user)); } - public Task Notify(string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task NotifyAsync(string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task IsValidProviderForUser(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task IsValidProviderForUserAsync(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(true); } @@ -424,14 +424,14 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var user = new InMemoryUser("ResetPasswordTest"); const string password = "password"; const string newPassword = "newpassword"; - IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - var token = await manager.GeneratePasswordResetToken(user.Id); + var token = await manager.GeneratePasswordResetTokenAsync(user); Assert.NotNull(token); - IdentityResultAssert.IsSuccess(await manager.ResetPassword(user.Id, token, newPassword)); - Assert.Null(await manager.Find(user.UserName, password)); - Assert.Equal(user, await manager.Find(user.UserName, newPassword)); + IdentityResultAssert.IsSuccess(await manager.ResetPassword(user, token, newPassword)); + Assert.Null(await manager.FindByUserNamePassword(user.UserName, password)); + Assert.Equal(user, await manager.FindByUserNamePassword(user.UserName, newPassword)); Assert.NotEqual(stamp, user.SecurityStamp); } @@ -443,16 +443,16 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var user = new InMemoryUser("ResetPasswordTest"); const string password = "password"; const string newPassword = "newpassword"; - IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - var token = await manager.GeneratePasswordResetToken(user.Id); + var token = await manager.GeneratePasswordResetTokenAsync(user); Assert.NotNull(token); manager.PasswordValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.ResetPassword(user.Id, token, newPassword), + IdentityResultAssert.IsFailure(await manager.ResetPassword(user, token, newPassword), AlwaysBadValidator.ErrorMessage); - Assert.NotNull(await manager.Find(user.UserName, password)); - Assert.Equal(user, await manager.Find(user.UserName, password)); + Assert.NotNull(await manager.FindByUserNamePassword(user.UserName, password)); + Assert.Equal(user, await manager.FindByUserNamePassword(user.UserName, password)); Assert.Equal(stamp, user.SecurityStamp); } @@ -464,12 +464,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var user = new InMemoryUser("ResetPasswordTest"); const string password = "password"; const string newPassword = "newpassword"; - IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - IdentityResultAssert.IsFailure(await manager.ResetPassword(user.Id, "bogus", newPassword), "Invalid token."); - Assert.NotNull(await manager.Find(user.UserName, password)); - Assert.Equal(user, await manager.Find(user.UserName, password)); + IdentityResultAssert.IsFailure(await manager.ResetPassword(user, "bogus", newPassword), "Invalid token."); + Assert.NotNull(await manager.FindByUserNamePassword(user.UserName, password)); + Assert.Equal(user, await manager.FindByUserNamePassword(user.UserName, password)); Assert.Equal(stamp, user.SecurityStamp); } @@ -480,13 +480,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.UserTokenProvider = new StaticTokenProvider(); var user = new InMemoryUser("UserTokenTest"); var user2 = new InMemoryUser("UserTokenTest2"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsSuccess(await manager.Create(user2)); - var token = await manager.GenerateUserToken("test", user.Id); - Assert.True(await manager.VerifyUserToken(user.Id, "test", token)); - Assert.False(await manager.VerifyUserToken(user.Id, "test2", token)); - Assert.False(await manager.VerifyUserToken(user.Id, "test", token + "a")); - Assert.False(await manager.VerifyUserToken(user2.Id, "test", token)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user2)); + var token = await manager.GenerateUserTokenAsync("test", user); + Assert.True(await manager.VerifyUserTokenAsync(user, "test", token)); + Assert.False(await manager.VerifyUserTokenAsync(user, "test2", token)); + Assert.False(await manager.VerifyUserTokenAsync(user, "test", token + "a")); + Assert.False(await manager.VerifyUserTokenAsync(user2, "test", token)); } [Fact] @@ -496,13 +496,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.UserTokenProvider = new StaticTokenProvider(); var user = new InMemoryUser("test"); Assert.False(user.EmailConfirmed); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - var token = await manager.GenerateEmailConfirmationToken(user.Id); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + var token = await manager.GenerateEmailConfirmationTokenAsync(user); Assert.NotNull(token); - IdentityResultAssert.IsSuccess(await manager.ConfirmEmail(user.Id, token)); - Assert.True(await manager.IsEmailConfirmed(user.Id)); - IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, null)); - Assert.False(await manager.IsEmailConfirmed(user.Id)); + IdentityResultAssert.IsSuccess(await manager.ConfirmEmailAsync(user, token)); + Assert.True(await manager.IsEmailConfirmedAsync(user)); + IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user, null)); + Assert.False(await manager.IsEmailConfirmedAsync(user)); } [Fact] @@ -512,9 +512,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.UserTokenProvider = new StaticTokenProvider(); var user = new InMemoryUser("test"); Assert.False(user.EmailConfirmed); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - IdentityResultAssert.IsFailure(await manager.ConfirmEmail(user.Id, "bogus"), "Invalid token."); - Assert.False(await manager.IsEmailConfirmed(user.Id)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + IdentityResultAssert.IsFailure(await manager.ConfirmEmailAsync(user, "bogus"), "Invalid token."); + Assert.False(await manager.IsEmailConfirmedAsync(user)); } // TODO: Can't reenable til we have a SecurityStamp linked token provider @@ -524,12 +524,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test // var manager = CreateManager(); // var user = new InMemoryUser("test"); // Assert.False(user.EmailConfirmed); - // IdentityResultAssert.IsSuccess(await manager.Create(user, "password")); - // var token = await manager.GenerateEmailConfirmationToken(user.Id); + // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, "password")); + // var token = await manager.GenerateEmailConfirmationTokenAsync(user); // Assert.NotNull(token); - // IdentityResultAssert.IsSuccess(await manager.ChangePassword(user.Id, "password", "newpassword")); - // IdentityResultAssert.IsFailure(await manager.ConfirmEmail(user.Id, token), "Invalid token."); - // Assert.False(await manager.IsEmailConfirmed(user.Id)); + // IdentityResultAssert.IsSuccess(await manager.ChangePasswordAsync(user, "password", "newpassword")); + // IdentityResultAssert.IsFailure(await manager.ConfirmEmailAsync(user, token), "Invalid token."); + // Assert.False(await manager.IsEmailConfirmedAsync(user)); //} // Lockout tests @@ -541,14 +541,14 @@ namespace Microsoft.AspNet.Identity.InMemory.Test mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1); mgr.UserLockoutEnabledByDefault = true; var user = new InMemoryUser("fastLockout"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - Assert.False(await mgr.IsLockedOut(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.True(await mgr.IsLockedOut(user.Id)); - Assert.True(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); + Assert.False(await mgr.IsLockedOutAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.True(await mgr.IsLockedOutAsync(user)); + Assert.True(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user)); } [Fact] @@ -559,18 +559,18 @@ namespace Microsoft.AspNet.Identity.InMemory.Test mgr.UserLockoutEnabledByDefault = true; mgr.MaxFailedAccessAttemptsBeforeLockout = 2; var user = new InMemoryUser("twoFailureLockout"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - Assert.False(await mgr.IsLockedOut(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.False(await mgr.IsLockedOut(user.Id)); - Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.True(await mgr.IsLockedOut(user.Id)); - Assert.True(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); + Assert.False(await mgr.IsLockedOutAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.False(await mgr.IsLockedOutAsync(user)); + Assert.False(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.True(await mgr.IsLockedOutAsync(user)); + Assert.True(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user)); } [Fact] @@ -581,22 +581,22 @@ namespace Microsoft.AspNet.Identity.InMemory.Test mgr.UserLockoutEnabledByDefault = true; mgr.MaxFailedAccessAttemptsBeforeLockout = 2; var user = new InMemoryUser("resetLockout"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - Assert.False(await mgr.IsLockedOut(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.False(await mgr.IsLockedOut(user.Id)); - Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.ResetAccessFailedCount(user.Id)); - Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); - Assert.False(await mgr.IsLockedOut(user.Id)); - Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.False(await mgr.IsLockedOut(user.Id)); - Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); + Assert.False(await mgr.IsLockedOutAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.False(await mgr.IsLockedOutAsync(user)); + Assert.False(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.ResetAccessFailedCountAsync(user)); + Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user)); + Assert.False(await mgr.IsLockedOutAsync(user)); + Assert.False(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.False(await mgr.IsLockedOutAsync(user)); + Assert.False(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user)); } [Fact] @@ -606,21 +606,21 @@ namespace Microsoft.AspNet.Identity.InMemory.Test mgr.DefaultAccountLockoutTimeSpan = TimeSpan.FromHours(1); mgr.MaxFailedAccessAttemptsBeforeLockout = 2; var user = new InMemoryUser("manualLockout"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.False(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.False(await mgr.GetLockoutEnabledAsync(user)); Assert.False(user.LockoutEnabled); - IdentityResultAssert.IsSuccess(await mgr.SetLockoutEnabled(user.Id, true)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.SetLockoutEnabledAsync(user, true)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - Assert.False(await mgr.IsLockedOut(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.False(await mgr.IsLockedOut(user.Id)); - Assert.False(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(1, await mgr.GetAccessFailedCount(user.Id)); - IdentityResultAssert.IsSuccess(await mgr.AccessFailed(user.Id)); - Assert.True(await mgr.IsLockedOut(user.Id)); - Assert.True(await mgr.GetLockoutEndDate(user.Id) > DateTimeOffset.UtcNow.AddMinutes(55)); - Assert.Equal(0, await mgr.GetAccessFailedCount(user.Id)); + Assert.False(await mgr.IsLockedOutAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.False(await mgr.IsLockedOutAsync(user)); + Assert.False(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(1, await mgr.GetAccessFailedCountAsync(user)); + IdentityResultAssert.IsSuccess(await mgr.AccessFailedAsync(user)); + Assert.True(await mgr.IsLockedOutAsync(user)); + Assert.True(await mgr.GetLockoutEndDate(user) > DateTimeOffset.UtcNow.AddMinutes(55)); + Assert.Equal(0, await mgr.GetAccessFailedCountAsync(user)); } [Fact] @@ -629,12 +629,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var mgr = CreateManager(); mgr.UserLockoutEnabledByDefault = true; var user = new InMemoryUser("LockoutTest"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user.Id, new DateTimeOffset())); - Assert.False(await mgr.IsLockedOut(user.Id)); - Assert.Equal(new DateTimeOffset(), await mgr.GetLockoutEndDate(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user, new DateTimeOffset())); + Assert.False(await mgr.IsLockedOutAsync(user)); + Assert.Equal(new DateTimeOffset(), await mgr.GetLockoutEndDate(user)); Assert.Equal(new DateTimeOffset(), user.LockoutEnd); } @@ -643,12 +643,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var mgr = CreateManager(); var user = new InMemoryUser("LockoutNotEnabledTest"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.False(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.False(await mgr.GetLockoutEnabledAsync(user)); Assert.False(user.LockoutEnabled); - IdentityResultAssert.IsFailure(await mgr.SetLockoutEndDate(user.Id, new DateTimeOffset()), + IdentityResultAssert.IsFailure(await mgr.SetLockoutEndDate(user, new DateTimeOffset()), "Lockout is not enabled for this user."); - Assert.False(await mgr.IsLockedOut(user.Id)); + Assert.False(await mgr.IsLockedOutAsync(user)); } [Fact] @@ -657,10 +657,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var mgr = CreateManager(); mgr.UserLockoutEnabledByDefault = true; var user = new InMemoryUser("LockoutUtcNowTest") {LockoutEnd = DateTimeOffset.UtcNow.AddSeconds(-1)}; - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - Assert.False(await mgr.IsLockedOut(user.Id)); + Assert.False(await mgr.IsLockedOutAsync(user)); } [Fact] @@ -669,11 +669,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var mgr = CreateManager(); mgr.UserLockoutEnabledByDefault = true; var user = new InMemoryUser("LockoutUtcNowTest"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user.Id, DateTimeOffset.UtcNow.AddSeconds(-1))); - Assert.False(await mgr.IsLockedOut(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user, DateTimeOffset.UtcNow.AddSeconds(-1))); + Assert.False(await mgr.IsLockedOutAsync(user)); } [Fact] @@ -682,10 +682,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var mgr = CreateManager(); mgr.UserLockoutEnabledByDefault = true; var user = new InMemoryUser("LockoutUtcNowTest") {LockoutEnd = DateTimeOffset.UtcNow.AddMinutes(5)}; - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); - Assert.True(await mgr.IsLockedOut(user.Id)); + Assert.True(await mgr.IsLockedOutAsync(user)); } [Fact] @@ -694,13 +694,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var mgr = CreateManager(); mgr.UserLockoutEnabledByDefault = true; var user = new InMemoryUser("LockoutTest"); - IdentityResultAssert.IsSuccess(await mgr.Create(user)); - Assert.True(await mgr.GetLockoutEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await mgr.CreateAsync(user)); + Assert.True(await mgr.GetLockoutEnabledAsync(user)); Assert.True(user.LockoutEnabled); var lockoutEnd = new DateTimeOffset(DateTime.Now.AddMinutes(30).ToLocalTime()); - IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user.Id, lockoutEnd)); - Assert.True(await mgr.IsLockedOut(user.Id)); - var end = await mgr.GetLockoutEndDate(user.Id); + IdentityResultAssert.IsSuccess(await mgr.SetLockoutEndDate(user, lockoutEnd)); + Assert.True(await mgr.IsLockedOutAsync(user)); + var end = await mgr.GetLockoutEndDate(user); Assert.Equal(lockoutEnd, end); } @@ -710,9 +710,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateRoleManager(); var role = new InMemoryRole("create"); - Assert.False(await manager.RoleExists(role.Name)); - IdentityResultAssert.IsSuccess(await manager.Create(role)); - Assert.True(await manager.RoleExists(role.Name)); + Assert.False(await manager.RoleExistsAsync(role.Name)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); + Assert.True(await manager.RoleExistsAsync(role.Name)); } private class AlwaysBadValidator : IUserValidator, IRoleValidator, @@ -720,17 +720,17 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { public const string ErrorMessage = "I'm Bad."; - public Task Validate(string password, CancellationToken cancellationToken = default(CancellationToken)) + public Task ValidateAsync(string password, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(IdentityResult.Failed(ErrorMessage)); } - public Task Validate(RoleManager manager, InMemoryRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task ValidateAsync(RoleManager manager, InMemoryRole role, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(IdentityResult.Failed(ErrorMessage)); } - public Task Validate(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task ValidateAsync(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(IdentityResult.Failed(ErrorMessage)); } @@ -741,7 +741,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateRoleManager(); manager.RoleValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.Create(new InMemoryRole("blocked")), + IdentityResultAssert.IsFailure(await manager.CreateAsync(new InMemoryRole("blocked")), AlwaysBadValidator.ErrorMessage); } @@ -750,10 +750,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateRoleManager(); var role = new InMemoryRole("poorguy"); - IdentityResultAssert.IsSuccess(await manager.Create(role)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); var error = AlwaysBadValidator.ErrorMessage; manager.RoleValidator = new AlwaysBadValidator(); - IdentityResultAssert.IsFailure(await manager.Update(role), error); + IdentityResultAssert.IsFailure(await manager.UpdateAsync(role), error); } [Fact] @@ -761,30 +761,30 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateRoleManager(); var role = new InMemoryRole("delete"); - Assert.False(await manager.RoleExists(role.Name)); - IdentityResultAssert.IsSuccess(await manager.Create(role)); - IdentityResultAssert.IsSuccess(await manager.Delete(role)); - Assert.False(await manager.RoleExists(role.Name)); + Assert.False(await manager.RoleExistsAsync(role.Name)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); + IdentityResultAssert.IsSuccess(await manager.DeleteAsync(role)); + Assert.False(await manager.RoleExistsAsync(role.Name)); } [Fact] public async Task CanRoleFindByIdTest() { var manager = CreateRoleManager(); - var role = new InMemoryRole("FindById"); - Assert.Null(await manager.FindById(role.Id)); - IdentityResultAssert.IsSuccess(await manager.Create(role)); - Assert.Equal(role, await manager.FindById(role.Id)); + var role = new InMemoryRole("FindByIdAsync"); + Assert.Null(await manager.FindByIdAsync(role.Id)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); + Assert.Equal(role, await manager.FindByIdAsync(role.Id)); } [Fact] public async Task CanRoleFindByName() { var manager = CreateRoleManager(); - var role = new InMemoryRole("FindByName"); + var role = new InMemoryRole("FindByNameAsync"); Assert.Null(await manager.FindByName(role.Name)); - Assert.False(await manager.RoleExists(role.Name)); - IdentityResultAssert.IsSuccess(await manager.Create(role)); + Assert.False(await manager.RoleExistsAsync(role.Name)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); Assert.Equal(role, await manager.FindByName(role.Name)); } @@ -793,12 +793,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateRoleManager(); var role = new InMemoryRole("update"); - Assert.False(await manager.RoleExists(role.Name)); - IdentityResultAssert.IsSuccess(await manager.Create(role)); - Assert.True(await manager.RoleExists(role.Name)); + Assert.False(await manager.RoleExistsAsync(role.Name)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); + Assert.True(await manager.RoleExistsAsync(role.Name)); role.Name = "Changed"; - IdentityResultAssert.IsSuccess(await manager.Update(role)); - Assert.False(await manager.RoleExists("update")); + IdentityResultAssert.IsSuccess(await manager.UpdateAsync(role)); + Assert.False(await manager.RoleExistsAsync("update")); Assert.Equal(role, await manager.FindByName(role.Name)); } @@ -813,7 +813,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (var r in roles) { - IdentityResultAssert.IsSuccess(await manager.Create(r)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(r)); } Assert.Equal(roles.Length, manager.Roles.Count()); var r1 = manager.Roles.FirstOrDefault(r => r.Name == "r1"); @@ -827,16 +827,16 @@ namespace Microsoft.AspNet.Identity.InMemory.Test // var userMgr = CreateManager(); // var roleMgr = CreateRoleManager(); // var role = new InMemoryRole("deleteNonEmpty"); - // Assert.False(await roleMgr.RoleExists(role.Name)); - // IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); + // Assert.False(await roleMgr.RoleExistsAsync(role.Name)); + // IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); // var user = new InMemoryUser("t"); - // IdentityResultAssert.IsSuccess(await userMgr.Create(user)); - // IdentityResultAssert.IsSuccess(await userMgr.AddToRole(user.Id, role.Name)); - // IdentityResultAssert.IsSuccess(await roleMgr.Delete(role)); - // Assert.Null(await roleMgr.FindByName(role.Name)); - // Assert.False(await roleMgr.RoleExists(role.Name)); + // IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); + // IdentityResultAssert.IsSuccess(await userMgr.AddToRoleAsync(user, role.Name)); + // IdentityResultAssert.IsSuccess(await roleMgr.DeleteAsync(role)); + // Assert.Null(await roleMgr.FindByNameAsync(role.Name)); + // Assert.False(await roleMgr.RoleExistsAsync(role.Name)); // // REVIEW: We should throw if deleteing a non empty role? - // var roles = await userMgr.GetRoles(user.Id); + // var roles = await userMgr.GetRolesAsync(user); // // In memory this doesn't work since there's no concept of cascading deletes // //Assert.Equal(0, roles.Count()); @@ -849,13 +849,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test //// var userMgr = CreateManager(); //// var roleMgr = CreateRoleManager(); //// var role = new InMemoryRole("deleteNonEmpty"); - //// Assert.False(await roleMgr.RoleExists(role.Name)); - //// IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); + //// Assert.False(await roleMgr.RoleExistsAsync(role.Name)); + //// IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); //// var user = new InMemoryUser("t"); - //// IdentityResultAssert.IsSuccess(await userMgr.Create(user)); - //// IdentityResultAssert.IsSuccess(await userMgr.AddToRole(user.Id, role.Name)); - //// IdentityResultAssert.IsSuccess(await userMgr.Delete(user)); - //// role = roleMgr.FindById(role.Id); + //// IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); + //// IdentityResultAssert.IsSuccess(await userMgr.AddToRoleAsync(user, role.Name)); + //// IdentityResultAssert.IsSuccess(await userMgr.DeleteAsync(user)); + //// role = roleMgr.FindByIdAsync(role.Id); ////} [Fact] @@ -863,11 +863,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateRoleManager(); var role = new InMemoryRole("dupeRole"); - Assert.False(await manager.RoleExists(role.Name)); - IdentityResultAssert.IsSuccess(await manager.Create(role)); - Assert.True(await manager.RoleExists(role.Name)); + Assert.False(await manager.RoleExistsAsync(role.Name)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(role)); + Assert.True(await manager.RoleExistsAsync(role.Name)); var role2 = new InMemoryRole("dupeRole"); - IdentityResultAssert.IsFailure(await manager.Create(role2)); + IdentityResultAssert.IsFailure(await manager.CreateAsync(role2)); } [Fact] @@ -876,7 +876,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); var roleManager = CreateRoleManager(); var role = new InMemoryRole("addUserTest"); - IdentityResultAssert.IsSuccess(await roleManager.Create(role)); + IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(role)); InMemoryUser[] users = { new InMemoryUser("1"), new InMemoryUser("2"), new InMemoryUser("3"), @@ -884,9 +884,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (var u in users) { - IdentityResultAssert.IsSuccess(await manager.Create(u)); - IdentityResultAssert.IsSuccess(await manager.AddToRole(u.Id, role.Name)); - Assert.True(await manager.IsInRole(u.Id, role.Name)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(u)); + IdentityResultAssert.IsSuccess(await manager.AddToRoleAsync(u, role.Name)); + Assert.True(await manager.IsInRoleAsync(u, role.Name)); } } @@ -907,21 +907,21 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (var u in users) { - IdentityResultAssert.IsSuccess(await userManager.Create(u)); + IdentityResultAssert.IsSuccess(await userManager.CreateAsync(u)); } foreach (var r in roles) { - IdentityResultAssert.IsSuccess(await roleManager.Create(r)); + IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(r)); foreach (var u in users) { - IdentityResultAssert.IsSuccess(await userManager.AddToRole(u.Id, r.Name)); - Assert.True(await userManager.IsInRole(u.Id, r.Name)); + IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(u, r.Name)); + Assert.True(await userManager.IsInRoleAsync(u, r.Name)); } } foreach (var u in users) { - var rs = await userManager.GetRoles(u.Id); + var rs = await userManager.GetRolesAsync(u); Assert.Equal(roles.Length, rs.Count); foreach (var r in roles) { @@ -937,7 +937,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var userManager = CreateManager(); var roleManager = CreateRoleManager(); var user = new InMemoryUser("MultiRoleUser"); - IdentityResultAssert.IsSuccess(await userManager.Create(user)); + IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user)); InMemoryRole[] roles = { new InMemoryRole("r1"), new InMemoryRole("r2"), new InMemoryRole("r3"), @@ -945,12 +945,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (var r in roles) { - IdentityResultAssert.IsSuccess(await roleManager.Create(r)); - IdentityResultAssert.IsSuccess(await userManager.AddToRole(user.Id, r.Name)); - Assert.True(await userManager.IsInRole(user.Id, r.Name)); + IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(r)); + IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(user, r.Name)); + Assert.True(await userManager.IsInRoleAsync(user, r.Name)); } - IdentityResultAssert.IsSuccess(await userManager.RemoveFromRole(user.Id, roles[2].Name)); - Assert.False(await userManager.IsInRole(user.Id, roles[2].Name)); + IdentityResultAssert.IsSuccess(await userManager.RemoveFromRoleAsync(user, roles[2].Name)); + Assert.False(await userManager.IsInRoleAsync(user, roles[2].Name)); } [Fact] @@ -965,19 +965,19 @@ namespace Microsoft.AspNet.Identity.InMemory.Test }; foreach (var u in users) { - IdentityResultAssert.IsSuccess(await userManager.Create(u)); + IdentityResultAssert.IsSuccess(await userManager.CreateAsync(u)); } var r = new InMemoryRole("r1"); - IdentityResultAssert.IsSuccess(await roleManager.Create(r)); + IdentityResultAssert.IsSuccess(await roleManager.CreateAsync(r)); foreach (var u in users) { - IdentityResultAssert.IsSuccess(await userManager.AddToRole(u.Id, r.Name)); - Assert.True(await userManager.IsInRole(u.Id, r.Name)); + IdentityResultAssert.IsSuccess(await userManager.AddToRoleAsync(u, r.Name)); + Assert.True(await userManager.IsInRoleAsync(u, r.Name)); } foreach (var u in users) { - IdentityResultAssert.IsSuccess(await userManager.RemoveFromRole(u.Id, r.Name)); - Assert.False(await userManager.IsInRole(u.Id, r.Name)); + IdentityResultAssert.IsSuccess(await userManager.RemoveFromRoleAsync(u, r.Name)); + Assert.False(await userManager.IsInRoleAsync(u, r.Name)); } } @@ -988,9 +988,9 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var roleMgr = CreateRoleManager(); var role = new InMemoryRole("addUserDupeTest"); var user = new InMemoryUser("user1"); - IdentityResultAssert.IsSuccess(await userMgr.Create(user)); - IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); - var result = await userMgr.RemoveFromRole(user.Id, role.Name); + IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); + var result = await userMgr.RemoveFromRoleAsync(user, role.Name); IdentityResultAssert.IsFailure(result, "User is not in role."); } @@ -1001,11 +1001,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var roleMgr = CreateRoleManager(); var role = new InMemoryRole("addUserDupeTest"); var user = new InMemoryUser("user1"); - IdentityResultAssert.IsSuccess(await userMgr.Create(user)); - IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); - IdentityResultAssert.IsSuccess(await userMgr.AddToRole(user.Id, role.Name)); - Assert.True(await userMgr.IsInRole(user.Id, role.Name)); - IdentityResultAssert.IsFailure(await userMgr.AddToRole(user.Id, role.Name), "User already in role."); + IdentityResultAssert.IsSuccess(await userMgr.CreateAsync(user)); + IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); + IdentityResultAssert.IsSuccess(await userMgr.AddToRoleAsync(user, role.Name)); + Assert.True(await userMgr.IsInRoleAsync(user, role.Name)); + IdentityResultAssert.IsFailure(await userMgr.AddToRoleAsync(user, role.Name), "User already in role."); } [Fact] @@ -1013,7 +1013,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var roleMgr = CreateRoleManager(); var role = new InMemoryRole("findRoleByNameTest"); - IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); + IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); Assert.Equal(role.Id, (await roleMgr.FindByName(role.Name)).Id); } @@ -1022,8 +1022,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var roleMgr = CreateRoleManager(); var role = new InMemoryRole("findRoleTest"); - IdentityResultAssert.IsSuccess(await roleMgr.Create(role)); - Assert.Equal(role.Name, (await roleMgr.FindById(role.Id)).Name); + IdentityResultAssert.IsSuccess(await roleMgr.CreateAsync(role)); + Assert.Equal(role.Name, (await roleMgr.FindByIdAsync(role.Id)).Name); } [Fact] @@ -1033,11 +1033,11 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var userName = "PhoneTest"; var user = new InMemoryUser(userName); user.PhoneNumber = "123-456-7890"; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - var stamp = await manager.GetSecurityStamp(user.Id); - Assert.Equal(await manager.GetPhoneNumber(user.Id), "123-456-7890"); - IdentityResultAssert.IsSuccess(await manager.SetPhoneNumber(user.Id, "111-111-1111")); - Assert.Equal(await manager.GetPhoneNumber(user.Id), "111-111-1111"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + var stamp = await manager.GetSecurityStampAsync(user); + Assert.Equal(await manager.GetPhoneNumberAsync(user), "123-456-7890"); + IdentityResultAssert.IsSuccess(await manager.SetPhoneNumberAsync(user, "111-111-1111")); + Assert.Equal(await manager.GetPhoneNumberAsync(user), "111-111-1111"); Assert.NotEqual(stamp, user.SecurityStamp); } @@ -1047,13 +1047,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); const string userName = "PhoneTest"; var user = new InMemoryUser(userName) {PhoneNumber = "123-456-7890"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - Assert.False(await manager.IsPhoneNumberConfirmed(user.Id)); - var stamp = await manager.GetSecurityStamp(user.Id); - var token1 = await manager.GenerateChangePhoneNumberToken(user.Id, "111-111-1111"); - IdentityResultAssert.IsSuccess(await manager.ChangePhoneNumber(user.Id, "111-111-1111", token1)); - Assert.True(await manager.IsPhoneNumberConfirmed(user.Id)); - Assert.Equal(await manager.GetPhoneNumber(user.Id), "111-111-1111"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + Assert.False(await manager.IsPhoneNumberConfirmedAsync(user)); + var stamp = await manager.GetSecurityStampAsync(user); + var token1 = await manager.GenerateChangePhoneNumberToken(user, "111-111-1111"); + IdentityResultAssert.IsSuccess(await manager.ChangePhoneNumberAsync(user, "111-111-1111", token1)); + Assert.True(await manager.IsPhoneNumberConfirmedAsync(user)); + Assert.Equal(await manager.GetPhoneNumberAsync(user), "111-111-1111"); Assert.NotEqual(stamp, user.SecurityStamp); } @@ -1063,13 +1063,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); const string userName = "PhoneTest"; var user = new InMemoryUser(userName) {PhoneNumber = "123-456-7890"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - Assert.False(await manager.IsPhoneNumberConfirmed(user.Id)); - var stamp = await manager.GetSecurityStamp(user.Id); - IdentityResultAssert.IsFailure(await manager.ChangePhoneNumber(user.Id, "111-111-1111", "bogus"), + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + Assert.False(await manager.IsPhoneNumberConfirmedAsync(user)); + var stamp = await manager.GetSecurityStampAsync(user); + IdentityResultAssert.IsFailure(await manager.ChangePhoneNumberAsync(user, "111-111-1111", "bogus"), "Invalid token."); - Assert.False(await manager.IsPhoneNumberConfirmed(user.Id)); - Assert.Equal(await manager.GetPhoneNumber(user.Id), "123-456-7890"); + Assert.False(await manager.IsPhoneNumberConfirmedAsync(user)); + Assert.Equal(await manager.GetPhoneNumberAsync(user), "123-456-7890"); Assert.Equal(stamp, user.SecurityStamp); } @@ -1079,39 +1079,39 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var manager = CreateManager(); const string userName = "VerifyPhoneTest"; var user = new InMemoryUser(userName); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); const string num1 = "111-123-4567"; const string num2 = "111-111-1111"; - var token1 = await manager.GenerateChangePhoneNumberToken(user.Id, num1); - var token2 = await manager.GenerateChangePhoneNumberToken(user.Id, num2); + var token1 = await manager.GenerateChangePhoneNumberToken(user, num1); + var token2 = await manager.GenerateChangePhoneNumberToken(user, num2); Assert.NotEqual(token1, token2); - Assert.True(await manager.VerifyChangePhoneNumberToken(user.Id, token1, num1)); - Assert.True(await manager.VerifyChangePhoneNumberToken(user.Id, token2, num2)); - Assert.False(await manager.VerifyChangePhoneNumberToken(user.Id, token2, num1)); - Assert.False(await manager.VerifyChangePhoneNumberToken(user.Id, token1, num2)); + Assert.True(await manager.VerifyChangePhoneNumberTokenAsync(user, token1, num1)); + Assert.True(await manager.VerifyChangePhoneNumberTokenAsync(user, token2, num2)); + Assert.False(await manager.VerifyChangePhoneNumberTokenAsync(user, token2, num1)); + Assert.False(await manager.VerifyChangePhoneNumberTokenAsync(user, token1, num2)); } private class EmailTokenProvider : IUserTokenProvider { - public Task Generate(string purpose, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GenerateAsync(string purpose, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(MakeToken(purpose)); } - public Task Validate(string purpose, string token, UserManager manager, + public Task ValidateAsync(string purpose, string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(token == MakeToken(purpose)); } - public Task Notify(string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task NotifyAsync(string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { - return manager.SendEmail(user.Id, token, token); + return manager.SendEmail(user, token, token); } - public async Task IsValidProviderForUser(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public async Task IsValidProviderForUserAsync(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { - return !string.IsNullOrEmpty(await manager.GetEmail(user.Id)); + return !string.IsNullOrEmpty(await manager.GetEmailAsync(user)); } private static string MakeToken(string purpose) @@ -1122,25 +1122,25 @@ namespace Microsoft.AspNet.Identity.InMemory.Test private class SmsTokenProvider : IUserTokenProvider { - public Task Generate(string purpose, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GenerateAsync(string purpose, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(MakeToken(purpose)); } - public Task Validate(string purpose, string token, UserManager manager, + public Task ValidateAsync(string purpose, string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(token == MakeToken(purpose)); } - public Task Notify(string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task NotifyAsync(string token, UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { - return manager.SendSms(user.Id, token, cancellationToken); + return manager.SendSms(user, token, cancellationToken); } - public async Task IsValidProviderForUser(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) + public async Task IsValidProviderForUserAsync(UserManager manager, InMemoryUser user, CancellationToken cancellationToken = default(CancellationToken)) { - return !string.IsNullOrEmpty(await manager.GetPhoneNumber(user.Id, cancellationToken)); + return !string.IsNullOrEmpty(await manager.GetPhoneNumberAsync(user, cancellationToken)); } private static string MakeToken(string purpose) @@ -1159,17 +1159,17 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.RegisterTwoFactorProvider(factorId, new EmailTokenProvider()); var user = new InMemoryUser("EmailCodeTest") {Email = "foo@foo.com"}; const string password = "password"; - IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - var token = await manager.GenerateTwoFactorToken(user.Id, factorId); + var token = await manager.GenerateTwoFactorTokenAsync(user, factorId); Assert.NotNull(token); Assert.Null(messageService.Message); - IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); + IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user, factorId, token)); Assert.NotNull(messageService.Message); Assert.Equal(token, messageService.Message.Subject); Assert.Equal(token, messageService.Message.Body); - Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); + Assert.True(await manager.VerifyTwoFactorTokenAsync(user, factorId, token)); } [Fact] @@ -1177,10 +1177,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("NotifyFail"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); await ExceptionAssert.ThrowsAsync( - async () => await manager.NotifyTwoFactorToken(user.Id, "Bogus", "token"), + async () => await manager.NotifyTwoFactorTokenAsync(user, "Bogus", "token"), "No IUserTwoFactorProvider for 'Bogus' is registered."); } @@ -1199,17 +1199,17 @@ namespace Microsoft.AspNet.Identity.InMemory.Test // }); // var user = new InMemoryUser("EmailCodeTest") { Email = "foo@foo.com" }; // const string password = "password"; - // IdentityResultAssert.IsSuccess(await manager.Create(user, password)); + // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user, password)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); - // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); + // var token = await manager.GenerateTwoFactorTokenAsync(user, factorId); // Assert.NotNull(token); // Assert.Null(messageService.Message); - // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); + // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user, factorId, token)); // Assert.NotNull(messageService.Message); // Assert.Equal("Security Code", messageService.Message.Subject); // Assert.Equal("Your code is: " + token, messageService.Message.Body); - // Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); + // Assert.True(await manager.VerifyTwoFactorTokenAsync(user, factorId, token)); //} //[Fact] @@ -1219,13 +1219,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test // const string factorId = "EmailCode"; // manager.RegisterTwoFactorProvider(factorId, new EmailTokenProvider()); // var user = new InMemoryUser("EmailCodeTest") { Email = "foo@foo.com" }; - // IdentityResultAssert.IsSuccess(await manager.Create(user)); + // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); - // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); + // var token = await manager.GenerateTwoFactorTokenAsync(user, factorId); // Assert.NotNull(token); - // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStamp(user.Id)); - // Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); + // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStampAsync(user)); + // Assert.False(await manager.VerifyTwoFactorTokenAsync(user, factorId, token)); //} [Fact] @@ -1233,12 +1233,12 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("TwoFactorEnabledTest"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - IdentityResultAssert.IsSuccess(await manager.SetTwoFactorEnabled(user.Id, true)); - Assert.NotEqual(stamp, await manager.GetSecurityStamp(user.Id)); - Assert.True(await manager.GetTwoFactorEnabled(user.Id)); + IdentityResultAssert.IsSuccess(await manager.SetTwoFactorEnabledAsync(user, true)); + Assert.NotEqual(stamp, await manager.GetSecurityStampAsync(user)); + Assert.True(await manager.GetTwoFactorEnabled(user)); } [Fact] @@ -1248,8 +1248,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var messageService = new TestMessageService(); manager.SmsService = messageService; var user = new InMemoryUser("SmsTest") {PhoneNumber = "4251234567"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - await manager.SendSms(user.Id, "Hi"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + await manager.SendSms(user, "Hi"); Assert.NotNull(messageService.Message); Assert.Equal("Hi", messageService.Message.Body); } @@ -1261,8 +1261,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test var messageService = new TestMessageService(); manager.EmailService = messageService; var user = new InMemoryUser("EmailTest") {Email = "foo@foo.com"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - await manager.SendEmail(user.Id, "Hi", "Body"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + await manager.SendEmail(user, "Hi", "Body"); Assert.NotNull(messageService.Message); Assert.Equal("Hi", messageService.Message.Subject); Assert.Equal("Body", messageService.Message.Body); @@ -1277,16 +1277,16 @@ namespace Microsoft.AspNet.Identity.InMemory.Test const string factorId = "PhoneCode"; manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider()); var user = new InMemoryUser("PhoneCodeTest") {PhoneNumber = "4251234567"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); var stamp = user.SecurityStamp; Assert.NotNull(stamp); - var token = await manager.GenerateTwoFactorToken(user.Id, factorId); + var token = await manager.GenerateTwoFactorTokenAsync(user, factorId); Assert.NotNull(token); Assert.Null(messageService.Message); - IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); + IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user, factorId, token)); Assert.NotNull(messageService.Message); Assert.Equal(token, messageService.Message.Body); - Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); + Assert.True(await manager.VerifyTwoFactorTokenAsync(user, factorId, token)); } //[Fact] @@ -1301,16 +1301,16 @@ namespace Microsoft.AspNet.Identity.InMemory.Test // MessageFormat = "Your code is: {0}" // }); // var user = new InMemoryUser("PhoneCodeTest") { PhoneNumber = "4251234567" }; - // IdentityResultAssert.IsSuccess(await manager.Create(user)); + // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); - // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); + // var token = await manager.GenerateTwoFactorTokenAsync(user, factorId); // Assert.NotNull(token); // Assert.Null(messageService.Message); - // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorToken(user.Id, factorId, token)); + // IdentityResultAssert.IsSuccess(await manager.NotifyTwoFactorTokenAsync(user, factorId, token)); // Assert.NotNull(messageService.Message); // Assert.Equal("Your code is: " + token, messageService.Message.Body); - // Assert.True(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); + // Assert.True(await manager.VerifyTwoFactorTokenAsync(user, factorId, token)); //} [Fact] @@ -1318,13 +1318,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("PhoneCodeTest"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); const string error = "No IUserTwoFactorProvider for 'bogus' is registered."; await ExceptionAssert.ThrowsAsync( - () => manager.GenerateTwoFactorToken(user.Id, "bogus"), error); + () => manager.GenerateTwoFactorTokenAsync(user, "bogus"), error); await ExceptionAssert.ThrowsAsync( - () => manager.VerifyTwoFactorToken(user.Id, "bogus", "bogus"), error); + () => manager.VerifyTwoFactorTokenAsync(user, "bogus", "bogus"), error); } [Fact] @@ -1332,8 +1332,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { var manager = CreateManager(); var user = new InMemoryUser("test"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - var factors = await manager.GetValidTwoFactorProviders(user.Id); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + var factors = await manager.GetValidTwoFactorProviders(user); Assert.NotNull(factors); Assert.True(!factors.Any()); } @@ -1345,21 +1345,21 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.RegisterTwoFactorProvider("phone", new SmsTokenProvider()); manager.RegisterTwoFactorProvider("email", new EmailTokenProvider()); var user = new InMemoryUser("test"); - IdentityResultAssert.IsSuccess(await manager.Create(user)); - var factors = await manager.GetValidTwoFactorProviders(user.Id); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + var factors = await manager.GetValidTwoFactorProviders(user); Assert.NotNull(factors); Assert.True(!factors.Any()); - IdentityResultAssert.IsSuccess(await manager.SetPhoneNumber(user.Id, "111-111-1111")); - factors = await manager.GetValidTwoFactorProviders(user.Id); + IdentityResultAssert.IsSuccess(await manager.SetPhoneNumberAsync(user, "111-111-1111")); + factors = await manager.GetValidTwoFactorProviders(user); Assert.NotNull(factors); Assert.True(factors.Count() == 1); Assert.Equal("phone", factors[0]); - IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, "test@test.com")); - factors = await manager.GetValidTwoFactorProviders(user.Id); + IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user, "test@test.com")); + factors = await manager.GetValidTwoFactorProviders(user); Assert.NotNull(factors); Assert.True(factors.Count() == 2); - IdentityResultAssert.IsSuccess(await manager.SetEmail(user.Id, null)); - factors = await manager.GetValidTwoFactorProviders(user.Id); + IdentityResultAssert.IsSuccess(await manager.SetEmailAsync(user, null)); + factors = await manager.GetValidTwoFactorProviders(user); Assert.NotNull(factors); Assert.True(factors.Count() == 1); Assert.Equal("phone", factors[0]); @@ -1373,13 +1373,13 @@ namespace Microsoft.AspNet.Identity.InMemory.Test // manager.RegisterTwoFactorProvider(factorId, new PhoneNumberTokenProvider()); // var user = new InMemoryUser("PhoneCodeTest"); // user.PhoneNumber = "4251234567"; - // IdentityResultAssert.IsSuccess(await manager.Create(user)); + // IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); // var stamp = user.SecurityStamp; // Assert.NotNull(stamp); - // var token = await manager.GenerateTwoFactorToken(user.Id, factorId); + // var token = await manager.GenerateTwoFactorTokenAsync(user, factorId); // Assert.NotNull(token); - // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStamp(user.Id)); - // Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, token)); + // IdentityResultAssert.IsSuccess(await manager.UpdateSecurityStampAsync(user)); + // Assert.False(await manager.VerifyTwoFactorTokenAsync(user, factorId, token)); //} [Fact] @@ -1389,10 +1389,10 @@ namespace Microsoft.AspNet.Identity.InMemory.Test manager.RegisterTwoFactorProvider("PhoneCode", new SmsTokenProvider()); manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider()); var user = new InMemoryUser("WrongTokenProviderTest") {PhoneNumber = "4251234567"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - var token = await manager.GenerateTwoFactorToken(user.Id, "PhoneCode"); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + var token = await manager.GenerateTwoFactorTokenAsync(user, "PhoneCode"); Assert.NotNull(token); - Assert.False(await manager.VerifyTwoFactorToken(user.Id, "EmailCode", token)); + Assert.False(await manager.VerifyTwoFactorTokenAsync(user, "EmailCode", token)); } [Fact] @@ -1402,8 +1402,8 @@ namespace Microsoft.AspNet.Identity.InMemory.Test const string factorId = "PhoneCode"; manager.RegisterTwoFactorProvider(factorId, new SmsTokenProvider()); var user = new InMemoryUser("PhoneCodeTest") {PhoneNumber = "4251234567"}; - IdentityResultAssert.IsSuccess(await manager.Create(user)); - Assert.False(await manager.VerifyTwoFactorToken(user.Id, factorId, "bogus")); + IdentityResultAssert.IsSuccess(await manager.CreateAsync(user)); + Assert.False(await manager.VerifyTwoFactorTokenAsync(user, factorId, "bogus")); } private static UserManager CreateManager() @@ -1420,7 +1420,7 @@ namespace Microsoft.AspNet.Identity.InMemory.Test { public IdentityMessage Message { get; set; } - public Task Send(IdentityMessage message, CancellationToken cancellationToken = default(CancellationToken)) + public Task SendAsync(IdentityMessage message, CancellationToken cancellationToken = default(CancellationToken)) { Message = message; return Task.FromResult(0); diff --git a/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs b/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs index e3141d7962..baa80813c5 100644 --- a/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs +++ b/test/Microsoft.AspNet.Identity.Security.Test/SignInManagerTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Identity.Security.Test var identityFactory = new Mock>(); const string authType = "Test"; var testIdentity = new ClaimsIdentity(authType); - identityFactory.Setup(s => s.Create(userManager, user, authType, CancellationToken.None)).ReturnsAsync(testIdentity).Verifiable(); + identityFactory.Setup(s => s.CreateAsync(userManager, user, authType, CancellationToken.None)).ReturnsAsync(testIdentity).Verifiable(); userManager.ClaimsIdentityFactory = identityFactory.Object; var context = new Mock(); var response = new Mock(); @@ -44,12 +44,12 @@ namespace Microsoft.AspNet.Identity.Security.Test // Setup var user = new TestUser { UserName = "Foo" }; var manager = new Mock>(); - manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(true).Verifiable(); - manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); + manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(true).Verifiable(); + manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); var helper = new SignInManager { UserManager = manager.Object }; // Act - var result = await helper.PasswordSignIn(user.UserName, "bogus", false, false); + var result = await helper.PasswordSignInAsync(user.UserName, "bogus", false, false); // Assert Assert.Equal(SignInStatus.LockedOut, result); @@ -62,9 +62,9 @@ namespace Microsoft.AspNet.Identity.Security.Test // Setup var user = new TestUser { UserName = "Foo" }; var manager = new Mock>(); - manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(false).Verifiable(); - manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); - manager.Setup(m => m.CheckPassword(user, "password", CancellationToken.None)).ReturnsAsync(true).Verifiable(); + manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(false).Verifiable(); + manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); + manager.Setup(m => m.CheckPasswordAsync(user, "password", CancellationToken.None)).ReturnsAsync(true).Verifiable(); manager.Setup(m => m.CreateIdentity(user, "Microsoft.AspNet.Identity", CancellationToken.None)).ReturnsAsync(new ClaimsIdentity("Microsoft.AspNet.Identity")).Verifiable(); var context = new Mock(); var response = new Mock(); @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Identity.Security.Test var helper = new SignInManager { UserManager = manager.Object, Context = context.Object }; // Act - var result = await helper.PasswordSignIn(user.UserName, "password", false, false); + var result = await helper.PasswordSignInAsync(user.UserName, "password", false, false); // Assert Assert.Equal(SignInStatus.Success, result); @@ -86,13 +86,13 @@ namespace Microsoft.AspNet.Identity.Security.Test // Setup var user = new TestUser { UserName = "Foo" }; var manager = new Mock>(); - manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(false).Verifiable(); - manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); - manager.Setup(m => m.CheckPassword(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable(); + manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(false).Verifiable(); + manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); + manager.Setup(m => m.CheckPasswordAsync(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable(); var helper = new SignInManager { UserManager = manager.Object }; // Act - var result = await helper.PasswordSignIn(user.UserName, "bogus", false, false); + var result = await helper.PasswordSignInAsync(user.UserName, "bogus", false, false); // Assert Assert.Equal(SignInStatus.Failure, result); @@ -105,11 +105,11 @@ namespace Microsoft.AspNet.Identity.Security.Test { // Setup var manager = new Mock>(); - manager.Setup(m => m.FindByName("bogus", CancellationToken.None)).ReturnsAsync(null).Verifiable(); + manager.Setup(m => m.FindByNameAsync("bogus", CancellationToken.None)).ReturnsAsync(null).Verifiable(); var helper = new SignInManager { UserManager = manager.Object }; // Act - var result = await helper.PasswordSignIn("bogus", "bogus", false, false); + var result = await helper.PasswordSignInAsync("bogus", "bogus", false, false); // Assert Assert.Equal(SignInStatus.Failure, result); @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Identity.Security.Test var helper = new SignInManager(); // Act - var result = await helper.PasswordSignIn("bogus", "bogus", false, false); + var result = await helper.PasswordSignInAsync("bogus", "bogus", false, false); // Assert Assert.Equal(SignInStatus.Failure, result); @@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Identity.Security.Test var helper = new SignInManager(); // Act - var result = await helper.CreateUserIdentity(user); + var result = await helper.CreateUserIdentityAsync(user); // Assert Assert.Null(result); @@ -151,18 +151,18 @@ namespace Microsoft.AspNet.Identity.Security.Test var user = new TestUser { UserName = "Foo" }; var manager = new Mock>(); var lockedout = false; - manager.Setup(m => m.AccessFailed(user.Id, CancellationToken.None)).Returns(() => + manager.Setup(m => m.AccessFailedAsync(user, CancellationToken.None)).Returns(() => { lockedout = true; return Task.FromResult(IdentityResult.Success); }).Verifiable(); - manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).Returns(() => Task.FromResult(lockedout)); - manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); - manager.Setup(m => m.CheckPassword(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable(); + manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).Returns(() => Task.FromResult(lockedout)); + manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable(); + manager.Setup(m => m.CheckPasswordAsync(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable(); var helper = new SignInManager { UserManager = manager.Object }; // Act - var result = await helper.PasswordSignIn(user.UserName, "bogus", false, true); + var result = await helper.PasswordSignInAsync(user.UserName, "bogus", false, true); // Assert Assert.Equal(SignInStatus.LockedOut, result); diff --git a/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs b/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs index 2826fc46ab..3b33e49b68 100644 --- a/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/ClaimsIdentityFactoryTest.cs @@ -16,11 +16,11 @@ namespace Microsoft.AspNet.Identity.Test var factory = new ClaimsIdentityFactory(); var manager = new UserManager(new NoopUserStore()); await Assert.ThrowsAsync("manager", - async () => await factory.Create(null, null, "whatever")); + async () => await factory.CreateAsync(null, null, "whatever")); await Assert.ThrowsAsync("user", - async () => await factory.Create(manager, null, "whatever")); + async () => await factory.CreateAsync(manager, null, "whatever")); await Assert.ThrowsAsync("value", - async () => await factory.Create(manager, new TestUser(), null)); + async () => await factory.CreateAsync(manager, new TestUser(), null)); } #if NET45 @@ -37,18 +37,18 @@ namespace Microsoft.AspNet.Identity.Test var user = new TestUser { UserName = "Foo" }; userManager.Setup(m => m.SupportsUserRole).Returns(supportRoles); userManager.Setup(m => m.SupportsUserClaim).Returns(supportClaims); - userManager.Setup(m => m.GetUserId(user, CancellationToken.None)).ReturnsAsync(user.Id); - userManager.Setup(m => m.GetUserName(user, CancellationToken.None)).ReturnsAsync(user.UserName); + userManager.Setup(m => m.GetUserIdAsync(user, CancellationToken.None)).ReturnsAsync(user.Id); + userManager.Setup(m => m.GetUserNameAsync(user, CancellationToken.None)).ReturnsAsync(user.UserName); var roleClaims = new[] { "Admin", "Local" }; - userManager.Setup(m => m.GetRoles(user.Id, CancellationToken.None)).ReturnsAsync(roleClaims); + userManager.Setup(m => m.GetRolesAsync(user, CancellationToken.None)).ReturnsAsync(roleClaims); var userClaims = new[] { new Claim("Whatever", "Value"), new Claim("Whatever2", "Value2") }; - userManager.Setup(m => m.GetClaims(user.Id, CancellationToken.None)).ReturnsAsync(userClaims); + userManager.Setup(m => m.GetClaimsAsync(user, CancellationToken.None)).ReturnsAsync(userClaims); const string authType = "Microsoft.AspNet.Identity"; var factory = new ClaimsIdentityFactory(); // Act - var identity = await factory.Create(userManager.Object, user, authType); + var identity = await factory.CreateAsync(userManager.Object, user, authType); // Assert Assert.NotNull(identity); diff --git a/test/Microsoft.AspNet.Identity.Test/NoopRoleStore.cs b/test/Microsoft.AspNet.Identity.Test/NoopRoleStore.cs index f6c70e2511..a504c9c56b 100644 --- a/test/Microsoft.AspNet.Identity.Test/NoopRoleStore.cs +++ b/test/Microsoft.AspNet.Identity.Test/NoopRoleStore.cs @@ -5,27 +5,27 @@ namespace Microsoft.AspNet.Identity.Test { public class NoopRoleStore : IRoleStore { - public Task Create(TestRole user, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateAsync(TestRole user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task Update(TestRole user, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TestRole user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetRoleName(TestRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleNameAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(null); } - public Task FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } @@ -34,12 +34,12 @@ namespace Microsoft.AspNet.Identity.Test { } - public Task Delete(TestRole user, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TestRole user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetRoleId(TestRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleIdAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(null); } diff --git a/test/Microsoft.AspNet.Identity.Test/NoopUserStore.cs b/test/Microsoft.AspNet.Identity.Test/NoopUserStore.cs index d9b54af6d1..2c1ed18e42 100644 --- a/test/Microsoft.AspNet.Identity.Test/NoopUserStore.cs +++ b/test/Microsoft.AspNet.Identity.Test/NoopUserStore.cs @@ -5,32 +5,37 @@ namespace Microsoft.AspNet.Identity.Test { public class NoopUserStore : IUserStore { - public Task GetUserId(TestUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserIdAsync(TestUser user, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(user.Id); } - public Task GetUserName(TestUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserNameAsync(TestUser user, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(user.UserName); } - public Task Create(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetUserNameAsync(TestUser user, string userName, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(0); } - public Task Update(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + { + return Task.FromResult(0); + } + + public Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } @@ -39,7 +44,7 @@ namespace Microsoft.AspNet.Identity.Test { } - public Task Delete(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } diff --git a/test/Microsoft.AspNet.Identity.Test/PasswordValidatorTest.cs b/test/Microsoft.AspNet.Identity.Test/PasswordValidatorTest.cs index 377f2bd3f3..8deb9a6af1 100644 --- a/test/Microsoft.AspNet.Identity.Test/PasswordValidatorTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/PasswordValidatorTest.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity.Test // Act // Assert - await Assert.ThrowsAsync(() => validator.Validate(null)); + await Assert.ThrowsAsync(() => validator.ValidateAsync(null)); } @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Identity.Test { const string error = "Passwords must be at least 6 characters."; var valid = new PasswordValidator {RequiredLength = 6}; - IdentityResultAssert.IsFailure(await valid.Validate(input), error); + IdentityResultAssert.IsFailure(await valid.ValidateAsync(input), error); } [Theory] @@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Identity.Test public async Task SuccessIfLongEnoughTests(string input) { var valid = new PasswordValidator {RequiredLength = 6}; - IdentityResultAssert.IsSuccess(await valid.Validate(input)); + IdentityResultAssert.IsSuccess(await valid.ValidateAsync(input)); } [Theory] @@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Identity.Test public async Task FailsWithoutRequiredNonAlphanumericTests(string input) { var valid = new PasswordValidator {RequireNonLetterOrDigit = true}; - IdentityResultAssert.IsFailure(await valid.Validate(input), + IdentityResultAssert.IsFailure(await valid.ValidateAsync(input), "Passwords must have at least one non letter or digit character."); } @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Identity.Test public async Task SucceedsWithRequiredNonAlphanumericTests(string input) { var valid = new PasswordValidator {RequireNonLetterOrDigit = true}; - IdentityResultAssert.IsSuccess(await valid.Validate(input)); + IdentityResultAssert.IsSuccess(await valid.ValidateAsync(input)); } [Theory] @@ -115,11 +115,11 @@ namespace Microsoft.AspNet.Identity.Test } if (errors.Count == 0) { - IdentityResultAssert.IsSuccess(await valid.Validate(input)); + IdentityResultAssert.IsSuccess(await valid.ValidateAsync(input)); } else { - IdentityResultAssert.IsFailure(await valid.Validate(input), string.Join(" ", errors)); + IdentityResultAssert.IsFailure(await valid.ValidateAsync(input), string.Join(" ", errors)); } } } diff --git a/test/Microsoft.AspNet.Identity.Test/RoleManagerTest.cs b/test/Microsoft.AspNet.Identity.Test/RoleManagerTest.cs index 2d2cfbd503..61b4144936 100644 --- a/test/Microsoft.AspNet.Identity.Test/RoleManagerTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/RoleManagerTest.cs @@ -36,11 +36,11 @@ namespace Microsoft.AspNet.Identity.Test Assert.Throws("store", () => new RoleManager(null)); var manager = new RoleManager(new NotImplementedStore()); - await Assert.ThrowsAsync("role", async () => await manager.Create(null)); - await Assert.ThrowsAsync("role", async () => await manager.Update(null)); - await Assert.ThrowsAsync("role", async () => await manager.Delete(null)); + await Assert.ThrowsAsync("role", async () => await manager.CreateAsync(null)); + await Assert.ThrowsAsync("role", async () => await manager.UpdateAsync(null)); + await Assert.ThrowsAsync("role", async () => await manager.DeleteAsync(null)); await Assert.ThrowsAsync("roleName", async () => await manager.FindByName(null)); - await Assert.ThrowsAsync("roleName", async () => await manager.RoleExists(null)); + await Assert.ThrowsAsync("roleName", async () => await manager.RoleExistsAsync(null)); } [Fact] @@ -48,47 +48,47 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new RoleManager(new NoopRoleStore()); manager.Dispose(); - await Assert.ThrowsAsync(() => manager.FindById(null)); + await Assert.ThrowsAsync(() => manager.FindByIdAsync(null)); await Assert.ThrowsAsync(() => manager.FindByName(null)); - await Assert.ThrowsAsync(() => manager.RoleExists(null)); - await Assert.ThrowsAsync(() => manager.Create(null)); - await Assert.ThrowsAsync(() => manager.Update(null)); - await Assert.ThrowsAsync(() => manager.Delete(null)); + await Assert.ThrowsAsync(() => manager.RoleExistsAsync(null)); + await Assert.ThrowsAsync(() => manager.CreateAsync(null)); + await Assert.ThrowsAsync(() => manager.UpdateAsync(null)); + await Assert.ThrowsAsync(() => manager.DeleteAsync(null)); } private class NotImplementedStore : IRoleStore { - public Task Create(TestRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task Update(TestRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task Delete(TestRole role, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetRoleId(TestRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleIdAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); } - public Task GetRoleName(TestRole role, CancellationToken cancellationToken = new CancellationToken()) + public Task GetRoleNameAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); } - public Task FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task FindByName(string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNet.Identity.Test/RoleValidatorTest.cs b/test/Microsoft.AspNet.Identity.Test/RoleValidatorTest.cs index 4bf573a88d..2b6e67ef5b 100644 --- a/test/Microsoft.AspNet.Identity.Test/RoleValidatorTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/RoleValidatorTest.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNet.Identity.Test // Act // Assert - await Assert.ThrowsAsync("manager", async () => await validator.Validate(null, null)); - await Assert.ThrowsAsync("role", async () => await validator.Validate(manager, null)); + await Assert.ThrowsAsync("manager", async () => await validator.ValidateAsync(null, null)); + await Assert.ThrowsAsync("role", async () => await validator.ValidateAsync(manager, null)); } [Theory] @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Identity.Test var user = new TestRole {Name = input}; // Act - var result = await validator.Validate(manager, user); + var result = await validator.ValidateAsync(manager, user); // Assert IdentityResultAssert.IsFailure(result, "Name cannot be null or empty."); diff --git a/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs b/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs index 32e40a73f8..f023efcd8e 100644 --- a/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/UserManagerTest.cs @@ -38,14 +38,14 @@ namespace Microsoft.AspNet.Identity.Test // Setup var store = new Mock>(); var user = new TestUser { UserName = "Foo" }; - store.Setup(s => s.Create(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); + store.Setup(s => s.CreateAsync(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); var validator = new Mock>(); var userManager = new UserManager(store.Object); - validator.Setup(v => v.Validate(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); + validator.Setup(v => v.ValidateAsync(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); userManager.UserValidator = validator.Object; // Act - var result = await userManager.Create(user); + var result = await userManager.CreateAsync(user); // Assert Assert.True(result.Succeeded); @@ -58,11 +58,11 @@ namespace Microsoft.AspNet.Identity.Test // Setup var store = new Mock>(); var user = new TestUser { UserName = "Foo" }; - store.Setup(s => s.Delete(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); + store.Setup(s => s.DeleteAsync(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); var userManager = new UserManager(store.Object); // Act - var result = await userManager.Delete(user); + var result = await userManager.DeleteAsync(user); // Assert Assert.True(result.Succeeded); @@ -75,14 +75,34 @@ namespace Microsoft.AspNet.Identity.Test // Setup var store = new Mock>(); var user = new TestUser { UserName = "Foo" }; - store.Setup(s => s.Update(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); + store.Setup(s => s.UpdateAsync(user, CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); var validator = new Mock>(); var userManager = new UserManager(store.Object); - validator.Setup(v => v.Validate(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); + validator.Setup(v => v.ValidateAsync(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); userManager.UserValidator = validator.Object; // Act - var result = await userManager.Update(user); + var result = await userManager.UpdateAsync(user); + + // Assert + Assert.True(result.Succeeded); + store.VerifyAll(); + } + + [Fact] + public async Task SetUserNameCallsStore() + { + // Setup + var store = new Mock>(); + var user = new TestUser(); + store.Setup(s => s.SetUserNameAsync(user, It.IsAny(), CancellationToken.None)).Returns(Task.FromResult(0)).Verifiable(); + var validator = new Mock>(); + var userManager = new UserManager(store.Object); + validator.Setup(v => v.ValidateAsync(userManager, user, CancellationToken.None)).Returns(Task.FromResult(IdentityResult.Success)).Verifiable(); + userManager.UserValidator = validator.Object; + + // Act + var result = await userManager.SetUserName(user, "foo"); // Assert Assert.True(result.Succeeded); @@ -95,11 +115,11 @@ namespace Microsoft.AspNet.Identity.Test // Setup var store = new Mock>(); var user = new TestUser { UserName = "Foo" }; - store.Setup(s => s.FindById(user.Id, CancellationToken.None)).Returns(Task.FromResult(user)).Verifiable(); + store.Setup(s => s.FindByIdAsync(user.Id, CancellationToken.None)).Returns(Task.FromResult(user)).Verifiable(); var userManager = new UserManager(store.Object); // Act - var result = await userManager.FindById(user.Id); + var result = await userManager.FindByIdAsync(user.Id); // Assert Assert.Equal(user, result); @@ -112,11 +132,11 @@ namespace Microsoft.AspNet.Identity.Test // Setup var store = new Mock>(); var user = new TestUser {UserName="Foo"}; - store.Setup(s => s.FindByName(user.UserName, CancellationToken.None)).Returns(Task.FromResult(user)).Verifiable(); + store.Setup(s => s.FindByNameAsync(user.UserName, CancellationToken.None)).Returns(Task.FromResult(user)).Verifiable(); var userManager = new UserManager(store.Object); // Act - var result = await userManager.FindByName(user.UserName); + var result = await userManager.FindByNameAsync(user.UserName); // Assert Assert.Equal(user, result); @@ -129,14 +149,14 @@ namespace Microsoft.AspNet.Identity.Test public async Task CheckPasswordWithNullUserReturnsFalse() { var manager = new UserManager(new EmptyStore()); - Assert.False(await manager.CheckPassword(null, "whatevs")); + Assert.False(await manager.CheckPasswordAsync(null, "whatevs")); } [Fact] public async Task FindWithUnknownUserAndPasswordReturnsNull() { var manager = new UserManager(new EmptyStore()); - Assert.Null(await manager.Find("bogus", "whatevs")); + Assert.Null(await manager.FindByUserNamePassword("bogus", "whatevs")); } [Fact] @@ -152,11 +172,11 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserEmail); - await Assert.ThrowsAsync(() => manager.FindByEmail(null)); - await Assert.ThrowsAsync(() => manager.SetEmail(null, null)); - await Assert.ThrowsAsync(() => manager.GetEmail(null)); - await Assert.ThrowsAsync(() => manager.IsEmailConfirmed(null)); - await Assert.ThrowsAsync(() => manager.ConfirmEmail(null, null)); + await Assert.ThrowsAsync(() => manager.FindByEmailAsync(null)); + await Assert.ThrowsAsync(() => manager.SetEmailAsync(null, null)); + await Assert.ThrowsAsync(() => manager.GetEmailAsync(null)); + await Assert.ThrowsAsync(() => manager.IsEmailConfirmedAsync(null)); + await Assert.ThrowsAsync(() => manager.ConfirmEmailAsync(null, null)); } [Fact] @@ -164,9 +184,9 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserPhoneNumber); - await Assert.ThrowsAsync(async () => await manager.SetPhoneNumber(null, null)); - await Assert.ThrowsAsync(async () => await manager.SetPhoneNumber(null, null)); - await Assert.ThrowsAsync(async () => await manager.GetPhoneNumber(null)); + await Assert.ThrowsAsync(async () => await manager.SetPhoneNumberAsync(null, null)); + await Assert.ThrowsAsync(async () => await manager.SetPhoneNumberAsync(null, null)); + await Assert.ThrowsAsync(async () => await manager.GetPhoneNumberAsync(null)); } [Fact] @@ -174,9 +194,9 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); await Assert.ThrowsAsync( - async () => await manager.GenerateUserToken(null, null)); + async () => await manager.GenerateUserTokenAsync(null, null)); await Assert.ThrowsAsync( - async () => await manager.VerifyUserToken(null, null, null)); + async () => await manager.VerifyUserTokenAsync(null, null, null)); } [Fact] @@ -184,12 +204,12 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserPassword); - await Assert.ThrowsAsync(() => manager.Create(null, null)); - await Assert.ThrowsAsync(() => manager.ChangePassword(null, null, null)); - await Assert.ThrowsAsync(() => manager.AddPassword(null, null)); - await Assert.ThrowsAsync(() => manager.RemovePassword(null)); - await Assert.ThrowsAsync(() => manager.CheckPassword(null, null)); - await Assert.ThrowsAsync(() => manager.HasPassword(null)); + await Assert.ThrowsAsync(() => manager.CreateAsync(null, null)); + await Assert.ThrowsAsync(() => manager.ChangePasswordAsync(null, null, null)); + await Assert.ThrowsAsync(() => manager.AddPasswordAsync(null, null)); + await Assert.ThrowsAsync(() => manager.RemovePasswordAsync(null)); + await Assert.ThrowsAsync(() => manager.CheckPasswordAsync(null, null)); + await Assert.ThrowsAsync(() => manager.HasPasswordAsync(null)); } [Fact] @@ -197,14 +217,14 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserSecurityStamp); - await Assert.ThrowsAsync(() => manager.UpdateSecurityStamp("bogus")); - await Assert.ThrowsAsync(() => manager.GetSecurityStamp("bogus")); + await Assert.ThrowsAsync(() => manager.UpdateSecurityStampAsync(null)); + await Assert.ThrowsAsync(() => manager.GetSecurityStampAsync(null)); await Assert.ThrowsAsync( - () => manager.VerifyChangePhoneNumberToken("bogus", "1", "111-111-1111")); + () => manager.VerifyChangePhoneNumberTokenAsync(null, "1", "111-111-1111")); await Assert.ThrowsAsync( - () => manager.GenerateChangePhoneNumberToken("bogus", "111-111-1111")); + () => manager.GenerateChangePhoneNumberToken(null, "111-111-1111")); } [Fact] @@ -212,10 +232,10 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserLogin); - await Assert.ThrowsAsync(async () => await manager.AddLogin("bogus", null)); - await Assert.ThrowsAsync(async () => await manager.RemoveLogin("bogus", null)); - await Assert.ThrowsAsync(async () => await manager.GetLogins("bogus")); - await Assert.ThrowsAsync(async () => await manager.Find(null)); + await Assert.ThrowsAsync(async () => await manager.AddLogin(null, null)); + await Assert.ThrowsAsync(async () => await manager.RemoveLogin(null, null)); + await Assert.ThrowsAsync(async () => await manager.GetLogins(null)); + await Assert.ThrowsAsync(async () => await manager.FindByLoginAsync(null)); } [Fact] @@ -223,9 +243,9 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserClaim); - await Assert.ThrowsAsync(async () => await manager.AddClaim("bogus", null)); - await Assert.ThrowsAsync(async () => await manager.RemoveClaim("bogus", null)); - await Assert.ThrowsAsync(async () => await manager.GetClaims("bogus")); + await Assert.ThrowsAsync(async () => await manager.AddClaimAsync(null, null)); + await Assert.ThrowsAsync(async () => await manager.RemoveClaimAsync(null, null)); + await Assert.ThrowsAsync(async () => await manager.GetClaimsAsync(null)); } [Fact] @@ -233,9 +253,9 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserTwoFactor); - await Assert.ThrowsAsync(async () => await manager.GetTwoFactorEnabled("bogus")); + await Assert.ThrowsAsync(async () => await manager.GetTwoFactorEnabled(null)); await - Assert.ThrowsAsync(async () => await manager.SetTwoFactorEnabled("bogus", true)); + Assert.ThrowsAsync(async () => await manager.SetTwoFactorEnabledAsync(null, true)); } [Fact] @@ -243,12 +263,12 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserLockout); - await Assert.ThrowsAsync(async () => await manager.GetLockoutEnabled("bogus")); - await Assert.ThrowsAsync(async () => await manager.SetLockoutEnabled("bogus", true)); - await Assert.ThrowsAsync(async () => await manager.AccessFailed("bogus")); - await Assert.ThrowsAsync(async () => await manager.IsLockedOut("bogus")); - await Assert.ThrowsAsync(async () => await manager.ResetAccessFailedCount("bogus")); - await Assert.ThrowsAsync(async () => await manager.GetAccessFailedCount("bogus")); + await Assert.ThrowsAsync(async () => await manager.GetLockoutEnabledAsync(null)); + await Assert.ThrowsAsync(async () => await manager.SetLockoutEnabledAsync(null, true)); + await Assert.ThrowsAsync(async () => await manager.AccessFailedAsync(null)); + await Assert.ThrowsAsync(async () => await manager.IsLockedOutAsync(null)); + await Assert.ThrowsAsync(async () => await manager.ResetAccessFailedCountAsync(null)); + await Assert.ThrowsAsync(async () => await manager.GetAccessFailedCountAsync(null)); } [Fact] @@ -256,10 +276,10 @@ namespace Microsoft.AspNet.Identity.Test { var manager = new UserManager(new NoopUserStore()); Assert.False(manager.SupportsUserRole); - await Assert.ThrowsAsync(async () => await manager.AddToRole("bogus", null)); - await Assert.ThrowsAsync(async () => await manager.GetRoles("bogus")); - await Assert.ThrowsAsync(async () => await manager.RemoveFromRole("bogus", null)); - await Assert.ThrowsAsync(async () => await manager.IsInRole("bogus", "bogus")); + await Assert.ThrowsAsync(async () => await manager.AddToRoleAsync(null, "bogus")); + await Assert.ThrowsAsync(async () => await manager.GetRolesAsync(null)); + await Assert.ThrowsAsync(async () => await manager.RemoveFromRoleAsync(null, "bogus")); + await Assert.ThrowsAsync(async () => await manager.IsInRoleAsync(null, "bogus")); } [Fact] @@ -278,7 +298,7 @@ namespace Microsoft.AspNet.Identity.Test { PasswordValidator = new BadPasswordValidtor() }; - IdentityResultAssert.IsFailure(await manager.Create(new TestUser(), "password"), + IdentityResultAssert.IsFailure(await manager.CreateAsync(new TestUser(), "password"), BadPasswordValidtor.ErrorMessage); } @@ -295,20 +315,20 @@ namespace Microsoft.AspNet.Identity.Test await Assert.ThrowsAsync("user", async () => await manager.CreateIdentity(null, "whatever")); - await Assert.ThrowsAsync("user", async () => await manager.Create(null)); - await Assert.ThrowsAsync("user", async () => await manager.Create(null, null)); + await Assert.ThrowsAsync("user", async () => await manager.CreateAsync(null)); + await Assert.ThrowsAsync("user", async () => await manager.CreateAsync(null, null)); await Assert.ThrowsAsync("password", - async () => await manager.Create(new TestUser(), null)); - await Assert.ThrowsAsync("user", async () => await manager.Update(null)); - await Assert.ThrowsAsync("user", async () => await manager.Delete(null)); - await Assert.ThrowsAsync("claim", async () => await manager.AddClaim("bogus", null)); - await Assert.ThrowsAsync("userName", async () => await manager.FindByName(null)); - await Assert.ThrowsAsync("userName", async () => await manager.Find(null, null)); - await Assert.ThrowsAsync("login", async () => await manager.AddLogin("bogus", null)); + async () => await manager.CreateAsync(new TestUser(), null)); + await Assert.ThrowsAsync("user", async () => await manager.UpdateAsync(null)); + await Assert.ThrowsAsync("user", async () => await manager.DeleteAsync(null)); + await Assert.ThrowsAsync("claim", async () => await manager.AddClaimAsync(null, null)); + await Assert.ThrowsAsync("userName", async () => await manager.FindByNameAsync(null)); + await Assert.ThrowsAsync("userName", async () => await manager.FindByUserNamePassword(null, null)); + await Assert.ThrowsAsync("login", async () => await manager.AddLogin(null, null)); await - Assert.ThrowsAsync("login", async () => await manager.RemoveLogin("bogus", null)); - await Assert.ThrowsAsync("email", async () => await manager.FindByEmail(null)); + Assert.ThrowsAsync("login", async () => await manager.RemoveLogin(null, null)); + await Assert.ThrowsAsync("email", async () => await manager.FindByEmailAsync(null)); Assert.Throws("twoFactorProvider", () => manager.RegisterTwoFactorProvider(null, null)); Assert.Throws("provider", () => manager.RegisterTwoFactorProvider("bogus", null)); @@ -321,93 +341,92 @@ namespace Microsoft.AspNet.Identity.Test { UserTokenProvider = new NoOpTokenProvider() }; - const string error = "UserId not found."; - await ExceptionAssert.ThrowsAsync( - async () => await manager.AddClaim(null, new Claim("a", "b")), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.AddLogin(null, new UserLoginInfo("", "")), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.AddPassword(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.AddToRole(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.ChangePassword(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetClaims(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetLogins(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetRoles(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.IsInRole(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.RemoveClaim(null, new Claim("a", "b")), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.RemoveLogin(null, new UserLoginInfo("", "")), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.RemovePassword(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.RemoveFromRole(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.UpdateSecurityStamp(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetSecurityStamp(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.HasPassword(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GeneratePasswordResetToken(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.ResetPassword(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.IsEmailConfirmed(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GenerateEmailConfirmationToken(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.ConfirmEmail(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetEmail(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.SetEmail(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.IsPhoneNumberConfirmed(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.ChangePhoneNumber(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.VerifyChangePhoneNumberToken(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetPhoneNumber(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.SetPhoneNumber(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetTwoFactorEnabled(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.SetTwoFactorEnabled(null, true), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GenerateTwoFactorToken(null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.VerifyTwoFactorToken(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.NotifyTwoFactorToken(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetValidTwoFactorProviders(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.VerifyUserToken(null, null, null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.AccessFailed(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.ResetAccessFailedCount(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetAccessFailedCount(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetLockoutEnabled(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.SetLockoutEnabled(null, false), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.SetLockoutEndDate(null, DateTimeOffset.UtcNow), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.GetLockoutEndDate(null), error); - await ExceptionAssert.ThrowsAsync( - async () => await manager.IsLockedOut(null), error); + await Assert.ThrowsAsync("user", + async () => await manager.AddClaimAsync(null, new Claim("a", "b"))); + await Assert.ThrowsAsync("user", + async () => await manager.AddLogin(null, new UserLoginInfo("", ""))); + await Assert.ThrowsAsync("user", + async () => await manager.AddPasswordAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.AddToRoleAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.ChangePasswordAsync(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetClaimsAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetLogins(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetRolesAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.IsInRoleAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.RemoveClaimAsync(null, new Claim("a", "b"))); + await Assert.ThrowsAsync("user", + async () => await manager.RemoveLogin(null, new UserLoginInfo("", ""))); + await Assert.ThrowsAsync("user", + async () => await manager.RemovePasswordAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.RemoveFromRoleAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.UpdateSecurityStampAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetSecurityStampAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.HasPasswordAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GeneratePasswordResetTokenAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.ResetPassword(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.IsEmailConfirmedAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GenerateEmailConfirmationTokenAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.ConfirmEmailAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetEmailAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.SetEmailAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.IsPhoneNumberConfirmedAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.ChangePhoneNumberAsync(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.VerifyChangePhoneNumberTokenAsync(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetPhoneNumberAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.SetPhoneNumberAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetTwoFactorEnabled(null)); + await Assert.ThrowsAsync("user", + async () => await manager.SetTwoFactorEnabledAsync(null, true)); + await Assert.ThrowsAsync("user", + async () => await manager.GenerateTwoFactorTokenAsync(null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.VerifyTwoFactorTokenAsync(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.NotifyTwoFactorTokenAsync(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetValidTwoFactorProviders(null)); + await Assert.ThrowsAsync("user", + async () => await manager.VerifyUserTokenAsync(null, null, null)); + await Assert.ThrowsAsync("user", + async () => await manager.AccessFailedAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.ResetAccessFailedCountAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetAccessFailedCountAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.GetLockoutEnabledAsync(null)); + await Assert.ThrowsAsync("user", + async () => await manager.SetLockoutEnabledAsync(null, false)); + await Assert.ThrowsAsync("user", + async () => await manager.SetLockoutEndDate(null, DateTimeOffset.UtcNow)); + await Assert.ThrowsAsync("user", + async () => await manager.GetLockoutEndDate(null)); + await Assert.ThrowsAsync("user", + async () => await manager.IsLockedOutAsync(null)); } [Fact] @@ -416,43 +435,43 @@ namespace Microsoft.AspNet.Identity.Test var manager = new UserManager(new NoopUserStore()); manager.Dispose(); Assert.Throws(() => manager.ClaimsIdentityFactory); - await Assert.ThrowsAsync(() => manager.AddClaim("bogus", null)); - await Assert.ThrowsAsync(() => manager.AddLogin("bogus", null)); - await Assert.ThrowsAsync(() => manager.AddPassword("bogus", null)); - await Assert.ThrowsAsync(() => manager.AddToRole("bogus", null)); - await Assert.ThrowsAsync(() => manager.ChangePassword("bogus", null, null)); - await Assert.ThrowsAsync(() => manager.GetClaims("bogus")); - await Assert.ThrowsAsync(() => manager.GetLogins("bogus")); - await Assert.ThrowsAsync(() => manager.GetRoles("bogus")); - await Assert.ThrowsAsync(() => manager.IsInRole("bogus", null)); - await Assert.ThrowsAsync(() => manager.RemoveClaim("bogus", null)); - await Assert.ThrowsAsync(() => manager.RemoveLogin("bogus", null)); - await Assert.ThrowsAsync(() => manager.RemovePassword("bogus")); - await Assert.ThrowsAsync(() => manager.RemoveFromRole("bogus", null)); - await Assert.ThrowsAsync(() => manager.RemoveClaim("bogus", null)); - await Assert.ThrowsAsync(() => manager.Find("bogus", null)); - await Assert.ThrowsAsync(() => manager.Find(null)); - await Assert.ThrowsAsync(() => manager.FindById(null)); - await Assert.ThrowsAsync(() => manager.FindByName(null)); - await Assert.ThrowsAsync(() => manager.Create(null)); - await Assert.ThrowsAsync(() => manager.Create(null, null)); + await Assert.ThrowsAsync(() => manager.AddClaimAsync(null, null)); + await Assert.ThrowsAsync(() => manager.AddLogin(null, null)); + await Assert.ThrowsAsync(() => manager.AddPasswordAsync(null, null)); + await Assert.ThrowsAsync(() => manager.AddToRoleAsync(null, null)); + await Assert.ThrowsAsync(() => manager.ChangePasswordAsync(null, null, null)); + await Assert.ThrowsAsync(() => manager.GetClaimsAsync(null)); + await Assert.ThrowsAsync(() => manager.GetLogins(null)); + await Assert.ThrowsAsync(() => manager.GetRolesAsync(null)); + await Assert.ThrowsAsync(() => manager.IsInRoleAsync(null, null)); + await Assert.ThrowsAsync(() => manager.RemoveClaimAsync(null, null)); + await Assert.ThrowsAsync(() => manager.RemoveLogin(null, null)); + await Assert.ThrowsAsync(() => manager.RemovePasswordAsync(null)); + await Assert.ThrowsAsync(() => manager.RemoveFromRoleAsync(null, null)); + await Assert.ThrowsAsync(() => manager.RemoveClaimAsync(null, null)); + await Assert.ThrowsAsync(() => manager.FindByUserNamePassword(null, null)); + await Assert.ThrowsAsync(() => manager.FindByLoginAsync(null)); + await Assert.ThrowsAsync(() => manager.FindByIdAsync(null)); + await Assert.ThrowsAsync(() => manager.FindByNameAsync(null)); + await Assert.ThrowsAsync(() => manager.CreateAsync(null)); + await Assert.ThrowsAsync(() => manager.CreateAsync(null, null)); await Assert.ThrowsAsync(() => manager.CreateIdentity(null, null)); - await Assert.ThrowsAsync(() => manager.Update(null)); - await Assert.ThrowsAsync(() => manager.Delete(null)); - await Assert.ThrowsAsync(() => manager.UpdateSecurityStamp(null)); - await Assert.ThrowsAsync(() => manager.GetSecurityStamp(null)); - await Assert.ThrowsAsync(() => manager.GeneratePasswordResetToken(null)); + await Assert.ThrowsAsync(() => manager.UpdateAsync(null)); + await Assert.ThrowsAsync(() => manager.DeleteAsync(null)); + await Assert.ThrowsAsync(() => manager.UpdateSecurityStampAsync(null)); + await Assert.ThrowsAsync(() => manager.GetSecurityStampAsync(null)); + await Assert.ThrowsAsync(() => manager.GeneratePasswordResetTokenAsync(null)); await Assert.ThrowsAsync(() => manager.ResetPassword(null, null, null)); - await Assert.ThrowsAsync(() => manager.GenerateEmailConfirmationToken(null)); - await Assert.ThrowsAsync(() => manager.IsEmailConfirmed(null)); - await Assert.ThrowsAsync(() => manager.ConfirmEmail(null, null)); + await Assert.ThrowsAsync(() => manager.GenerateEmailConfirmationTokenAsync(null)); + await Assert.ThrowsAsync(() => manager.IsEmailConfirmedAsync(null)); + await Assert.ThrowsAsync(() => manager.ConfirmEmailAsync(null, null)); } private class BadPasswordValidtor : IPasswordValidator { public const string ErrorMessage = "I'm Bad."; - public Task Validate(string password, CancellationToken cancellationToken = default(CancellationToken)) + public Task ValidateAsync(string password, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(IdentityResult.Failed(ErrorMessage)); } @@ -469,97 +488,97 @@ namespace Microsoft.AspNet.Identity.Test IUserRoleStore, IUserSecurityStampStore { - public Task> GetClaims(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetClaimsAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult>(new List()); } - public Task AddClaim(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddClaimAsync(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task RemoveClaim(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveClaimAsync(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task SetEmail(TestUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetEmailAsync(TestUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetEmail(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(""); } - public Task GetEmailConfirmed(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailConfirmedAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(false); } - public Task SetEmailConfirmed(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetEmailConfirmedAsync(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task GetLockoutEndDate(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLockoutEndDateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(DateTimeOffset.MinValue); } - public Task SetLockoutEndDate(TestUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetLockoutEndDateAsync(TestUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task IncrementAccessFailedCount(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task IncrementAccessFailedCountAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task ResetAccessFailedCount(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task ResetAccessFailedCountAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetAccessFailedCount(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetAccessFailedCountAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetLockoutEnabled(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLockoutEnabledAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(false); } - public Task SetLockoutEnabled(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetLockoutEnabledAsync(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task AddLogin(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddLoginAsync(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task RemoveLogin(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveLoginAsync(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task> GetLogins(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetLoginsAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult>(new List()); } - public Task Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } @@ -568,112 +587,117 @@ namespace Microsoft.AspNet.Identity.Test { } - public Task Create(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetUserNameAsync(TestUser user, string userName, CancellationToken cancellationToken = new CancellationToken()) { return Task.FromResult(0); } - public Task Update(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task Delete(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + { + return Task.FromResult(0); + } + + public Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task SetPasswordHash(TestUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPasswordHashAsync(TestUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetPasswordHash(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPasswordHashAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task HasPassword(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task HasPasswordAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(false); } - public Task SetPhoneNumber(TestUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPhoneNumberAsync(TestUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetPhoneNumber(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPhoneNumberAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(""); } - public Task GetPhoneNumberConfirmed(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPhoneNumberConfirmedAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(false); } - public Task SetPhoneNumberConfirmed(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPhoneNumberConfirmedAsync(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task AddToRole(TestUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddToRoleAsync(TestUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task RemoveFromRole(TestUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveFromRoleAsync(TestUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task> GetRoles(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetRolesAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult>(new List()); } - public Task IsInRole(TestUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) + public Task IsInRoleAsync(TestUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(false); } - public Task SetSecurityStamp(TestUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetSecurityStampAsync(TestUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetSecurityStamp(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetSecurityStampAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(""); } - public Task SetTwoFactorEnabled(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetTwoFactorEnabledAsync(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task GetTwoFactorEnabled(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetTwoFactorEnabledAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(false); } - public Task GetUserId(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetUserIdAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } - public Task GetUserName(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetUserNameAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(null); } @@ -681,23 +705,23 @@ namespace Microsoft.AspNet.Identity.Test private class NoOpTokenProvider : IUserTokenProvider { - public Task Generate(string purpose, UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GenerateAsync(string purpose, UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult("Test"); } - public Task Validate(string purpose, string token, UserManager manager, + public Task ValidateAsync(string purpose, string token, UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(true); } - public Task Notify(string token, UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task NotifyAsync(string token, UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(0); } - public Task IsValidProviderForUser(UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task IsValidProviderForUserAsync(UserManager manager, TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult(true); } @@ -712,97 +736,97 @@ namespace Microsoft.AspNet.Identity.Test IUserLockoutStore, IUserTwoFactorStore { - public Task> GetClaims(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetClaimsAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task AddClaim(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddClaimAsync(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task RemoveClaim(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveClaimAsync(TestUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetEmail(TestUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetEmailAsync(TestUser user, string email, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetEmail(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetEmailConfirmed(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetEmailConfirmedAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetEmailConfirmed(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetEmailConfirmedAsync(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetLockoutEndDate(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLockoutEndDateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetLockoutEndDate(TestUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetLockoutEndDateAsync(TestUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task IncrementAccessFailedCount(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task IncrementAccessFailedCountAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task ResetAccessFailedCount(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task ResetAccessFailedCountAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetAccessFailedCount(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetAccessFailedCountAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetLockoutEnabled(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetLockoutEnabledAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetLockoutEnabled(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetLockoutEnabledAsync(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task AddLogin(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task AddLoginAsync(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task RemoveLogin(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task RemoveLoginAsync(TestUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task> GetLogins(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task> GetLoginsAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } @@ -812,82 +836,87 @@ namespace Microsoft.AspNet.Identity.Test throw new NotImplementedException(); } - public Task GetUserId(TestUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserIdAsync(TestUser user, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); } - public Task GetUserName(TestUser user, CancellationToken cancellationToken = new CancellationToken()) + public Task GetUserNameAsync(TestUser user, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); } - public Task Create(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetUserNameAsync(TestUser user, string userName, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); } - public Task Update(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task CreateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task Delete(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task UpdateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task FindById(string userId, CancellationToken cancellationToken = default(CancellationToken)) + public Task DeleteAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetPasswordHash(TestUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) + public Task FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetPasswordHash(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPasswordHashAsync(TestUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task HasPassword(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPasswordHashAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetPhoneNumber(TestUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) + public Task HasPasswordAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetPhoneNumber(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPhoneNumberAsync(TestUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetPhoneNumberConfirmed(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPhoneNumberAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetPhoneNumberConfirmed(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) + public Task GetPhoneNumberConfirmedAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task SetTwoFactorEnabled(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetPhoneNumberConfirmedAsync(TestUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } - public Task GetTwoFactorEnabled(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) + public Task SetTwoFactorEnabledAsync(TestUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken)) + { + throw new NotImplementedException(); + } + + public Task GetTwoFactorEnabledAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNet.Identity.Test/UserValidatorTest.cs b/test/Microsoft.AspNet.Identity.Test/UserValidatorTest.cs index b4103187f8..76698be4ea 100644 --- a/test/Microsoft.AspNet.Identity.Test/UserValidatorTest.cs +++ b/test/Microsoft.AspNet.Identity.Test/UserValidatorTest.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNet.Identity.Test // Act // Assert - await Assert.ThrowsAsync("manager", () => validator.Validate(null, null)); - await Assert.ThrowsAsync("user", () => validator.Validate(manager, null)); + await Assert.ThrowsAsync("manager", () => validator.ValidateAsync(null, null)); + await Assert.ThrowsAsync("user", () => validator.ValidateAsync(manager, null)); } [Theory] @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Identity.Test var user = new TestUser {UserName = input}; // Act - var result = await validator.Validate(manager, user); + var result = await validator.ValidateAsync(manager, user); // Assert IdentityResultAssert.IsFailure(result, "UserName cannot be null or empty."); @@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Identity.Test var user = new TestUser {UserName = userName}; // Act - var result = await validator.Validate(manager, user); + var result = await validator.ValidateAsync(manager, user); // Assert if (expectSuccess) @@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Identity.Test var user = new TestUser {UserName = userName}; // Act - var result = await validator.Validate(manager, user); + var result = await validator.ValidateAsync(manager, user); // Assert if (expectSuccess)