public IActionResult CreateCaseStatus([FromBody] CreateCaseStatusRequest request) { var validator = new CreateCaseStatusRequestValidator(); var validationResults = validator.Validate(request); if (!validationResults.IsValid) { return(BadRequest(validationResults.ToString())); } try { _caseStatusesUseCase.ExecutePost(request); return(CreatedAtAction(nameof(CreateCaseStatus), "Successfully created case status.")); } catch (Exception e) when( e is PersonNotFoundException || e is CaseStatusAlreadyExistsException || e is WorkerNotFoundException || e is InvalidStartDateException ) { return(BadRequest(e.Message)); } }
public void WhenRequestIsNullReturnsErrorsWithMessagesApartFromDetails() { var badRequest = new CreateCaseStatusRequest(); var response = _createCaseStatusRequestValidator.Validate(badRequest); response.IsValid.Should().BeFalse(); response.Errors.Should().HaveCount(5); response.Errors.Should().Contain(e => e.ErrorMessage == "'personId' must be provided."); response.Errors.Should().Contain(e => e.ErrorMessage == "'type' must be provided."); response.Errors.Should().Contain(e => e.ErrorMessage == "'createdBy' must be provided."); response.Errors.Should().Contain(e => e.ErrorMessage == "'startDate' must be provided."); response.Errors.Should().Contain(e => e.ErrorMessage == "'type' must be CIN, CP or LAC."); }