public async Task AddUserToRoleFailsIfAlreadyInRoleTest() { var userMgr = CreateManager(); var roleMgr = CreateRoleManager(); var role = new InMemoryRole("addUserDupeTest"); var user = new InMemoryUser("user1"); UnitTestHelper.IsSuccess(await userMgr.CreateAsync(user)); UnitTestHelper.IsSuccess(await roleMgr.CreateAsync(role)); UnitTestHelper.IsSuccess(await userMgr.AddToRoleAsync(user.Id, role.Name)); Assert.True(await userMgr.IsInRoleAsync(user.Id, role.Name)); UnitTestHelper.IsFailure(await userMgr.AddToRoleAsync(user.Id, role.Name), "User already in role."); }
public async Task FindRoleWithManagerTest() { var roleMgr = CreateRoleManager(); var role = new InMemoryRole("findRoleTest"); UnitTestHelper.IsSuccess(await roleMgr.CreateAsync(role)); Assert.Equal(role.Name, (await roleMgr.FindByIdAsync(role.Id)).Name); }
public async Task RemoveUserFromRoleTest() { var userManager = CreateManager(); var roleManager = CreateRoleManager(); InMemoryUser[] users = { new InMemoryUser("1"), new InMemoryUser("2"), new InMemoryUser("3"), new InMemoryUser("4") }; foreach (var u in users) { UnitTestHelper.IsSuccess(await userManager.CreateAsync(u, "password")); } var r = new InMemoryRole("r1"); UnitTestHelper.IsSuccess(await roleManager.CreateAsync(r)); foreach (var u in users) { UnitTestHelper.IsSuccess(await userManager.AddToRoleAsync(u.Id, r.Name)); Assert.True(await userManager.IsInRoleAsync(u.Id, r.Name)); } foreach (var u in users) { UnitTestHelper.IsSuccess(await userManager.RemoveFromRoleAsync(u.Id, r.Name)); Assert.False(await userManager.IsInRoleAsync(u.Id, r.Name)); } }
public async Task RemoveUserNotInRoleFailsTest() { var userMgr = CreateManager(); var roleMgr = CreateRoleManager(); var role = new InMemoryRole("addUserDupeTest"); var user = new InMemoryUser("user1"); UnitTestHelper.IsSuccess(await userMgr.CreateAsync(user)); UnitTestHelper.IsSuccess(await roleMgr.CreateAsync(role)); var result = await userMgr.RemoveFromRoleAsync(user.Id, role.Name); UnitTestHelper.IsFailure(result, "User is not in role."); }
public async Task CreateRoleFailsIfExistsTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("dupeRole"); Assert.False(await manager.RoleExistsAsync(role.Name)); UnitTestHelper.IsSuccess(await manager.CreateAsync(role)); Assert.True(await manager.RoleExistsAsync(role.Name)); var role2 = new InMemoryRole("dupeRole"); UnitTestHelper.IsFailure(await manager.CreateAsync(role2)); }
public async Task AddUserToRoleTest() { var manager = CreateManager(); var roleManager = CreateRoleManager(); var role = new InMemoryRole("addUserTest"); UnitTestHelper.IsSuccess(await roleManager.CreateAsync(role)); InMemoryUser[] users = { new InMemoryUser("1"), new InMemoryUser("2"), new InMemoryUser("3"), new InMemoryUser("4") }; foreach (InMemoryUser u in users) { UnitTestHelper.IsSuccess(await manager.CreateAsync(u)); UnitTestHelper.IsSuccess(await manager.AddToRoleAsync(u.Id, role.Name)); Assert.True(await manager.IsInRoleAsync(u.Id, role.Name)); } }
public async Task DeleteRoleNonEmptySucceedsTest() { // Need fail if not empty? var userMgr = CreateManager(); var roleMgr = CreateRoleManager(); var role = new InMemoryRole("deleteNonEmpty"); Assert.False(await roleMgr.RoleExistsAsync(role.Name)); UnitTestHelper.IsSuccess(await roleMgr.CreateAsync(role)); var user = new InMemoryUser("t"); UnitTestHelper.IsSuccess(await userMgr.CreateAsync(user)); UnitTestHelper.IsSuccess(await userMgr.AddToRoleAsync(user.Id, role.Name)); UnitTestHelper.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.GetRolesAsync(user.Id); // In memory this doesn't work since there's no concept of cascading deletes //Assert.Equal(0, roles.Count()); }
public async Task DeleteRoleUnknownFailsTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("bogus"); Assert.False(await manager.RoleExistsAsync(role.Name)); Assert.Throws<InvalidOperationException>(() => AsyncHelper.RunSync(() => manager.DeleteAsync(role))); }
public async Task UpdateRoleNameTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("update"); Assert.False(await manager.RoleExistsAsync(role.Name)); UnitTestHelper.IsSuccess(await manager.CreateAsync(role)); Assert.True(await manager.RoleExistsAsync(role.Name)); role.Name = "Changed"; UnitTestHelper.IsSuccess(await manager.UpdateAsync(role)); Assert.False(await manager.RoleExistsAsync("update")); Assert.Equal(role, await manager.FindByNameAsync(role.Name)); }
public async Task RoleFindByNameTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("FindByName"); Assert.Null(await manager.FindByNameAsync(role.Name)); Assert.False(await manager.RoleExistsAsync(role.Name)); UnitTestHelper.IsSuccess(await manager.CreateAsync(role)); Assert.Equal(role, await manager.FindByNameAsync(role.Name)); }
public async Task RoleFindByIdTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("FindById"); Assert.Null(await manager.FindByIdAsync(role.Id)); UnitTestHelper.IsSuccess(await manager.CreateAsync(role)); Assert.Equal(role, await manager.FindByIdAsync(role.Id)); }
public async Task DeleteRoleTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("delete"); Assert.False(await manager.RoleExistsAsync(role.Name)); UnitTestHelper.IsSuccess(await manager.CreateAsync(role)); UnitTestHelper.IsSuccess(await manager.DeleteAsync(role)); Assert.False(await manager.RoleExistsAsync(role.Name)); }
public async Task BadValidatorBlocksAllUpdatesTest() { var manager = CreateRoleManager(); var role = new InMemoryRole("poorguy"); UnitTestHelper.IsSuccess(await manager.CreateAsync(role)); var error = AlwaysBadValidator<InMemoryRole>.ErrorMessage; manager.RoleValidator = new AlwaysBadValidator<InMemoryRole>(); UnitTestHelper.IsFailure(await manager.UpdateAsync(role), error); }