Exemplo n.º 1
0
        public IActionResult CreatePersonalRelationship([FromBody] CreatePersonalRelationshipRequest request)
        {
            var validator         = new CreatePersonalRelationshipRequestValidator();
            var validationResults = validator.Validate(request);

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

            try
            {
                _personalRelationshipsUseCase.ExecutePost(request);

                return(CreatedAtAction("CreatePersonalRelationship", "Successfully created personal relationship."));
            }
            catch (Exception e) when(
                e is PersonNotFoundException ||
                e is PersonalRelationshipTypeNotFoundException ||
                e is PersonalRelationshipAlreadyExistsException ||
                e is WorkerNotFoundException
                )
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 2
0
        public void WhenRequestIsNullReturnsErrorsWithMessagesApartFromDetails()
        {
            var badRequest = new CreatePersonalRelationshipRequest();

            var response = createPersonalRelationshipRequestValidator.Validate(badRequest);

            response.IsValid.Should().BeFalse();
            response.Errors.Should().HaveCount(4);
            response.Errors.Should().Contain(e => e.ErrorMessage == "'personId' must be provided.");
            response.Errors.Should().Contain(e => e.ErrorMessage == "'otherPersonId' 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.");
        }