I'm already using the latest version of Fluent Validation which is 5.4.0.0; What I need to achieve is:
Think on a Vehicle VIN, which depends upon Make Id, Model Id and Year of manufacture. Does in Fluent I have the ability to execute a Rule based on more rules when these rules are successfully executed?
I must validate a vehicle vin if all three rules (Make, Model and Year) passes.
I've also read the whole documentation and couldn't find any reference to implement it.
class VehicleValidator : AbstractValidator<Vehicle>
{
public VehicleValidator()
{
RuleFor(v => v.MakeId)
.NotEmpty()
.WithMessage("Make Id is required")
RuleFor(v => v.ModelId)
.NotEmpty()
.WithMessage("Model Id is required")
RuleFor(v => v.Year)
.NotEqual(default(ushort))
.WithMessage("Year is required")
RuleFor(v => v)
.MustBeAValidVehicle()
.WithName("Vehicle")
.Unless(v => v.IdMarca == null || v.IdModelo == null && v.Ano == default(short));
RuleFor(v => v.VehicleVin)
.NotEmpty()
.WithMessage("Vehicle Vin is required")
//Only run this validation if the validation of MakeId, ModelId, Year and MustBeAValidVechile don't fail
RuleFor(v => v.VehicleVin)
.MustBeAValidVehicleVin()
.Unless(v => v.Chassi == null || v.IdMarca == null || v.IdModelo == null || v.Ano == default(ushort));
}
}