public void Given_a_request_with_a_null_or_empty_or_whitespace_propertyRef__When_GetAractionsByPropRefRequestValidator_is_called__Then_it_returns_only_one_corresponding_error_message()
        {
            // arrange
            var request_empty = new GetAractionsByPropRefRequest()
            {
                PropertyRef = ""
            };
            var request_whitespace = new GetAractionsByPropRefRequest()
            {
                PropertyRef = " "
            };
            var request_null = new GetAractionsByPropRefRequest()
            {
                PropertyRef = null
            };

            // act, assert
            _validatorUnderTest.ShouldHaveValidationErrorFor(r => r.PropertyRef, request_empty)
            .WithErrorMessage(ErrorMessagesFormatter.FieldIsWhiteSpaceOrEmpty("PropertyRef"))
            .WithoutErrorMessage(ErrorMessagesFormatter.FieldIsNullMessage("PropertyRef"));

            _validatorUnderTest.ShouldHaveValidationErrorFor(r => r.PropertyRef, request_whitespace)
            .WithErrorMessage(ErrorMessagesFormatter.FieldIsWhiteSpaceOrEmpty("PropertyRef"))
            .WithoutErrorMessage(ErrorMessagesFormatter.FieldIsNullMessage("PropertyRef"));

            _validatorUnderTest.ShouldHaveValidationErrorFor(r => r.PropertyRef, request_null)
            .WithErrorMessage(ErrorMessagesFormatter.FieldIsNullMessage("PropertyRef"))
            .WithoutErrorMessage(ErrorMessagesFormatter.FieldIsWhiteSpaceOrEmpty("PropertyRef"));
        }
Ejemplo n.º 2
0
        public GetAractionsByPropRefRequestValidator()
        {
            ValidatorOptions.Global.CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(request => request.PropertyRef)
            .NotNull().WithMessage(ErrorMessagesFormatter.FieldIsNullMessage("PropertyRef"))
            .NotEmpty().WithMessage(ErrorMessagesFormatter.FieldIsWhiteSpaceOrEmpty("PropertyRef"));
        }
        public void Given_a_list_of_validation_failures__When_FormatValidationFailures_formatter_method_is_called__Then_it_returns_a_list_of_corresponding_error_messages() //we don't check the message format. we only check that the related text was given as output.
        {
            //arrange
            var validation_failures_list = TestHelper.Generate_AListOfValidationFailures();
            var errorCount = validation_failures_list.Count;

            //act
            var formattedList = ErrorMessagesFormatter.FormatValidationFailures(validation_failures_list);

            //assert
            Assert.AreEqual(errorCount, formattedList.Count);

            for (int i = 0; i < errorCount; i++)
            {
                StringAssert.Contains(validation_failures_list[i].PropertyName, formattedList[i]);
                StringAssert.Contains(validation_failures_list[i].ErrorMessage, formattedList[i]);
            }
        }
        public void Given_a_request_with_a_null_propertyRef__When_GetAractionsByPropRefRequestValidator_is_called__Then_it_returns_correct_error_message()
        {
            // arrange
            var request = new GetAractionsByPropRefRequest()
            {
                PropertyRef = null
            };

            // act, assert
            _validatorUnderTest.ShouldHaveValidationErrorFor(r => r.PropertyRef, request).WithErrorMessage(ErrorMessagesFormatter.FieldIsNullMessage("PropertyRef"));
        }
        public void Given_a_request_with_an_empty_or_whitespace_propertyRef__When_GetAractionsByPropRefRequestValidator_is_called__Then_it_returns_correct_error_message(string test_prop_ref)
        {
            // arrange
            var request = new GetAractionsByPropRefRequest()
            {
                PropertyRef = test_prop_ref
            };

            // act, assert
            _validatorUnderTest.ShouldHaveValidationErrorFor(r => r.PropertyRef, request).WithErrorMessage(ErrorMessagesFormatter.FieldIsWhiteSpaceOrEmpty("PropertyRef"));
        }
 public ErrorResponse(IList <ValidationFailure> validationFailures)
 {
     Errors = ErrorMessagesFormatter.FormatValidationFailures(validationFailures);
 }