protected override void CreateConstraint(IArgumentConstraintManager <object> scope) { scope.NullCheckedMatches(x => x is string, x => x.Write("is of type string")); }
/// <summary> /// Constrains the string so that it must start with 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> /// <returns>A dummy argument value.</returns> public static string StartsWith(this IArgumentConstraintManager <string> manager, string value) { return(manager.NullCheckedMatches(x => x.StartsWith(value, StringComparison.Ordinal), x => x.Write("string that starts with ").WriteArgumentValue(value))); }
/// <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))); }
/// <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))); }
/// <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.ToString()))); }
/// <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"))); }
/// <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"))); }