public async Task <IActionResult> AddRoles( int id, [FromBody] UpdateUserRoleRequest request) { if (await appsService.IsRequestValidOnThisLicense( request.AppId, request.License, request.RequestorId)) { var result = await usersService.AddUserRoles( id, request.RoleIds.ToList(), request.License); if (result.Success) { result.Message = ControllerMessages.StatusCode200(result.Message); return(Ok(result)); } else { result.Message = ControllerMessages.StatusCode404(result.Message); return(NotFound(result)); } } else { return(BadRequest(ControllerMessages.InvalidLicenseRequestMessage)); } }
public async Task AddRolesToUsers() { // Arrange var userId = 2; var user = context.Users .Include(u => u.Roles) .FirstOrDefault(u => u.Id == userId); var updateUserRoleRequest = new UpdateUserRoleRequest(); updateUserRoleRequest.RoleIds.Add(3); var license = TestObjects.GetLicense(); // Act var result = await sut.AddUserRoles( userId, updateUserRoleRequest.RoleIds, license); // Assert Assert.That(result.Success, Is.True); Assert.That(result.Message, Is.EqualTo("Roles Added")); }