public static IAfterCallSpecifiedConfiguration Throws <T>(this IExceptionThrowerConfiguration configuration) where T : Exception, new() { Guard.AgainstNull(configuration, nameof(configuration)); return(configuration.Throws(_ => new T())); }
/// <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())); }
public static IAfterCallConfiguredWithOutAndRefParametersConfiguration <IReturnValueConfiguration <Task <T> > > Returns <T>(this IReturnValueConfiguration <Task <T> > configuration, T value) { Guard.AgainstNull(configuration, nameof(configuration)); return(configuration.ReturnsLazily(() => value)); }
/// <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())); }
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"))); }
/// <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)); }
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"))); }
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())); }
/// <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))); }
/// <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> /// 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))); }