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"));
        }
Esempio 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_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"));
        }