public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            [RequestBodyType(typeof(PostAssignRoleRequest), "post assign role")] PostAssignRoleRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                if (req.IsValid(out var validationResults))
                {
                    PostAssignRoleResponse response = await _mediator.Send(req, cancellationToken);

                    return(new OkObjectResult(ResponseWrapper <PostAssignRoleResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
                }
                else
                {
                    return(new ObjectResult(ResponseWrapper <PostAssignRoleResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults))
                    {
                        StatusCode = 422
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in PostAssignRole", ex);
                return(new ObjectResult(ResponseWrapper <PostCreateGroupResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Exemple #2
0
        private void SetupGroupService()
        {
            _groupService = new Mock <IGroupService>();
            _groupService.Setup(x => x.GetUserGroups(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => _getUserGroupsReponse);

            _postAssignRoleResponse = new PostAssignRoleResponse()
            {
                Outcome = GroupPermissionOutcome.Success
            };

            _groupService.Setup(x => x.PostAssignRole(It.IsAny <PostAssignRoleRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => _postAssignRoleResponse);

            _groupService.Setup(x => x.GetGroupMember(It.IsAny <GetGroupMemberRequest>()))
            .ReturnsAsync(() => _getGroupMemberResponse);

            _groupService.Setup(x => x.GetGroupActivityCredentials(It.IsAny <GetGroupActivityCredentialsRequest>()))
            .ReturnsAsync(() => _getGroupActivityCredentialsResponse);
        }