Exemple #1
0
        internal static void CollectionShouldBeEmpty <T>(ConditionValidator <T> validator, string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.CollectionShouldBeEmpty,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Exemple #2
0
        internal static void ValueShouldNotBePositiveInfinity <T>(ConditionValidator <T> validator, string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldNotBePositiveInfinity,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Exemple #3
0
        internal static void ValueShouldBeANumber <T>(ConditionValidator <T> validator, string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldBeANumber,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Exemple #4
0
        internal static void StringShouldMatchPattern(ConditionValidator <string> validator, string pattern,
                                                      string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldMatchPatternX,
                                                            conditionDescription, validator.ArgumentName, pattern.Stringify());

            validator.ThrowException(condition);
        }
Exemple #5
0
        internal static void StringShouldStartWith(ConditionValidator <string> validator, string value,
                                                   string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldStartWithX,
                                                            conditionDescription, validator.ArgumentName, value.Stringify());

            validator.ThrowException(condition);
        }
Exemple #6
0
        internal static void CollectionShouldContain <T>(ConditionValidator <T> validator, object value,
                                                         string conditionDescription) where T : IEnumerable
        {
            string condition = GetFormattedConditionMessage(validator, SR.CollectionShouldContainX,
                                                            conditionDescription, validator.ArgumentName, value.Stringify());

            validator.ThrowException(condition);
        }
Exemple #7
0
        internal static void StringShouldNotBeNullOrWhiteSpace(ConditionValidator <string> validator,
                                                               string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldNotBeNullOrWhiteSpace,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Exemple #8
0
        internal static void CollectionShouldNotContainAllOf <T>(ConditionValidator <T> validator, IEnumerable values,
                                                                 string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.CollectionShouldNotContainAllOfX,
                                                            conditionDescription, validator.ArgumentName, values.Stringify());

            validator.ThrowException(condition);
        }
Exemple #9
0
        internal static void ValueShouldNotBeAnEmptyString(ConditionValidator <string> validator,
                                                           string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldNotBeEmpty,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Exemple #10
0
        internal static void ValueShouldNotBeOfType <T>(ConditionValidator <T> validator, Type type,
                                                        string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldNotBeOfTypeX,
                                                            conditionDescription, validator.ArgumentName, type.Name);

            validator.ThrowException(condition);
        }
Exemple #11
0
        internal static void ValueShouldBeUnequalTo <T>(ConditionValidator <T> validator, T value,
                                                        string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldBeUnequalToX,
                                                            conditionDescription, validator.ArgumentName, value.Stringify());

            ConstraintViolationType violationType = GetEnumViolationOrDefault <T>();

            validator.ThrowException(condition, violationType);
        }
Exemple #12
0
        internal static void ExpressionEvaluatedFalse <T>(ConditionValidator <T> validator, string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldBeValid,
                                                            conditionDescription, validator.ArgumentName);

            string additionalMessage = GetActualValueMessage(validator);
            ConstraintViolationType violationType = GetEnumViolationOrDefault <T>();

            validator.ThrowException(condition, additionalMessage, violationType);
        }
Exemple #13
0
        internal static void ValueShouldNotBeBetween <T>(ConditionValidator <T> validator, T minValue, T maxValue,
                                                         string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldNotBeBetweenXAndY,
                                                            conditionDescription, validator.ArgumentName, minValue.Stringify(), maxValue.Stringify());

            string additionalMessage = GetActualValueMessage(validator);
            ConstraintViolationType violationType = GetEnumViolationOrDefault <T>();

            validator.ThrowException(condition, additionalMessage, violationType);
        }
Exemple #14
0
        internal static void CollectionShouldNotContainMoreOrEqual <T>(ConditionValidator <T> validator,
                                                                       int numberOfElements, string conditionDescription) where T : IEnumerable
        {
            string condition =
                GetFormattedConditionMessage(validator, SR.CollectionShouldNotContainXOrMoreElements,
                                             conditionDescription, validator.ArgumentName, numberOfElements);

            string additionalMessage = GetCollectionContainsElementsMessage(validator);

            validator.ThrowException(condition, additionalMessage);
        }
Exemple #15
0
        internal static void ValueShouldNotBeGreaterThanOrEqualTo <T>(ConditionValidator <T> validator, T maxValue,
                                                                      string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldNotBeGreaterThanOrEqualToX,
                                                            conditionDescription, validator.ArgumentName, maxValue.Stringify());

            string additionalMessage     = GetActualValueMessage(validator);
            ConstraintViolationType type =
                GetEnumViolationOrDefault <T>(ConstraintViolationType.OutOfRangeViolation);

            validator.ThrowException(condition, additionalMessage, type);
        }
Exemple #16
0
        internal static void LambdaXShouldHoldForValue <T>(ConditionValidator <T> validator, LambdaExpression lambda,
                                                           string conditionDescription)
        {
            string lambdaDefinition = GetLambdaDefinition(lambda);

            string condition = GetFormattedConditionMessage(validator, SR.LambdaXShouldHoldForValue,
                                                            conditionDescription, validator.ArgumentName, lambdaDefinition);

            string additionalMessage = GetActualValueMessage(validator);
            ConstraintViolationType violationType = GetEnumViolationOrDefault <T>();

            validator.ThrowException(condition, additionalMessage, violationType);
        }
Exemple #17
0
        internal static void CollectionShouldNotContainNumberOfElements <T>(ConditionValidator <T> validator,
                                                                            int numberOfElements, string conditionDescription)
        {
            string condition;

            if (numberOfElements == 1)
            {
                condition = GetFormattedConditionMessage(validator, SR.CollectionShouldNotContain1Element,
                                                         conditionDescription, validator.ArgumentName);
            }
            else
            {
                condition = GetFormattedConditionMessage(validator, SR.CollectionShouldNotContainXElements,
                                                         conditionDescription, validator.ArgumentName, numberOfElements);
            }

            validator.ThrowException(condition);
        }
Exemple #18
0
        internal static void StringShouldNotHaveLength(ConditionValidator <string> validator, int length,
                                                       string conditionDescription)
        {
            string condition;

            if (length == 1)
            {
                condition = GetFormattedConditionMessage(validator, SR.StringShouldNotBe1CharacterLong,
                                                         conditionDescription, validator.ArgumentName);
            }
            else
            {
                condition = GetFormattedConditionMessage(validator, SR.StringShouldNotBeXCharactersLong,
                                                         conditionDescription, validator.ArgumentName, length);
            }

            validator.ThrowException(condition);
        }
Exemple #19
0
        internal static void CollectionShouldContainMoreThan <T>(ConditionValidator <T> validator, int numberOfElements,
                                                                 string conditionDescription) where T : IEnumerable
        {
            string condition;

            if (numberOfElements == 1)
            {
                condition = GetFormattedConditionMessage(validator, SR.CollectionShouldContainMoreThan1Element,
                                                         conditionDescription, validator.ArgumentName);
            }
            else
            {
                condition = GetFormattedConditionMessage(validator, SR.CollectionShouldContainMoreThanXElements,
                                                         conditionDescription, validator.ArgumentName, numberOfElements);
            }

            string additionalMessage = GetCollectionContainsElementsMessage(validator);

            validator.ThrowException(condition, additionalMessage);
        }
Exemple #20
0
        internal static void StringShouldBeShorterThan(ConditionValidator <string> validator, int maxLength,
                                                       string conditionDescription)
        {
            string condition;

            if (maxLength == 1)
            {
                condition = GetFormattedConditionMessage(validator, SR.StringShouldBeShorterThan1Character,
                                                         conditionDescription, validator.ArgumentName);
            }
            else
            {
                condition = GetFormattedConditionMessage(validator, SR.StringShouldBeShorterThanXCharacters,
                                                         conditionDescription, validator.ArgumentName, maxLength);
            }

            string additionalMessage = GetActualStringLengthMessage(validator);

            validator.ThrowException(condition, additionalMessage);
        }