Breaking change in 4.0?

May 2, 2013 at 9:17 PM
Hi,

As developers of Catel we also provide a FluentValidation extension. Now one of my workitems for today was to upgrade FluentValidation to 4.0, but then one of our unit tests failed.

After a bit of puzzling, it seems like this is no longer giving an error when the strings are null:
        RuleFor(model => model.PersonFirstName).Length(3, 20);
        RuleFor(model => model.PersonLastName).Length(3, 20);
Now I have to do it like this:
        RuleFor(model => model.PersonFirstName).NotNull().Length(3, 20);
        RuleFor(model => model.PersonLastName).NotNull().Length(3, 20);
But can you explain to my how a string, which is null, which has 0 or an undefined number of characters can succeed for a length test of a length between 3 and 20?
May 2, 2013 at 9:18 PM
And I should read the release notes before I start a new thread. You clearly noted this as a breaking change, my bad.
Coordinator
May 3, 2013 at 9:07 AM
Hi

I did think for a while whether or not I should make this change as I knew it would be breaking, but I think it's better in the long run.

This brings the Length validator in-line with other validators which do not execute if the value is null, because this is the role of the NotNullValidator. Additionally, it's consistent with the DataAnnotations StringLength validator.

Jeremy
May 3, 2013 at 10:48 AM
I partly agree with you. It's still not valid, so maybe the others are wrong. But I understand your point of view on the framework-side, so it's a good decision to keep it all the same.