Change IUserClaimStore to take IEnumerable<Claims>
https://github.com/aspnet/Identity/issues/163
This commit is contained in:
parent
097925a3e4
commit
2a45a851a5
|
|
@ -422,36 +422,41 @@ namespace Microsoft.AspNet.Identity.EntityFramework
|
||||||
return Task.FromResult((IList<Claim>)result);
|
return Task.FromResult((IList<Claim>)result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = new CancellationToken())
|
public Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
if (claim == null)
|
if (claims == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("claim");
|
throw new ArgumentNullException("claims");
|
||||||
|
}
|
||||||
|
foreach (var claim in claims)
|
||||||
|
{
|
||||||
|
UserClaims.Add(new IdentityUserClaim<TKey> { UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value });
|
||||||
}
|
}
|
||||||
UserClaims.Add(new IdentityUserClaim<TKey> { UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value });
|
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = new CancellationToken())
|
public Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = new CancellationToken())
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
if (claim == null)
|
if (claims == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("claim");
|
throw new ArgumentNullException("claims");
|
||||||
}
|
}
|
||||||
var claims = UserClaims.Where(uc => uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToList();
|
foreach (var claim in claims) {
|
||||||
foreach (var c in claims)
|
var matchedClaims = UserClaims.Where(uc => uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToList();
|
||||||
{
|
foreach (var c in matchedClaims)
|
||||||
UserClaims.Remove(c);
|
{
|
||||||
|
UserClaims.Remove(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,19 +27,19 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// Add a new user claim
|
/// Add a new user claim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <param name="claim"></param>
|
/// <param name="claims"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken));
|
Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove a user claim
|
/// Remove a user claim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <param name="claim"></param>
|
/// <param name="claims"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task RemoveClaimAsync(TUser user, Claim claim,
|
Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims,
|
||||||
CancellationToken cancellationToken = default(CancellationToken));
|
CancellationToken cancellationToken = default(CancellationToken));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -895,7 +895,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// <param name="claim"></param>
|
/// <param name="claim"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<IdentityResult> AddClaimAsync(TUser user, Claim claim,
|
public virtual Task<IdentityResult> AddClaimAsync(TUser user, Claim claim,
|
||||||
CancellationToken cancellationToken = default(CancellationToken))
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
@ -908,7 +908,30 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
await claimStore.AddClaimAsync(user, claim, cancellationToken);
|
return AddClaimsAsync(user, new Claim[] { claim }, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a user claim
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="claim"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<IdentityResult> AddClaimsAsync(TUser user, IEnumerable<Claim> claims,
|
||||||
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
{
|
||||||
|
ThrowIfDisposed();
|
||||||
|
var claimStore = GetClaimStore();
|
||||||
|
if (claims == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("claims");
|
||||||
|
}
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("user");
|
||||||
|
}
|
||||||
|
await claimStore.AddClaimsAsync(user, claims, cancellationToken);
|
||||||
return await UpdateAsync(user, cancellationToken);
|
return await UpdateAsync(user, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -919,7 +942,7 @@ namespace Microsoft.AspNet.Identity
|
||||||
/// <param name="claim"></param>
|
/// <param name="claim"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<IdentityResult> RemoveClaimAsync(TUser user, Claim claim,
|
public virtual Task<IdentityResult> RemoveClaimAsync(TUser user, Claim claim,
|
||||||
CancellationToken cancellationToken = default(CancellationToken))
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
@ -928,7 +951,35 @@ namespace Microsoft.AspNet.Identity
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
await claimStore.RemoveClaimAsync(user, claim, cancellationToken);
|
if (claim == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("claim");
|
||||||
|
}
|
||||||
|
return RemoveClaimsAsync(user, new Claim[] { claim }, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove a user claim
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="user"></param>
|
||||||
|
/// <param name="claims"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual async Task<IdentityResult> RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims,
|
||||||
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
{
|
||||||
|
ThrowIfDisposed();
|
||||||
|
var claimStore = GetClaimStore();
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("user");
|
||||||
|
}
|
||||||
|
if (claims == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("claims");
|
||||||
|
}
|
||||||
|
await claimStore.RemoveClaimsAsync(user, claims, cancellationToken);
|
||||||
return await UpdateAsync(user, cancellationToken);
|
return await UpdateAsync(user, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -358,13 +358,13 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a claim to a user
|
/// Add claims to a user
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <param name="claim"></param>
|
/// <param name="claims"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
public virtual Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
@ -372,22 +372,25 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
if (claim == null)
|
if (claims == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("claim");
|
throw new ArgumentNullException("claims");
|
||||||
|
}
|
||||||
|
foreach (var claim in claims)
|
||||||
|
{
|
||||||
|
user.Claims.Add(new TUserClaim { UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value });
|
||||||
}
|
}
|
||||||
user.Claims.Add(new TUserClaim { UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value });
|
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove a claim from a user
|
/// Remove claims from a user
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <param name="claim"></param>
|
/// <param name="claims"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
public virtual Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
ThrowIfDisposed();
|
ThrowIfDisposed();
|
||||||
|
|
@ -395,15 +398,18 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("user");
|
throw new ArgumentNullException("user");
|
||||||
}
|
}
|
||||||
if (claim == null)
|
if (claims == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("claim");
|
throw new ArgumentNullException("claims");
|
||||||
}
|
}
|
||||||
var claims =
|
foreach (var claim in claims)
|
||||||
user.Claims.Where(uc => uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToList();
|
|
||||||
foreach (var c in claims)
|
|
||||||
{
|
{
|
||||||
user.Claims.Remove(c);
|
var matchingClaims =
|
||||||
|
user.Claims.Where(uc => uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToList();
|
||||||
|
foreach (var c in matchingClaims)
|
||||||
|
{
|
||||||
|
user.Claims.Remove(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO:these claims might not exist in the dbset
|
// TODO:these claims might not exist in the dbset
|
||||||
//var query =
|
//var query =
|
||||||
|
|
|
||||||
|
|
@ -57,18 +57,18 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
||||||
{
|
{
|
||||||
var store = new InMemoryUserStore(new InMemoryContext());
|
var store = new InMemoryUserStore(new InMemoryContext());
|
||||||
store.Dispose();
|
store.Dispose();
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddClaimAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddLoginAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddLoginAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddToRoleAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddToRoleAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetClaimsAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetClaimsAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetLoginsAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetLoginsAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRolesAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRolesAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.IsInRoleAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.IsInRoleAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveLoginAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveLoginAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(
|
await Assert.ThrowsAsync<ObjectDisposedException>(
|
||||||
async () => await store.RemoveFromRoleAsync(null, null));
|
async () => await store.RemoveFromRoleAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByLoginAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByLoginAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByIdAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByIdAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByNameAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByNameAsync(null));
|
||||||
|
|
@ -95,8 +95,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.CreateAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.CreateAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.UpdateAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.UpdateAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.DeleteAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.DeleteAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.AddClaimAsync(null, null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.AddClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.RemoveClaimAsync(null, null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.RemoveClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetClaimsAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetClaimsAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetLoginsAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetLoginsAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetRolesAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetRolesAsync(null));
|
||||||
|
|
@ -115,10 +115,10 @@ namespace Microsoft.AspNet.Identity.EntityFramework.InMemory.Test
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetSecurityStampAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetSecurityStampAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
||||||
async () => await store.SetSecurityStampAsync(null, null));
|
async () => await store.SetSecurityStampAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("claim",
|
await Assert.ThrowsAsync<ArgumentNullException>("claims",
|
||||||
async () => await store.AddClaimAsync(new InMemoryUser("fake"), null));
|
async () => await store.AddClaimsAsync(new InMemoryUser("fake"), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("claim",
|
await Assert.ThrowsAsync<ArgumentNullException>("claims",
|
||||||
async () => await store.RemoveClaimAsync(new InMemoryUser("fake"), null));
|
async () => await store.RemoveClaimsAsync(new InMemoryUser("fake"), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
||||||
async () => await store.AddLoginAsync(new InMemoryUser("fake"), null));
|
async () => await store.AddLoginAsync(new InMemoryUser("fake"), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
||||||
|
|
|
||||||
|
|
@ -171,18 +171,18 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
||||||
{
|
{
|
||||||
var store = new UserStore(new IdentityDbContext());
|
var store = new UserStore(new IdentityDbContext());
|
||||||
store.Dispose();
|
store.Dispose();
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddClaimAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddLoginAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddLoginAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddToRoleAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.AddToRoleAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetClaimsAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetClaimsAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetLoginsAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetLoginsAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRolesAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRolesAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.IsInRoleAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.IsInRoleAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveLoginAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveLoginAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(
|
await Assert.ThrowsAsync<ObjectDisposedException>(
|
||||||
async () => await store.RemoveFromRoleAsync(null, null));
|
async () => await store.RemoveFromRoleAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimAsync(null, null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.RemoveClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByLoginAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByLoginAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByIdAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByIdAsync(null));
|
||||||
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByNameAsync(null));
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.FindByNameAsync(null));
|
||||||
|
|
@ -209,8 +209,8 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.CreateAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.CreateAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.UpdateAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.UpdateAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.DeleteAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.DeleteAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.AddClaimAsync(null, null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.AddClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.RemoveClaimAsync(null, null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.RemoveClaimsAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetClaimsAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetClaimsAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetLoginsAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetLoginsAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetRolesAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetRolesAsync(null));
|
||||||
|
|
@ -229,10 +229,10 @@ namespace Microsoft.AspNet.Identity.EntityFramework.Test
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetSecurityStampAsync(null));
|
await Assert.ThrowsAsync<ArgumentNullException>("user", async () => await store.GetSecurityStampAsync(null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
await Assert.ThrowsAsync<ArgumentNullException>("user",
|
||||||
async () => await store.SetSecurityStampAsync(null, null));
|
async () => await store.SetSecurityStampAsync(null, null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("claim",
|
await Assert.ThrowsAsync<ArgumentNullException>("claims",
|
||||||
async () => await store.AddClaimAsync(new IdentityUser("fake"), null));
|
async () => await store.AddClaimsAsync(new IdentityUser("fake"), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("claim",
|
await Assert.ThrowsAsync<ArgumentNullException>("claims",
|
||||||
async () => await store.RemoveClaimAsync(new IdentityUser("fake"), null));
|
async () => await store.RemoveClaimsAsync(new IdentityUser("fake"), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
||||||
async () => await store.AddLoginAsync(new IdentityUser("fake"), null));
|
async () => await store.AddLoginAsync(new IdentityUser("fake"), null));
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
await Assert.ThrowsAsync<ArgumentNullException>("login",
|
||||||
|
|
|
||||||
|
|
@ -39,20 +39,26 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
return Task.FromResult<IList<Claim>>(claims);
|
return Task.FromResult<IList<Claim>>(claims);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
public Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
user.Claims.Add(new IdentityUserClaim<string> { ClaimType = claim.Type, ClaimValue = claim.Value, UserId = user.Id });
|
foreach (var claim in claims)
|
||||||
|
{
|
||||||
|
user.Claims.Add(new IdentityUserClaim<string> { ClaimType = claim.Type, ClaimValue = claim.Value, UserId = user.Id });
|
||||||
|
}
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
public Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
var entity =
|
foreach (var claim in claims)
|
||||||
user.Claims.FirstOrDefault(
|
|
||||||
uc => uc.UserId == user.Id && uc.ClaimType == claim.Type && uc.ClaimValue == claim.Value);
|
|
||||||
if (entity != null)
|
|
||||||
{
|
{
|
||||||
user.Claims.Remove(entity);
|
var entity =
|
||||||
|
user.Claims.FirstOrDefault(
|
||||||
|
uc => uc.UserId == user.Id && uc.ClaimType == claim.Type && uc.ClaimValue == claim.Value);
|
||||||
|
if (entity != null)
|
||||||
|
{
|
||||||
|
user.Claims.Remove(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue