Example #1
0
        public async Task UpdateAsync_NotAdminSetHigherRole_ExceptionAsync(Role currentUserRole)
        {
            await using var context = InMemoryDatabaseHelper.GetDbContext();
            var userRepo = new UserRepository(context);

            var user1 = await new ApplicationUserFactory(Role.Employee).BuildAsync(userRepo);
            var user2 = await new ApplicationUserFactory(Role.Employee).BuildAsync(userRepo);

            IAuthorizationManager authMock = new FakeAuth(currentUserRole);

            var service = Target(context, authMock);

            var data = new UserDto("John", "Test", "*****@*****.**");

            long userId = await service.InsertAsync(data);

            data      = AutomapperSingleton.Map <UserDto>(await service.GetByIdAsync(userId));
            data.Role = Role.SystemAdministrator;

            await Assert.ThrowsAsync <BadAssException>(() => service.UpdateAsync(data));
        }
Example #2
0
        public async Task UpdateAsync_NotAdminLowerRole_ExceptionAsync(Role currentUserRole)
        {
            await using var context = InMemoryDatabaseHelper.GetDbContext();
            var user1 = await new ApplicationUserFactory(Role.Employee).BuildAsync(context);
            var user2 = await new ApplicationUserFactory(Role.Employee).BuildAsync(context);

            var service = Target(context, FakeAuth.SysAdmin);

            var  createData = new UserDto("John", "Test", "*****@*****.**");
            long userId     = await service.InsertAsync(createData);

            var updateData = AutomapperSingleton.Map <UserDto>(await service.GetByIdAsync(userId));

            updateData.Role = Role.SystemAdministrator;

            await service.UpdateAsync(updateData);

            service = Target(context, new FakeAuth(currentUserRole));

            updateData      = AutomapperSingleton.Map <UserDto>(await service.GetByIdAsync(userId));
            updateData.Role = Role.Employee;

            await Assert.ThrowsAsync <NoPermissionsException>(() => service.UpdateAsync(updateData));
        }
Example #3
0
 public User Please()
 {
     AutomapperSingleton.Initialize();
     return(AutomapperSingleton.Map <User>(this));
 }