64 lines
3.3 KiB
C#
64 lines
3.3 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.AspNet.Identity.Entity.Test
|
|
{
|
|
public class RoleStoreTest
|
|
{
|
|
[Fact]
|
|
public async Task RoleStoreMethodsThrowWhenDisposedTest()
|
|
{
|
|
var store = new RoleStore<EntityRole, string>(new IdentityContext());
|
|
store.Dispose();
|
|
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.GetRoleIdAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.GetRoleNameAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.SetRoleNameAsync(null, null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.CreateAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.UpdateAsync(null));
|
|
await Assert.ThrowsAsync<ObjectDisposedException>(async () => await store.DeleteAsync(null));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RoleStorePublicNullCheckTest()
|
|
{
|
|
Assert.Throws<ArgumentNullException>("context", () => new RoleStore<EntityRole, string>(null));
|
|
var store = new RoleStore<EntityRole, string>(new IdentityContext());
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.GetRoleIdAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.GetRoleNameAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.SetRoleNameAsync(null, null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.CreateAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.UpdateAsync(null));
|
|
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await store.DeleteAsync(null));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CanUpdateRoleName()
|
|
{
|
|
var manager = TestIdentityFactory.CreateRoleManager();
|
|
var role = new EntityRole("UpdateRoleName");
|
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(role));
|
|
Assert.Null(await manager.FindByNameAsync("New"));
|
|
role.Name = "New";
|
|
IdentityResultAssert.IsSuccess(await manager.UpdateAsync(role));
|
|
Assert.NotNull(await manager.FindByNameAsync("New"));
|
|
Assert.Null(await manager.FindByNameAsync("UpdateAsync"));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CanSetUserName()
|
|
{
|
|
var manager = TestIdentityFactory.CreateRoleManager();
|
|
var role = new EntityRole("UpdateRoleName");
|
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(role));
|
|
Assert.Null(await manager.FindByNameAsync("New"));
|
|
IdentityResultAssert.IsSuccess(await manager.SetRoleNameAsync(role, "New"));
|
|
Assert.NotNull(await manager.FindByNameAsync("New"));
|
|
Assert.Null(await manager.FindByNameAsync("UpdateAsync"));
|
|
}
|
|
|
|
}
|
|
}
|