Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertions Without*** when there are multiple failures (#1937) #1938

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/FluentValidation.Tests/ValidatorTesterTester.cs
Expand Up @@ -469,6 +469,22 @@ public class ValidatorTesterTester {
ex.Message.ShouldEqual("Found an unexpected error code of 'bar'");
}

[Fact]
public void Unexpected_without_error_code_check() {
//#1937
var validator = new InlineValidator<Person> {
v => v.RuleFor(x => x.Surname).NotNull(),
v => v.RuleFor(x => x.Forename).NotNull()
};

validator.TestValidate(new Person())
.ShouldHaveValidationErrorFor(x => x.Surname)
.WithoutErrorCode("foo")
.WithoutErrorMessage("bar")
.WithoutSeverity(Severity.Warning)
.WithoutCustomState(1);
}

[Fact]
public void Expected_severity_check() {
var validator = new InlineValidator<Person> {
Expand Down
Expand Up @@ -9,6 +9,7 @@ public interface ITestValidationWith : ITestValidationContinuation {
}

public interface ITestValidationContinuation : IEnumerable<ValidationFailure> {
IEnumerable<ValidationFailure> MatchedFailures { get; }
Aleksei-Pankratev-EPAM marked this conversation as resolved.
Show resolved Hide resolved
IEnumerable<ValidationFailure> UnmatchedFailures { get; }
}

Expand Down
2 changes: 1 addition & 1 deletion src/FluentValidation/TestHelper/ValidatorTestExtensions.cs
Expand Up @@ -198,7 +198,7 @@ public static class ValidationTestExtension {
}

public static ITestValidationContinuation WhenAll(this ITestValidationContinuation failures, Func<ValidationFailure, bool> failurePredicate, string exceptionMessage = null) {
var result = TestValidationContinuation.Create(failures);
var result = TestValidationContinuation.Create(failures.MatchedFailures);
Aleksei-Pankratev-EPAM marked this conversation as resolved.
Show resolved Hide resolved
result.ApplyPredicate(failurePredicate);

bool allMatched = !result.UnmatchedFailures.Any();
Expand Down