public async Task WhenUnSuccessfullyChangingJobStatusToCancelled_ReturnsFalse() { _updateJobStatusOutcome = UpdateJobStatusOutcome.BadRequest; _isSameAsProposed = false; _request = new PutUpdateJobStatusToCancelledRequest { 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.UpdateJobStatusCancelledAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); Assert.AreEqual(UpdateJobStatusOutcome.BadRequest, response.Outcome); }
public async Task WhenVolunteerDoesNotHavePermission_ReturnsUnauthorised() { _updateJobStatusOutcome = UpdateJobStatusOutcome.Unauthorized; _hasPermission = false; _isSameAsProposed = false; _request = new PutUpdateJobStatusToCancelledRequest { 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.UpdateJobStatusCancelledAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Never); Assert.AreEqual(UpdateJobStatusOutcome.Unauthorized, response.Outcome); }
public async Task <UpdateJobStatusOutcome?> UpdateJobStatusToCancelledAsync(int jobId, int createdByUserId) { var request = new PutUpdateJobStatusToCancelledRequest() { JobID = jobId, CreatedByUserID = createdByUserId }; var response = await PutAsync <BaseRequestHelpResponse <PutUpdateJobStatusToCancelledResponse> >($"/api/PutUpdateJobStatusToCancelled", request); if (response.HasContent && response.IsSuccessful) { return(response.Content.Outcome); } return(null); }
public async Task WhenJobStatusIsAlreadyCancelled_ReturnsAlreadyInThisStatus() { _updateJobStatusOutcome = UpdateJobStatusOutcome.AlreadyInThisStatus; _hasPermission = true; _isSameAsProposed = true; _request = new PutUpdateJobStatusToCancelledRequest { 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.UpdateJobStatusCancelledAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Never); Assert.AreEqual(UpdateJobStatusOutcome.AlreadyInThisStatus, response.Outcome); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "put", Route = null)] [RequestBodyType(typeof(PutUpdateJobStatusToCancelledRequest), "put update job status to cancelled request")] PutUpdateJobStatusToCancelledRequest req, CancellationToken cancellationToken) { try { _logger.LogInformation("PutUpdateJobStatusToCancelled started"); PutUpdateJobStatusToCancelledResponse response = await _mediator.Send(req, cancellationToken); return(new OkObjectResult(ResponseWrapper <PutUpdateJobStatusToCancelledResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { _logger.LogErrorAndNotifyNewRelic("Exception occured in PutUpdateJobStatusToCancelled", exc); return(new ObjectResult(ResponseWrapper <PutUpdateJobStatusToCancelledResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }