public IActionResult CreateSubmission([FromBody] CreateCaseSubmissionRequest request)
        {
            var validator         = new CreateCaseSubmissionRequestValidator();
            var validationResults = validator.Validate(request);

            if (!validationResults.IsValid)
            {
                return(BadRequest(validationResults.ToString()));
            }

            try
            {
                var createdSubmission = _formSubmissionsUseCase.ExecutePost(request).Item1;

                return(CreatedAtAction(nameof(CreateSubmission), createdSubmission));
            }
            catch (WorkerNotFoundException e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (PersonNotFoundException e)
            {
                return(UnprocessableEntity(e.Message));
            }
        }
Exemplo n.º 2
0
        public void ValidCreateCaseSubmissionRequestReturnsNoErrorsOnValidation()
        {
            var createTeamRequest = TestHelpers.CreateCaseSubmissionRequest();
            var validator         = new CreateCaseSubmissionRequestValidator();

            var validationResponse = validator.Validate(createTeamRequest);

            validationResponse.IsValid.Should().Be(true);
        }
Exemplo n.º 3
0
        public void CreateCaseSubmissionRequestValidationReturnsErrorsWithInvalidProperties()
        {
            var badCreateCaseSubmissionRequest = new List <(CreateCaseSubmissionRequest, string)>
            {
                (TestHelpers.CreateCaseSubmissionRequest(createdBy: "invalid email"), "Provide a valid email address for who created the submission"),
            };

            var validator = new CreateCaseSubmissionRequestValidator();

            foreach (var(request, expectedErrorMessage) in badCreateCaseSubmissionRequest)
            {
                var validationResponse = validator.Validate(request);

                validationResponse.IsValid.Should().Be(false);
                validationResponse.ToString().Should().Be(expectedErrorMessage);
            }
        }