public static TestValidationContinuation Create(ITestValidationContinuation continuation) { if (continuation is TestValidationContinuation instance) { return(instance); } var allFailures = continuation.Union(continuation.UnmatchedFailures); instance = new TestValidationContinuation(allFailures); instance.ApplyPredicate(failure => !continuation.UnmatchedFailures.Contains(failure)); return(instance); }
public static ITestValidationContinuation WhenAll(this ITestValidationContinuation failures, Func <ValidationFailure, bool> failurePredicate, string exceptionMessage = null) { var result = TestValidationContinuation.Create(((TestValidationContinuation)failures).MatchedFailures); result.ApplyPredicate(failurePredicate); bool allMatched = !result.UnmatchedFailures.Any(); if (!allMatched) { var failure = result.UnmatchedFailures.First(); string message = BuildErrorMessage(failure, exceptionMessage, "Found an unexpected validation error"); throw new ValidationTestException(message); } return(result); }
public static ITestValidationWith When(this ITestValidationContinuation failures, Func <ValidationFailure, bool> failurePredicate, string exceptionMessage = null) { var result = TestValidationContinuation.Create(((TestValidationContinuation)failures).MatchedFailures); result.ApplyPredicate(failurePredicate); var anyMatched = result.Any(); if (!anyMatched) { var failure = result.UnmatchedFailures.FirstOrDefault(); string message = BuildErrorMessage(failure, exceptionMessage, "Expected validation error was not found"); throw new ValidationTestException(message); } return(result); }
public static ITestValidationContinuation WithoutErrorCode(this ITestValidationContinuation failures, string unexpectedErrorCode) { return(failures.WhenAll(failure => failure.ErrorCode != unexpectedErrorCode, string.Format("Found an unexpected error code of '{0}'", unexpectedErrorCode))); }
public static ITestValidationContinuation WithoutCustomState(this ITestValidationContinuation failures, object unexpectedCustomState) { return(failures.WhenAll(failure => failure.CustomState != unexpectedCustomState, string.Format("Found an unexpected custom state of '{0}'", unexpectedCustomState))); }
public static ITestValidationContinuation WithoutSeverity(this ITestValidationContinuation failures, Severity unexpectedSeverity) { return(failures.WhenAll(failure => failure.Severity != unexpectedSeverity, string.Format("Found an unexpected severity of '{0}'", unexpectedSeverity))); }
public static ITestValidationWith WithErrorCode(this ITestValidationContinuation failures, string expectedErrorCode) { return(failures.When(failure => failure.ErrorCode == expectedErrorCode, string.Format("Expected an error code of '{0}'. Actual error code was '{{Code}}'", expectedErrorCode))); }
public static ITestValidationWith WithErrorMessage(this ITestValidationContinuation failures, string expectedErrorMessage) { return(failures.When(failure => failure.ErrorMessage == expectedErrorMessage, string.Format("Expected an error message of '{0}'. Actual message was '{{Message}}'", expectedErrorMessage))); }
public static ITestValidationWith WithMessageArgument <T>(this ITestValidationContinuation failures, string argumentKey, T argumentValue) { return(failures.When(failure => failure.FormattedMessagePlaceholderValues.ContainsKey(argumentKey) && ((T)failure.FormattedMessagePlaceholderValues[argumentKey]).Equals(argumentValue), string.Format("Expected message argument '{0}' with value '{1}'. Actual value was '{{MessageArgument:{0}}}'", argumentKey, argumentValue.ToString()))); }
public static ITestValidationWith WithCustomState(this ITestValidationContinuation failures, object expectedCustomState, IEqualityComparer comparer = null) { return(failures.When(failure => comparer?.Equals(failure.CustomState, expectedCustomState) ?? Equals(failure.CustomState, expectedCustomState), string.Format("Expected custom state of '{0}'. Actual state was '{{State}}'", expectedCustomState))); }
public static ITestValidationWith WithSeverity(this ITestValidationContinuation failures, Severity expectedSeverity) { return(failures.When(failure => failure.Severity == expectedSeverity, string.Format("Expected a severity of '{0}'. Actual severity was '{{Severity}}'", expectedSeverity))); }