Пример #1
0
        internal static IStringAssertion DoesNotEndWith(this StringAssertion source, string text)
        {
            source.Extend(x => AssertResult.New(!x.EndsWith(text, StringComparison.CurrentCultureIgnoreCase),
                                                Resources.DoesNotEndWith, text));

            return(source);
        }
Пример #2
0
        public IMixedTypeAssertion <T, U> IsEqualTo <S>(S comparedTo)
        {
            Extend((x, t) =>
            {
                if (t == typeof(U))
                {
                    if (_newType == null)
                    {
                        return(AssertResult.New(comparedTo == null, Resources.IsEqualTo, comparedTo));
                    }

                    return(AssertResult.New(_newType.Equals(comparedTo), Resources.IsEqualTo, comparedTo == null ? "null" : comparedTo.ToString()));
                }
                else
                {
                    if (x == null)
                    {
                        return(AssertResult.New(comparedTo == null, Resources.IsEqualTo, comparedTo));
                    }

                    return(AssertResult.New(x.Equals(comparedTo), Resources.IsEqualTo, comparedTo == null ? "null" : comparedTo.ToString()));
                }
            });
            return(this);
        }
Пример #3
0
 public IClassAssertion <T> PropertyValuesMatch <S>(S item, bool throwExceptionOnPropertyMismatch = false, string[] ignoreProperties = null)
 {
     Extend(x =>
     {
         return(AssertResult.New(PropertiesMatch(x, item, throwExceptionOnPropertyMismatch: throwExceptionOnPropertyMismatch, ignoreProperties: ignoreProperties), "Property values do not match"));
     });
     return(this);
 }
Пример #4
0
 public IClassAssertion <T> PropertyValuesDoNotMatch <S>(S item, bool throwExceptionOnPropertyMismatch = false, Func <string, object, object, bool> propertyChanged = null, string[] ignoreProperties = null)
 {
     Extend(x =>
     {
         return(AssertResult.New(!PropertiesMatch(x, item, throwExceptionOnPropertyMismatch: throwExceptionOnPropertyMismatch, propertyChanged: propertyChanged, ignoreProperties: ignoreProperties), "Property values match"));
     });
     return(this);
 }
Пример #5
0
 public IClassAssertion <T> PropertyValuesDoNotMatch <S>(S item, Func <string, object, object, bool> propertyChanged = null)
 {
     Extend(x =>
     {
         return(AssertResult.New(!PropertiesMatch(x, item, propertyChanged), "Property values match"));
     });
     return(this);
 }
Пример #6
0
 public IClassAssertion <T> PropertyValuesMatch <S>(S item)
 {
     Extend(x =>
     {
         return(AssertResult.New(PropertiesMatch(x, item), "Property values do not match"));
     });
     return(this);
 }
Пример #7
0
 private static IStringAssertion IsValidISBN10(this IStringAssertionU source)
 {
     source.Extend(x =>
     {
         return(AssertResult.New(ValidIsbn10(x), Resources.IsValidISBN));
     });
     return((IStringAssertion)source);
 }
Пример #8
0
        public IDictionaryAssertion <T1, T2> ContainsKey(T1 key)
        {
            Extend(x => {
                return(AssertResult.New(x.ContainsKey(key), Resources.ContainsKey, key));
            });

            return(this);
        }
Пример #9
0
 public static IStringAssertion IsValidPersonalNumber(this IStringAssertionU source)
 {
     source.Extend(x =>
     {
         return(AssertResult.New(Luhn.IsValid(x.ToIntArray()), Resources.IsValidPersonalNumber));
     });
     return((IStringAssertion)source);
 }
Пример #10
0
        public static IStringAssertion IsNotValidImoNr(this IStringAssertionU source)
        {
            source.Extend(x =>
            {
                return(AssertResult.New(!ImoValidator.IsValid(x), Resources.IsNotValidImoNr));
            });

            return((IStringAssertion)source);
        }
Пример #11
0
 public INumberAssertion <T> IsNotWithin(T min, T max)
 {
     Extend(x =>
     {
         dynamic d = x;
         return(AssertResult.New(d < min || d > max, Resources.IsNotWithin, min, max));
     });
     return(this);
 }
Пример #12
0
 internal static EnumerableAssertion ContainsMoreThan(this EnumerableAssertion source, int nElements)
 {
     source.Extend(x =>
     {
         var count = GetCount(x);
         return(AssertResult.New(count > nElements, Resources.ContainsMoreThan, nElements));
     });
     return(source);
 }
Пример #13
0
 internal static EnumerableAssertion IsEmpty(this EnumerableAssertion source)
 {
     source.Extend(x =>
     {
         var c = GetCount(x);
         return(AssertResult.New(c == 0, Resources.IsEmpty));
     });
     return(source);
 }
Пример #14
0
 public IDateTimeAssertion SameMinuteAs(DateTime date)
 {
     Extend(x =>
     {
         var diff = (Item - date).TotalMinutes;
         return(AssertResult.New(diff >= 0 && diff <= 1.0, Resources.SameMinuteAs, date.ToString("yyyy-MM-dd HH:mm")));
     });
     return(this);
 }
Пример #15
0
 internal static StringAssertion DoesNotContainDigit(this StringAssertion source)
 {
     source.Extend(x =>
     {
         bool isValid = Regex.IsMatch(x, @"\d");
         return(AssertResult.New(!isValid, Resources.DoesNotContainDigit));
     });
     return(source);
 }
Пример #16
0
 public IDateTimeAssertion SameYearAs(DateTime date)
 {
     Extend(x =>
     {
         var sameYear = x.Date.Year == date.Year;
         return(AssertResult.New(sameYear, Resources.SameYearAs, date.ToString("yyyy")));
     });
     return(this);
 }
Пример #17
0
 public static IStringAssertion IsValidSocialSecurityNumber(this IStringAssertionU source)
 {
     source.Extend(x =>
     {
         var isValid = Regex.IsMatch(x, _regex);
         return(AssertResult.New(isValid, Resources.IsValidSocialSecurityNumber));
     });
     return((IStringAssertion)source);
 }
Пример #18
0
 public static IStringAssertion IsValidZipCode(this IStringAssertionU source)
 {
     source.Extend(x =>
     {
         var isValid = Regex.IsMatch(x, _regex);
         return(AssertResult.New(isValid, Resources.IsValidZipCode));
     });
     return((IStringAssertion)source);
 }
Пример #19
0
 public IEnumerableAssertion <T> ContainsLessThan(int nElements)
 {
     Extend(x =>
     {
         var count = x.Count();
         return(AssertResult.New(count < nElements, Resources.ContainsLessThan, nElements));
     });
     return(this);
 }
Пример #20
0
 public IDateTimeAssertion IsWithin(DateTime min, DateTime max)
 {
     Extend(x =>
     {
         dynamic d = x;
         return(AssertResult.New(d >= min && d <= max, Resources.IsWithin, min, max));
     });
     return(this);
 }
Пример #21
0
 public IDateTimeAssertion IsNotWithin(DateTime min, DateTime max)
 {
     Extend(x =>
     {
         dynamic d = Item;
         return(AssertResult.New(d < min || d > max, Resources.IsNotWithin, min, max));
     });
     return(this);
 }
Пример #22
0
 public IDateTimeAssertion NotSameSecondAs(DateTime date)
 {
     Extend(x =>
     {
         var diff = (x - date).TotalSeconds;
         return(AssertResult.New(diff < 0 || diff > 1.0, Resources.NotSameSecondAs, date.ToString("yyyy-MM-dd HH:mm:ss")));
     });
     return(this);
 }
Пример #23
0
        public IStringAssertion DoesNotMatch(string regex, RegexOptions options = RegexOptions.None)
        {
            Extend(x =>
            {
                _previousMatch = Regex.Match(x, regex, options);
                return(AssertResult.New(!_previousMatch.Success, Resources.DoesNotMatch, regex));
            });

            return(this);
        }
Пример #24
0
        public static IStringAssertion IsNotValidPhoneNumber(this IStringAssertionU source)
        {
            source.Extend(x =>
            {
                var isValid = Regex.IsMatch(x, _regex);

                return(AssertResult.New(!isValid, Resources.IsNotValidPhoneNumber));
            });
            return((IStringAssertion)source);
        }
Пример #25
0
        public IEnumerableAssertion <T> Contains(params T[] items)
        {
            Extend(x =>
            {
                var containsItems = items.All(y => x.Contains(y));

                return(AssertResult.New(containsItems, Resources.ContainsItems, String.Join(",", items.Select(y => y.ToString()).ToArray())));
            });
            return(this);
        }
Пример #26
0
        public IDateTimeAssertion NotSameMonthAs(DateTime date)
        {
            Extend(x =>
            {
                var sameYear  = x.Date.Year == date.Year;
                var sameMonth = x.Date.Month == date.Month;

                return(AssertResult.New(!(sameYear && sameMonth), Resources.NotSameMonthAs, date.ToString("yyyy-MM")));
            });
            return(this);
        }
Пример #27
0
        internal static IAssertion <T> IsEqualTo <T>(this Assertion <T> source, T comparedTo)
        {
            source.Extend(x =>
            {
                if (x == null)
                {
                    return(AssertResult.New(comparedTo == null, Resources.IsEqualTo, comparedTo));
                }

                return(AssertResult.New(x.Equals(comparedTo), Resources.IsEqualTo, comparedTo == null ? "null" : comparedTo.ToString()));
            });
            return(source);
        }
Пример #28
0
        public IClassAssertion <T> IsNotPartOf(IEnumerable <T> enumerable)
        {
            Extend(x =>
            {
                if (enumerable == null || x == null)
                {
                    return(AssertResult.New(true, Resources.IsNotPartOf));
                }

                return(AssertResult.New(!enumerable.Contains(x), Resources.IsNotPartOf));
            });
            return(this);
        }
Пример #29
0
        public IClassAssertion <T> IsEqualTo <S>(S comparedTo)
        {
            Extend(x =>
            {
                if (x == null)
                {
                    return(AssertResult.New(comparedTo == null, Resources.IsEqualTo, comparedTo));
                }

                return(AssertResult.New(x.Equals(comparedTo), Resources.IsEqualTo, comparedTo == null ? "null" : comparedTo.ToString()));
            });
            return(this);
        }
Пример #30
0
        internal static StringAssertion IsNotValidEmail(this StringAssertion source)
        {
            source.Extend(x =>
            {
                //bool isEmail = Regex.IsMatch(x, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z");

                RegexHelper helper = new RegexHelper();
                var isEmail        = helper.IsValidEmail(x);

                return(AssertResult.New(string.IsNullOrWhiteSpace(x) || !isEmail, Resources.IsNotValidEmail));
            });

            return(source);
        }