Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: CascadeMode set inside Validator .ctor is broken

$
0
0

Hi,

I have the following validator:

    public class ResponseValidator : AbstractValidator<Response>
    {
        public ResponseValidator()
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor( cr => cr.Result )
                .Must( r => r == RequestResult.Success )
                .WithMessage( "The request failed." );

            RuleFor( r => r.CheckoutId ).NotEmpty()
                .WithName( "CheckoutResponse.CheckoutId" );
        }
    }

/////////////////

Notice I set the CascadeMode = CascaseMode.StopOnFirstFailure.

Next, I validate a response by:

/////////////////

var result = validator.Validate(
              new Response {  Result = RequestResult.Failure,
                              Message = "Invalid request!"
                           } );
    result.IsValid.ShouldBeFalse(); //OK
    result.Errors.Count.ShouldEqual( 1 ); //Count = 2 !!!

////////////////

If I'm not mistaken, Cascase.StopOnFirstFailure property set inside the Validator's constructor, the validator.Validate() should return Errors.Count of 1.

Let me know your thoughts.

Thanks,
Brian 


Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>