Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 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)));
 }
Exemplo n.º 5
0
 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)));
 }
Exemplo n.º 6
0
 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)));
 }
Exemplo n.º 7
0
 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)));
 }
Exemplo n.º 8
0
 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)));
 }
Exemplo n.º 9
0
 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())));
 }
Exemplo n.º 10
0
 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)));
 }
Exemplo n.º 11
0
 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)));
 }