I have a problem with fluentvalidation (version 3.4.6.0 with fluentvalidation.MVC4, jQuery validation 1.9.0.1), the validation will fail when the value is 0 and it should not. Here is my code and a failing test.
public class SomeModel
{
public string Id { get; set; }
public decimal Price { get; set; }
}
public class EditMachineValidator : AbstractValidator<SomeModel>
{
public SomeModelValidator()
{
RuleFor(x => x.Price).NotEmpty();
RuleFor(x => x.Price).GreaterThanOrEqualTo(0m);
}
}
[Fact]
public void Should_Not_Have_Error_When_Price_Is_Zero()
{
var validator = SomeModelValidator();
validator.ShouldNotHaveValidationErrorFor(x => x.Price, 0m);
}
Am I doing something wrong here?
after some tests,
GreaterThanOrEqualTois not the problem.It’s coming from
as a
0value is considered asempty!If you remove it, it will work.