Exemple #1
0
 /// <summary>
 /// Constrains the argument to be not null (Nothing in VB) and to match
 /// the specified predicate.
 /// </summary>
 /// <typeparam name="T">The type of the argument to constrain.</typeparam>
 /// <param name="manager">The constraint manager.</param>
 /// <param name="predicate">The predicate that constrains non null values.</param>
 /// <param name="descriptionWriter">An action that writes a description of the constraint
 /// to the output.</param>
 /// <returns>A dummy argument value.</returns>
 public static T NullCheckedMatches <T>(this IArgumentConstraintManager <T> manager, Func <T, bool> predicate, Action <IOutputWriter> descriptionWriter)
 {
     return(manager.Matches(
                x => ((object)x) != null && predicate(x),
                descriptionWriter));
 }
Exemple #2
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)
 {
     return(scope.Matches(predicate, x => x.Write(description)));
 }
Exemple #3
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
 {
     return(manager.Matches(x => x == null, x => x.Write("NULL")));
 }
 public static string IsLongerThan(this IArgumentConstraintManager <string> validations, int length)
 {
     return(validations.Matches(x => x.Length > length, string.Format(CultureInfo.InvariantCulture, "Longer than {0}", length)));
 }
 public static FakeManager Fakes(this IArgumentConstraintManager <FakeManager> scope, object fake)
 {
     return(scope.Matches(x => x.Equals(Fake.GetFakeManager(fake)), "Specified FakeObject"));
 }
Exemple #6
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)));
        }
 internal static FakeOptions HasArgumentsForConstructor(this IArgumentConstraintManager <FakeOptions> scope, IEnumerable <object> argumentsForConstructor)
 {
     return(scope.Matches(x => argumentsForConstructor.SequenceEqual(x.ArgumentsForConstructor), "Constructor arguments ({0})".FormatInvariant(string.Join(", ", argumentsForConstructor.Select(x => x.ToString()).ToArray()))));
 }
 public static IEnumerable <T> IsSameCollectionAs <T>(this IArgumentConstraintManager <IEnumerable <T> > manager, IEnumerable <T> value, Action <ComparisonConfig> config)
 {
     return(manager.Matches(
                x => x.IsSameCollectionAs(value, config),
                x => x.Write("object that is same collection by property values as ").WriteArgumentValue(value)));
 }
Exemple #9
0
 public static T HasSamePropertyValuesAs <T>(this IArgumentConstraintManager <T> manager, object value, bool ignoreCollectionOrder, IEnumerable <string> membersToIgnore)
 {
     return(manager.Matches(
                x => x.HasSamePropertyValuesAs(value, ignoreCollectionOrder, membersToIgnore),
                x => x.Write("object that matches by property values as ").WriteArgumentValue(value)));
 }
Exemple #10
0
 public static T HasSamePropertyValuesAs <T>(this IArgumentConstraintManager <T> manager, object value, Action <ComparisonConfig> config)
 {
     return(manager.Matches(
                x => x.HasSamePropertyValuesAs(value, config),
                x => x.Write("object that matches by property values as ").WriteArgumentValue(value)));
 }
 internal static ParsedArgumentExpression ProducesValue(this IArgumentConstraintManager <ParsedArgumentExpression> scope, object expectedValue)
 {
     return(scope.Matches(x => object.Equals(expectedValue, Helpers.GetValueProducedByExpression(x.Expression)),
                          string.Format(CultureInfo.InvariantCulture, "Expression that produces the value {0}", expectedValue)));
 }
Exemple #12
0
 public static SniperSnapshot HasState(this IArgumentConstraintManager <SniperSnapshot> iacm, SniperState state)
 {
     return(iacm.Matches(ss => ss.State == state));
 }
        public static T BeEquivalentTo <T>(this IArgumentConstraintManager <T> comparacao, T valor)
        {
            var mensagem = string.Empty;

            return(comparacao.Matches(a => BeEquivalentTo(a, valor, out mensagem), a => a.Write(mensagem)));
        }
 public static Expression ProducesValue(this IArgumentConstraintManager <Expression> scope, object expectedValue)
 {
     return(scope.Matches(
                x => object.Equals(expectedValue, x.Evaluate()),
                string.Format(CultureInfo.InvariantCulture, "Expression that produces the value {0}", expectedValue)));
 }
Exemple #15
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))));
        }
Exemple #16
0
 public static IEnumerable <T> IsSameCollectionAs <T>(this IArgumentConstraintManager <IEnumerable <T> > manager, IEnumerable <T> value, IEnumerable <string> membersToIgnore)
 {
     return(manager.Matches(
                x => x.IsSameCollectionAs(value, membersToIgnore),
                x => x.Write("object that is same collection by property values as ").WriteArgumentValue(value)));
 }
Exemple #17
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"));
 }
        /// <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)
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(x => string.IsNullOrEmpty(x), "NULL or string.Empty"));
        }
 internal static FakeOptions HasRecorder(this IArgumentConstraintManager <FakeOptions> scope, ISelfInitializingFakeRecorder recorder)
 {
     return(scope.Matches(x => recorder.Equals(x.SelfInitializedFakeRecorder), "Specified recorder"));
 }
Exemple #20
0
        public static T?IsNull <T>(this IArgumentConstraintManager <T?> manager) where T : struct
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(x => x == null, x => x.Write("NULL")));
        }
 internal static FakeOptions Wraps(this IArgumentConstraintManager <FakeOptions> scope, object wrappedInstance)
 {
     return(scope.Matches(x => object.ReferenceEquals(x.WrappedInstance, wrappedInstance), "Wraps {0}".FormatInvariant(wrappedInstance)));
 }
Exemple #22
0
        protected override void CreateConstraint(IArgumentConstraintManager <string> scope)
        {
            FakeItEasy.Guard.AgainstNull(scope, "scope");

            scope.Matches(x => x == null || x == "foo", x => x.Write("string that is \"foo\" or is empty"));
        }
 public static T IsThisSequence <T>(this IArgumentConstraintManager <T> scope, T collection) where T : IEnumerable
 {
     return(scope.Matches(
                x => x.Cast <object>().SequenceEqual(collection.Cast <object>()),
                "This sequence: " + collection.Cast <object>().ToCollectionString(x => x.ToString(), ", ")));
 }
 public static string Contains(this IArgumentConstraintManager <string> scope, string value)
 {
     return(scope.Matches(x => x.Contains(value), string.Format(CultureInfo.CurrentCulture, "Contains \"{0}\"", value)));
 }
Exemple #25
0
 /// <summary>
 /// Tests that the passed in argument is equal to the specified value.
 /// </summary>
 /// <typeparam name="T">The type of the argument.</typeparam>
 /// <param name="manager">The constraint manager to match the constraint.</param>
 /// <param name="value">The value to compare to.</param>
 /// <returns>A dummy argument value.</returns>
 public static T IsEqualTo <T>(this IArgumentConstraintManager <T> manager, T value)
 {
     return(manager.Matches(
                x => Equals(value, x),
                x => x.Write("equal to ").WriteArgumentValue(value)));
 }
 public static string StartsWith(this IArgumentConstraintManager <string> scope, string beginning)
 {
     return(scope.Matches(
                x => x.StartsWith(beginning, StringComparison.CurrentCulture), string.Format(CultureInfo.CurrentCulture, "Starts with \"{0}\"", beginning)));
 }
Exemple #27
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)
 {
     return(manager.Matches(predicate, x => x.Write(string.Format(descriptionFormat, args))));
 }
 public static string IsLongerThan(this IArgumentConstraintManager <string> validations, int length)
 {
     return(validations.Matches(x => x.Length > length, $"Longer than {length}"));
 }
Exemple #29
0
 public static T Matches <T>(this IArgumentConstraintManager <T> scope, Expression <Func <T, bool> > predicate)
 {
     return(scope.Matches(predicate.Compile(), predicate.ToString()));
 }
 public static string StartsWith(this IArgumentConstraintManager <string> scope, string beginning)
 {
     return(scope.Matches(x => x.StartsWith(beginning, StringComparison.CurrentCulture), $@"Starts with ""{beginning}"""));
 }