Esempio n. 1
0
        public async Task <UpdateJobStatusOutcome?> UpdateJobStatusToInProgressAsync(int jobId, int createdByUserId, int volunteerUserId)
        {
            var request = new PutUpdateJobStatusToInProgressRequest()
            {
                JobID           = jobId,
                CreatedByUserID = createdByUserId,
                VolunteerUserID = volunteerUserId
            };

            var response = await PutAsync <BaseRequestHelpResponse <PutUpdateJobStatusToInProgressResponse> >($"/api/PutUpdateJobStatusToInProgress", request);

            if (response.HasContent && response.IsSuccessful)
            {
                return(response.Content.Outcome);
            }
            return(null);
        }
Esempio n. 2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)]
            [RequestBodyType(typeof(PutUpdateJobStatusToInProgressRequest), "put update job status to in progress request")] PutUpdateJobStatusToInProgressRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                _logger.LogInformation("PutUpdateJobStatusToInProgress started");
                PutUpdateJobStatusToInProgressResponse response = await _mediator.Send(req, cancellationToken);

                return(new OkObjectResult(ResponseWrapper <PutUpdateJobStatusToInProgressResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response)));
            }
            catch (Exception exc)
            {
                _logger.LogErrorAndNotifyNewRelic("Exception occured in PutUpdateJobStatusToInProgress", exc);
                return(new ObjectResult(ResponseWrapper <PutUpdateJobStatusToInProgressResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Esempio n. 3
0
        public async Task WhenjobGroupDoesNotContainsVolunteerGroups_ReturnsBadRequest()
        {
            _updateJobStatusOutcome = UpdateJobStatusOutcome.BadRequest;
            _request = new PutUpdateJobStatusToInProgressRequest
            {
                CreatedByUserID = 1,
                JobID           = 1,
                VolunteerUserID = 1
            };

            _getUserGroupsReponse = new GetUserGroupsResponse()
            {
                Groups = new List <int>()
                {
                    1
                }
            };

            _getGroupsForJobResponse = new List <int>()
            {
                2
            };

            _referringGroupId = 1;

            var response = await _classUnderTest.Handle(_request, CancellationToken.None);

            _repository.Verify(x => x.JobIsInProgressWithSameVolunteerUserId(It.IsAny <int>(), It.IsAny <int?>()), Times.Once);
            _groupService.Verify(x => x.GetUserGroups(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _repository.Verify(x => x.GetGroupsForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _repository.Verify(x => x.GetReferringGroupIDForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _groupService.Verify(x => x.GetGroupMember(It.IsAny <GetGroupMemberRequest>()), Times.Never);
            _groupService.Verify(x => x.GetGroupActivityCredentials(It.IsAny <GetGroupActivityCredentialsRequest>()), Times.Never);
            _repository.Verify(x => x.UpdateJobStatusInProgressAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Never);
            _communicationService.Verify(x => x.RequestCommunication(It.IsAny <RequestCommunicationRequest>(), It.IsAny <CancellationToken>()), Times.Never);
            Assert.AreEqual(UpdateJobStatusOutcome.BadRequest, response.Outcome);
        }
Esempio n. 4
0
        public async Task WhenCreatedByUserIsSameAsVolunteerUserID_ReturnsSuccess(GroupRoles role)
        {
            _updateJobStatusOutcome = UpdateJobStatusOutcome.Success;
            _request = new PutUpdateJobStatusToInProgressRequest
            {
                CreatedByUserID = 1,
                JobID           = 1,
                VolunteerUserID = 1
            };
            _getUserGroupsReponse = new GetUserGroupsResponse()
            {
                Groups = new List <int>()
                {
                    1
                }
            };

            _getGroupsForJobResponse = new List <int>()
            {
                1
            };

            _referringGroupId = 1;

            Dictionary <int, List <int> > roles = new Dictionary <int, List <int> >();

            roles.Add(1, new List <int>()
            {
                (int)role
            });

            _getJobDetailsResponse = new GetJobDetailsResponse()
            {
                JobSummary = new JobSummary()
                {
                    JobID           = 1,
                    SupportActivity = SupportActivities.Shopping
                }
            };

            _getGroupMemberResponse = new GetGroupMemberResponse()
            {
                UserInGroup = new UserInGroup()
                {
                    GroupId    = 1,
                    UserId     = 1,
                    GroupRoles = new List <GroupRoles>()
                    {
                        GroupRoles.Member
                    },
                    ValidCredentials = new List <int>()
                    {
                        -1
                    }
                }
            };

            _getGroupActivityCredentialsResponse = new GetGroupActivityCredentialsResponse()
            {
                CredentialSets = new List <List <int> > {
                    new List <int>()
                    {
                        -1
                    }
                }
            };

            _hasPermission = true;

            var response = await _classUnderTest.Handle(_request, CancellationToken.None);

            _repository.Verify(x => x.JobIsInProgressWithSameVolunteerUserId(It.IsAny <int>(), It.IsAny <int?>()), Times.Once);
            _groupService.Verify(x => x.GetUserGroups(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _groupService.Verify(x => x.GetGroupMember(It.IsAny <GetGroupMemberRequest>()), Times.Once);
            _groupService.Verify(x => x.GetGroupActivityCredentials(It.IsAny <GetGroupActivityCredentialsRequest>()), Times.Once);
            _repository.Verify(x => x.GetGroupsForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _repository.Verify(x => x.GetReferringGroupIDForJobAsync(It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _groupService.Verify(x => x.GetGroupMember(It.IsAny <GetGroupMemberRequest>()), Times.Once);
            _groupService.Verify(x => x.GetGroupActivityCredentials(It.IsAny <GetGroupActivityCredentialsRequest>()), Times.Once);
            _repository.Verify(x => x.UpdateJobStatusInProgressAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once);
            _communicationService.Verify(x => x.RequestCommunication(It.IsAny <RequestCommunicationRequest>(), It.IsAny <CancellationToken>()), Times.Once);
            Assert.AreEqual(UpdateJobStatusOutcome.Success, response.Outcome);
        }