I have the following code:
public class NewsEditViewDataValidator : AbstractValidator<NewsEditViewData>
{
public NewsEditViewDataValidator()
{
// Status unique identifier cannot be empty
// Status unique identifier must be greater or equal to 1
RuleFor(x => x.StatusId)
.NotEmpty()
.WithMessage("Status is required")
.GreaterThanOrEqualTo(1)
.WithMessage("Status unique identifier must be greater or equal to 1");
// Other rule sets
}
}
StatusId is an integer. How does NotEmpty work in this case? What does it validate? Integers or string? What would the unit test look like for this part checking that an integer is not empty?
This is used to validate a dropdown list in my MVC 3 application. The validation works well on the view. The GreaterThanOrEqualTo part is that the status unique identifier can never less than 1. This I want to trigger to validate my object. When do it this way will NotEmpty also not fire? Is there a preference as to which one will be fired first? If StatusId is 0 which rule set will fire? If it is -1? I would like NotEmpty to work with the view and GreaterThanOrEqualTo when checking the id of the business object. Any suggestions?