public async Task UpdateAsync_NotAdminLowerRole_ExceptionAsync(Role currentUserRole) { using (var context = InMemoryDatabaseHelper.GetDbContext()) { var userRepo = new UserRepository(context, AutomapperSingleton.Mapper); var user1 = await new ApplicationUserFactory(Role.Employee).BuildAsync(userRepo); var user2 = await new ApplicationUserFactory(Role.Employee).BuildAsync(userRepo); IAuthorizationManager authMock = new AuthManagerMockHelper(Role.SystemAdministrator).GetManager(); var service = Target(context, authMock); var user = CreateAppUserForImport("John", "Test", "*****@*****.**"); long userId = await service.InsertAsync(user); var newUser = await service.GetByIdAsync(userId); newUser.Role = Role.SystemAdministrator; await service.UpdateAsync(newUser); authMock = new AuthManagerMockHelper(currentUserRole).GetManager(); service = Target(context, authMock); newUser = await service.GetByIdAsync(userId); newUser.Role = Role.Employee; await Assert.ThrowsAsync <NoPermissionsException>(() => service.UpdateAsync(newUser)); } }
public async Task InsertAsync_NoFunctionalManager_OkAsync(Role currentUserRole) { using (var context = InMemoryDatabaseHelper.GetDbContext()) { IAuthorizationManager authMock = new AuthManagerMockHelper(currentUserRole).GetManager(); var service = Target(context, authMock); ApplicationUser user = await service.GetByIdAsync( await service.InsertAsync( CreateAppUserForImport("John", "Test", "*****@*****.**"))); Assert.Equal(Role.Employee, user.Role); Assert.Equal("John", user.FirstName); Assert.Equal("Test", user.LastName); Assert.Equal("*****@*****.**", user.UserName); Assert.Equal("*****@*****.**", user.Email); } }