示例#1
0
        public static IAfterCallSpecifiedConfiguration Throws <T>(this IExceptionThrowerConfiguration configuration) where T : Exception, new()
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.Throws(_ => new T()));
        }
示例#2
0
        /// <summary>
        /// Throws the specified exception when the currently configured
        /// call gets called.
        /// </summary>
        /// <param name="configuration">The configuration to use.</param>
        /// <param name="exceptionFactory">A function that returns the exception to throw when invoked.</param>
        /// <returns>Configuration object.</returns>
        public static IAfterCallSpecifiedConfiguration Throws(this IExceptionThrowerConfiguration configuration, Func <Exception> exceptionFactory)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.Throws(_ => exceptionFactory()));
        }
示例#3
0
        public static IAfterCallConfiguredWithOutAndRefParametersConfiguration <IReturnValueConfiguration <Task <T> > > Returns <T>(this IReturnValueConfiguration <Task <T> > configuration, T value)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.ReturnsLazily(() => value));
        }
示例#4
0
        /// <summary>
        /// Executes the specified action when a matching call is being made. This overload can also be used to fake calls with arguments when they don't need to be accessed.
        /// </summary>
        /// <typeparam name="TInterface">The type of configuration interface to return.</typeparam>
        /// <param name="configuration">The configuration that is extended.</param>
        /// <param name="actionToInvoke">The <see cref="Action" /> to invoke.</param>
        /// <returns>The fake object.</returns>
        public static TInterface Invokes <TInterface>(this ICallbackConfiguration <TInterface> configuration, Action actionToInvoke)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.Invokes(call => actionToInvoke()));
        }
示例#5
0
        public static T?IsNotNull <T>(this INegatableArgumentConstraintManager <T?> manager) where T : struct
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(x => x is object, x => x.Write("NOT NULL")));
        }
示例#6
0
        /// <summary>
        /// Configures the specified call to do nothing when called.
        /// </summary>
        /// <param name="configuration">The call configuration to extend.</param>
        /// <returns>A configuration object.</returns>
        public static IAfterCallConfiguredConfiguration <IReturnValueConfiguration <Task> > DoesNothing(this IReturnValueConfiguration <Task> configuration)
        {
            Guard.AgainstNull(configuration, nameof(configuration));

            return(configuration.Returns(TaskHelper.CompletedTask));
        }
示例#7
0
        public static T?IsNull <T>(this IArgumentConstraintManager <T?> manager) where T : struct
        {
            Guard.AgainstNull(manager, nameof(manager));

            return(manager.Matches(x => x is null, x => x.Write("NULL")));
        }
示例#8
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()));
        }
示例#9
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(descriptionFormat, args)));
        }
示例#10
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)));
        }
示例#11
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)));
        }