public static T NonNullValueOf <T>() { if (default(T) != null) { throw new InvalidOperationException("You cannot use this method with a non-nullable type."); } Matcher.Create <T>(x => x != null, "Non-null value of " + typeof(T).FullName); return(default(T)); }
public static T ValueInRange <T>(T min, T max, bool inclusive) where T : IComparable { if (inclusive) { var message = string.Format("Object greater than or equal to {0} and less than or equal to {1}", min, max); Matcher.Create <T>(x => x.CompareTo(min) >= 0 && x.CompareTo(max) <= 0, message); } else { var message = string.Format("Object greater than {0} and less than {1}", min, max); Matcher.Create <T>(x => x.CompareTo(min) > 0 && x.CompareTo(max) < 0, message); } return(default(T)); }
public static T[] ListContaining <T>(T obj) { Matcher.Create <IEnumerable <T> >(x => x.Contains(obj), $"Expected list containing [{obj}], but item was not found."); return(default(T[])); }
public static T[] ListContaining <T>(Expression <Func <T> > initializer) where T : class { Matcher.Create <IEnumerable <T> >(x => x.ContainsMatch(initializer), $"Expected list containing item matching [{initializer.Body}], but match was not found."); return(default(T[])); }
public static T ValueOf <T>(Expression <Func <T, bool> > matcher) { Matcher.Create(matcher, "Object matching " + matcher.Body); return(default(T)); }
public static T ValueOf <T>() { Matcher.Create <T>(null, "Any value of type " + typeof(T).FullName); return(default(T)); }
public static T NonDefaultValueOf <T>() where T : struct { Matcher.Create <T>(x => !Equals(x, default(T)), "Non-default value of " + typeof(T).FullName); return(default(T)); }