Пример #1
0
        public static MandateContext <T> IsNotNull <T>(this MandateContext <T> context) where T : class
        {
            Mandate.That(context, context.Value == default(T), () => new ArgumentNullException(context.ParamName));


            return(new MandateContext <T>(context));
        }
Пример #2
0
        public static MandateContext <T> Is <T>(this MandateContext <T> context, T comparisonValue) where T : IComparable
        {
            Mandate.That(context, context.Value.CompareTo(comparisonValue) == 0, () =>
                         new ArgumentOutOfRangeException(context.ParamName, context.Value,
                                                         $"Parameter must be equal to {context.Value}"));

            return(new MandateContext <T>(context));
        }
Пример #3
0
 public static void That <T, TException>(MandateContext <T> context, bool condition, Func <TException> defer)
     where TException : Exception, new()
 {
     if (condition)
     {
         throw defer.Invoke();
     }
 }
        public static MandateContext <IEnumerable <T> > Contains <T>(this MandateContext <IEnumerable <T> > context, T value)
        {
            context.IsNotNull();

            Mandate.That(context, !context.Value.Contains(value), () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <IEnumerable <T> >(context));
        }
        public static MandateContext <T[]> SizeIs <T>(this MandateContext <T[]> context, int expected)
        {
            context.IsNotNull();

            Mandate.That(context, context.Value.Length != expected, () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <T[]>(context));
        }
        public static MandateContext <T[]> HasAny <T>(this MandateContext <T[]> context)
        {
            context.IsNotNull();

            Mandate.That(context, !context.Value.Any(), () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <T[]>(context));
        }
        public static MandateContext <IDictionary <TKey, TValue> > SizeIs <TKey, TValue>(
            this MandateContext <IDictionary <TKey, TValue> > context, int expected)
        {
            context.IsNotNull();


            Mandate.That(context, context.Value.Count != expected, () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <IDictionary <TKey, TValue> >(context));
        }
        public static MandateContext <IEnumerable <T> > SizeIs <T>(this MandateContext <IEnumerable <T> > context,
                                                                   int expected)
        {
            context.IsNotNull();

            Mandate.That(context, context.Value.Count() != expected,
                         () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <IEnumerable <T> >(context));
        }
        public static MandateContext <IDictionary <TKey, TValue> > HasAny <TKey, TValue>(
            this MandateContext <IDictionary <TKey, TValue> > context)
        {
            context.IsNotNull();


            Mandate.That(context, context.Value.Count == 0, () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <IDictionary <TKey, TValue> >(context));
        }
        public static MandateContext <IDictionary <TKey, TValue> > Contains <TKey, TValue>(
            this MandateContext <IDictionary <TKey, TValue> > context, KeyValuePair <TKey, TValue> value)
        {
            context.IsNotNull();


            Mandate.That(context, context.Value.Contains(value), () => new ArgumentNullException(context.ParamName));

            return(new MandateContext <IDictionary <TKey, TValue> >(context));
        }
Пример #11
0
        public static MandateContext <T> IsNotBetween <T>(this MandateContext <T> context, T minValue, T maxValue)
            where T : IComparable
        {
            Mandate.That(context,
                         context.Value.CompareTo(minValue) == 1 && context.Value.CompareTo(maxValue) == -1,
                         () =>
                         new ArgumentOutOfRangeException(context.ParamName, context.Value,
                                                         $"Parameter must be greater than {minValue} and less than {maxValue}"));

            return(new MandateContext <T>(context));
        }
Пример #12
0
        public static MandateContext <T> IsBetween <T>(this MandateContext <T> context, T minValue, T maxValue)
            where T : IComparable
        {
            Mandate.That(context,
                         context.Value.CompareTo(minValue) != -1 && context.Value.CompareTo(maxValue) != 1,
                         () =>
                         new ArgumentOutOfRangeException(context.ParamName, context.Value,
                                                         string.Format("Parameter must be greater than or equal to {0} and less than or equal to {1}",
                                                                       minValue, maxValue)));

            return(new MandateContext <T>(context));
        }
Пример #13
0
        public static MandateContext <T> IsLessThanOrEqualTo <T>(this MandateContext <T> context, T comparisonValue)
            where T : IComparable
        {
            var val = context.Value.CompareTo(comparisonValue);

            Mandate.That(context, context.Value.CompareTo(comparisonValue) == 0,
                         () =>
                         new ArgumentOutOfRangeException(context.ParamName, context.Value,
                                                         $"Parameter must be less than {comparisonValue}"));


            return(context);
        }
Пример #14
0
 internal DateTimeContext(MandateContext <DateTime> parentContext) : base(parentContext)
 {
 }