Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: When Problem.

$
0
0
Thanks for this. I'll take a look at what's wrong later in the week.

To answer your question, no, the shouldhavevalidationerror methods are not specific to NUnit. They will work with any testing framework.

Jeremy Skinner
Sent from my iPhone

On 14 Feb 2012, at 17:45, shapper <notifications@codeplex.com> wrote:

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; }
} // TestModel

public 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

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>