Beispiel #1
0
 /// <summary>
 /// Constrains the argument to be of the specified type.
 /// </summary>
 /// <typeparam name="T">The type of argument in the method signature.</typeparam>
 /// <param name="manager">The constraint manager.</param>
 /// <param name="type">The type to constrain the argument with.</param>
 /// <returns>A dummy value.</returns>
 public static T IsInstanceOf <T>(this IArgumentConstraintManager <T> manager, Type type)
 {
     return(manager.NullCheckedMatches(x => type.IsAssignableFrom(x.GetType()), x => x.Write("Instance of ").Write(type.FullName)));
 }
Beispiel #2
0
 /// <summary>
 /// The tested argument collection should contain the same elements as the
 /// specified collection, in the same order.
 /// </summary>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <param name="values">The sequence to test against.</param>
 /// <typeparam name="T">The type of argument to constrain.</typeparam>
 /// <returns>A dummy argument value.</returns>
 public static T IsSameSequenceAs <T>(this IArgumentConstraintManager <T> manager, params object[] values) where T : IEnumerable
 {
     return(manager.IsSameSequenceAs((IEnumerable)values));
 }
Beispiel #3
0
 /// <summary>
 /// Tests that the IEnumerable contains no items.
 /// </summary>
 /// <typeparam name="T">The type of argument.</typeparam>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <returns>A dummy argument value.</returns>
 public static T IsEmpty <T>(this IArgumentConstraintManager <T> manager) where T : IEnumerable
 {
     return(manager.NullCheckedMatches(
                x => !x.Cast <object>().Any(),
                x => x.Write("empty collection")));
 }
Beispiel #4
0
 /// <summary>
 /// Constrains the string so that it must end with the specified value.
 /// </summary>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <param name="value">The value the string should end with.</param>
 /// <returns>A dummy argument value.</returns>
 public static string EndsWith(this IArgumentConstraintManager <string> manager, string value)
 {
     return(manager.NullCheckedMatches(x => x.EndsWith(value, StringComparison.Ordinal), x => x.Write("string that ends with ").WriteArgumentValue(value)));
 }
Beispiel #5
0
        /// <summary>
        /// Constrains argument value so that it must be greater than the specified value.
        /// </summary>
        /// <param name="manager">The constraint manager to match the constraint.</param>
        /// <param name="value">The value the string should start with.</param>
        /// <typeparam name="T">The type of argument to constrain.</typeparam>
        /// <returns>A dummy argument value.</returns>
        public static T IsGreaterThan <T>(this IArgumentConstraintManager <T> manager, T value) where T : IComparable
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(x => x.CompareTo(value) > 0, x => x.Write("greater than ").WriteArgumentValue(value)));
        }
Beispiel #6
0
        /// <summary>
        /// Constrains an argument so that it must be null (Nothing in VB).
        /// </summary>
        /// <typeparam name="T">The type of the argument.</typeparam>
        /// <param name="manager">The constraint manager to match the constraint.</param>
        /// <returns>A dummy argument value.</returns>
        public static T IsNull <T>(this IArgumentConstraintManager <T> manager) where T : class
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(x => x == null, x => x.Write("NULL")));
        }
Beispiel #7
0
 /// <summary>
 /// Constrains the string argument to contain the specified text.
 /// </summary>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <param name="value">The string the argument string should contain.</param>
 /// <returns>A dummy argument value.</returns>
 public static string Contains(this IArgumentConstraintManager <string> manager, string value)
 {
     return(manager.NullCheckedMatches(x => x.Contains(value), x => x.Write("string that contains ").WriteArgumentValue(value)));
 }
 protected override void CreateConstraint(IArgumentConstraintManager <string> scope)
 {
     scope.EndsWith("table");
 }
Beispiel #9
0
 protected override void CreateConstraint(IArgumentConstraintManager <string> scope)
 {
     scope.IsNullOrEmpty();
 }
 protected override void CreateConstraint(IArgumentConstraintManager <IEnumerable <object> > scope)
 {
     scope.Contains(10);
 }
Beispiel #11
0
 public NotArgumentConstraintManager(IArgumentConstraintManager <T> parent)
 {
     this.parent = parent;
 }
Beispiel #12
0
 protected override void CreateConstraint(IArgumentConstraintManager <string> scope)
 {
     scope.StartsWith("abc");
 }
        protected override void CreateConstraint(IArgumentConstraintManager <string> scope)
        {
            Guard.AgainstNull(scope, nameof(scope));

            scope.Matches(x => x == null || x == "foo", x => x.Write("string that is \"foo\" or is empty"));
        }
Beispiel #14
0
 protected override void CreateConstraint(IArgumentConstraintManager <object> scope)
 {
     scope.IsSameAs(TheRealThing);
 }
Beispiel #15
0
        /// <summary>
        /// Constrains the argument with a predicate.
        /// </summary>
        /// <param name="scope">
        /// The constraint manager.
        /// </param>
        /// <param name="predicate">
        /// The predicate that should constrain the argument.
        /// </param>
        /// <param name="description">
        /// A human readable description of the constraint.
        /// </param>
        /// <typeparam name="T">
        /// The type of argument in the method signature.
        /// </typeparam>
        /// <returns>
        /// A dummy argument value.
        /// </returns>
        public static T Matches <T>(this IArgumentConstraintManager <T> scope, Func <T, bool> predicate, string description)
        {
            Guard.AgainstNull(scope, nameof(scope));

            return(scope.Matches(predicate, x => x.Write(description)));
        }
 /// <summary>
 /// Matches any value that is equivalent to <paramref name="expected"/>.
 /// </summary>
 /// <typeparam name="T">Type of the argument to check.</typeparam>
 /// <param name="mgr">The <seealso cref="IArgumentConstraintManager{T}"/> with the actual object to match.</param>
 /// <param name="expected">The expected object to match.</param>
 /// <returns>A dummy argument value.</returns>
 public static T IsEquivalentTo <T>(this IArgumentConstraintManager <T> mgr, T expected)
 {
     return(mgr.IsEquivalentTo(expected, config => config));
 }
Beispiel #17
0
        /// <summary>
        /// Constrains the argument with a predicate.
        /// </summary>
        /// <param name="manager">
        /// The constraint manager.
        /// </param>
        /// <param name="predicate">
        /// The predicate that should constrain the argument.
        /// </param>
        /// <param name="descriptionFormat">
        /// A human readable description of the constraint format string.
        /// </param>
        /// <param name="args">
        /// Arguments for the format string.
        /// </param>
        /// <typeparam name="T">
        /// The type of argument in the method signature.
        /// </typeparam>
        /// <returns>
        /// A dummy argument value.
        /// </returns>
        public static T Matches <T>(this IArgumentConstraintManager <T> manager, Func <T, bool> predicate, string descriptionFormat, params object[] args)
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(predicate, x => x.Write(string.Format(CultureInfo.CurrentCulture, descriptionFormat, args))));
        }
Beispiel #18
0
 protected override void CreateConstraint(IArgumentConstraintManager <object> scope)
 {
     scope.NullCheckedMatches(x => x is string, x => x.Write("is of type string"));
 }
Beispiel #19
0
        public static T Matches <T>(this IArgumentConstraintManager <T> scope, Expression <Func <T, bool> > predicate)
        {
            Guard.AgainstNull(predicate, nameof(predicate));

            return(scope.Matches(predicate.Compile(), predicate.ToString()));
        }
 public static string Contains(this IArgumentConstraintManager <string> scope, string value)
 {
     return(scope.Matches(x => x.Contains(value), string.Format("Contains \"{0}\"", value)));
 }
Beispiel #21
0
 /// <summary>
 /// Constrains the sequence so that it must contain the specified value.
 /// </summary>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <param name="value">The value the collection should contain.</param>
 /// <typeparam name="T">The type of sequence.</typeparam>
 /// <returns>A dummy argument value.</returns>
 public static T Contains <T>(this IArgumentConstraintManager <T> manager, object value) where T : IEnumerable
 {
     return(manager.NullCheckedMatches(
                x => x.Cast <object>().Contains(value),
                x => x.Write("sequence that contains the value ").WriteArgumentValue(value)));
 }
 public static string StartsWith(this IArgumentConstraintManager <string> scope, string beginning)
 {
     return(scope.Matches(x => x.StartsWith(beginning), string.Format("Starts with \"{0}\"", beginning)));
 }
Beispiel #23
0
 /// <summary>
 /// Constrains the string so that it must be null or empty.
 /// </summary>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <returns>A dummy argument value.</returns>
 public static string IsNullOrEmpty(this IArgumentConstraintManager <string> manager)
 {
     return(manager.Matches(x => string.IsNullOrEmpty(x), "NULL or string.Empty"));
 }
Beispiel #24
0
 /// <summary>
 /// The tested argument collection should contain the same elements as the
 /// as the specified collection.
 /// </summary>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <param name="value">The sequence to test against.</param>
 /// <typeparam name="T">The type of argument to constrain.</typeparam>
 /// <returns>A dummy argument value.</returns>
 public static T IsSameSequenceAs <T>(this IArgumentConstraintManager <T> manager, IEnumerable value) where T : IEnumerable
 {
     return(manager.NullCheckedMatches(
                x => x.Cast <object>().SequenceEqual(value.Cast <object>()),
                x => x.Write("specified sequence")));
 }
 protected override void CreateConstraint(IArgumentConstraintManager<CancellationToken> scope)
 {
     scope.IsCanceled();
 }
Beispiel #26
0
 protected override void CreateConstraint(IArgumentConstraintManager <object> scope)
 {
     scope.IsNull();
 }