Пример #1
0
        internal static void CollectionShouldBeEmpty <T>(ContractValidator <T> validator, string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.CollectionShouldBeEmpty,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Пример #2
0
        internal static void ValueShouldBeNull <T>(ContractValidator <T> validator, string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldBeNull,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Пример #3
0
        internal static void ValueShouldNotBeOfType <T>(ContractValidator <T> validator, Type type,
                                                        string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldNotBeOfTypeX,
                                                            conditionDescription, validator.ArgumentName, type.Name);

            validator.ThrowException(condition);
        }
Пример #4
0
        internal static void CollectionShouldNotContainAllOf <T>(ContractValidator <T> validator, IEnumerable values,
                                                                 string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.CollectionShouldNotContainAllOfX,
                                                            conditionDescription, validator.ArgumentName, values.Stringify());

            validator.ThrowException(condition);
        }
Пример #5
0
        internal static void ValueShouldNotBeAnEmptyString(ContractValidator <string> validator,
                                                           string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldNotBeEmpty,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Пример #6
0
        internal static void StringShouldNotBeNullOrWhiteSpace(ContractValidator <string> validator,
                                                               string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldNotBeNullOrWhiteSpace,
                                                            conditionDescription, validator.ArgumentName);

            validator.ThrowException(condition);
        }
Пример #7
0
        internal static void CollectionShouldContain <T>(ContractValidator <T> validator, object value,
                                                         string conditionDescription) where T : IEnumerable
        {
            string condition = GetFormattedConditionMessage(validator, SR.CollectionShouldContainX,
                                                            conditionDescription, validator.ArgumentName, value.Stringify());

            validator.ThrowException(condition);
        }
Пример #8
0
        internal static void StringShouldStartWith(ContractValidator <string> validator, string value,
                                                   string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.StringShouldStartWithX,
                                                            conditionDescription, validator.ArgumentName, value.Stringify());

            validator.ThrowException(condition);
        }
Пример #9
0
        internal static void ExpressionEvaluatedFalse <T>(ContractValidator <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);
        }
Пример #10
0
        internal static void ValueShouldBeUnequalTo <T>(ContractValidator <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);
        }
Пример #11
0
        internal static void ValueShouldNotBeBetween <T>(ContractValidator <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);
        }
Пример #12
0
        internal static void CollectionShouldNotContainMoreOrEqual <T>(ContractValidator <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);
        }
Пример #13
0
        internal static void ValueShouldBeGreaterThan <T>(ContractValidator <T> validator, T minValue,
                                                          string conditionDescription)
        {
            string condition = GetFormattedConditionMessage(validator, SR.ValueShouldBeGreaterThanX,
                                                            conditionDescription, validator.ArgumentName, minValue.Stringify());

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

            validator.ThrowException(condition, additionalMessage, violationType);
        }
Пример #14
0
        public static ContractValidator <T> ExistsIn <T>(
            this ContractValidator <T> validator, IEnumerable <T> collection)
        {
            // Value, ArgumentName and ThrowException won't show up in the
            // IntelliSense dropdown list, but you can use them.
            if (collection == null || !collection.Contains(validator.Value))
            {
                validator.ThrowException(validator.ArgumentName +
                                         " should be in the supplied collection");
            }

            return(validator);
        }
Пример #15
0
        internal static void LambdaXShouldHoldForValue <T>(ContractValidator <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);
        }
Пример #16
0
        internal static void StringShouldNotHaveLength(ContractValidator <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);
        }
Пример #17
0
        internal static void CollectionShouldNotContainNumberOfElements <T>(ContractValidator <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);
        }
Пример #18
0
        internal static void CollectionShouldContainMoreThan <T>(ContractValidator <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);
        }
Пример #19
0
        internal static void StringShouldBeShorterThan(ContractValidator <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);
        }