Jeremy Skinner
From: shapper
Hello Jeremy,
Sorry for the delay! I got stuck on something.
Fluent Validation's ShouldHaveValidationErrorFor and ShouldNotHaveValidationErrorFor are only for NUnit?
Anyway I did the following:
public class TestModel {
public String Name { get; set; }
} // TestModelpublic class TestValidator : AbstractValidator<TestModel> {
public TestValidator() {
RuleFor(x => x.Name).NotEmpty().WithMessage("The name is required");When(x => 1 == 1, () => {
When(x => 1 == 0, () => {
Custom(x => {
return new ValidationFailure("Custom", "The validation failed");
});
});
});
}
}So I did the following test:
public void Validator_IsValid() {
TestValidator validator = new TestValidator();
ValidationResult results = validator.Validate(new TestModel { Name = "John" });
Assert.IsTrue(results.IsValid);
}And it fails. It only passes if I set the first When condition to False.
It seems the condition in the second When is ignored.
Any idea?
Thank You,
Miguel
ShouldHaveValidationErrorFor