public async Task <UpdateJobStatusOutcome?> UpdateJobStatusToOpenAsync(int jobId, int createdByUserId) { var request = new PutUpdateJobStatusToOpenRequest() { JobID = jobId, CreatedByUserID = createdByUserId }; var response = await PutAsync <BaseRequestHelpResponse <PutUpdateJobStatusToOpenResponse> >($"/api/PutUpdateJobStatusToOpen", request); if (response.HasContent && response.IsSuccessful) { return(response.Content.Outcome); } return(null); }
public async Task WhenUnSuccessfullyChangingJobStatusToDone_ReturnsFalse() { _updateJobStatusOutcome = UpdateJobStatusOutcome.BadRequest; _request = new PutUpdateJobStatusToOpenRequest { CreatedByUserID = 1, JobID = 1 }; _isSameAsProposed = false; var response = await _classUnderTest.Handle(_request, CancellationToken.None); _repository.Verify(x => x.JobHasStatus(It.IsAny <int>(), It.IsAny <JobStatuses>()), Times.Exactly(2)); _repository.Verify(x => x.UpdateJobStatusOpenAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); _communicationService.Verify(x => x.RequestCommunication(It.IsAny <RequestCommunicationRequest>(), It.IsAny <CancellationToken>()), Times.Never); Assert.AreEqual(UpdateJobStatusOutcome.BadRequest, response.Outcome); }
public async Task WhenVolunteerDoesNotHavePermission_ReturnsUnauthorised() { _updateJobStatusOutcome = UpdateJobStatusOutcome.Unauthorized; _hasPermission = false; _isSameAsProposed = false; _request = new PutUpdateJobStatusToOpenRequest { CreatedByUserID = 1, JobID = 1 }; var response = await _classUnderTest.Handle(_request, CancellationToken.None); _repository.Verify(x => x.JobHasStatus(It.IsAny <int>(), It.IsAny <JobStatuses>()), Times.Exactly(2)); _repository.Verify(x => x.UpdateJobStatusOpenAsync(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.Unauthorized, response.Outcome); }
public async Task WhenJobStatusIsAlreadyOpen_ReturnsAlreadyInThisStatus() { _updateJobStatusOutcome = UpdateJobStatusOutcome.AlreadyInThisStatus; _hasPermission = true; _isSameAsProposed = true; _request = new PutUpdateJobStatusToOpenRequest { CreatedByUserID = 1, JobID = 1 }; var response = await _classUnderTest.Handle(_request, CancellationToken.None); _repository.Verify(x => x.JobHasStatus(It.IsAny <int>(), It.IsAny <JobStatuses>()), Times.Once); _repository.Verify(x => x.UpdateJobStatusOpenAsync(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.AlreadyInThisStatus, response.Outcome); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] [RequestBodyType(typeof(PutUpdateJobStatusToOpenRequest), "put update job status to open request")] PutUpdateJobStatusToOpenRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("PutUpdateJobStatusToOpen started"); PutUpdateJobStatusToOpenResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <PutUpdateJobStatusToOpenResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in PutUpdateJobStatusToOpen", exc); return(new ObjectResult(ResponseWrapper <PutUpdateJobStatusToOpenResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }