Example #1
0
 /// <summary>
 /// Specifies the exception to throw when the async method is invoked.
 /// </summary>
 public static void Throws <TResult>(this ValueTask <TResult> target, Exception exception)
 {
     target.Returns(() =>
     {
         var tcs = new TaskCompletionSource <TResult>();
         tcs.SetException(exception);
         return(new ValueTask <TResult>(tcs.Task));
     });
 }
Example #2
0
 public static ConfiguredCall ReturnsNull <T>(this ValueTask <T> value) where T : class =>
 value.Returns(default(T));
Example #3
0
 /// <summary>
 /// Sets the return value for a property or non-void async method to
 /// be evaluated dynamically using the given function on every
 /// call, while allowing access to all arguments of the invocation,
 /// including ref/out arguments.
 /// </summary>
 public static ValueTask <TResult> ReturnsAsync <TResult>(this ValueTask <TResult> target, Func <IArgumentCollection, TResult> value)
 {
     target.Returns(args => new ValueTask <TResult>(Task.FromResult(value(args))));
     return(target);
 }
Example #4
0
 /// <summary>
 /// Sets the return value for a property or non-void async method.
 /// </summary>
 public static ValueTask <TResult> ReturnsAsync <TResult>(this ValueTask <TResult> target, Func <TResult> value)
 {
     target.Returns(() => new ValueTask <TResult>(Task.FromResult(value())));
     return(target);
 }
Example #5
0
 /// <summary>
 /// Set null as returned value for this call.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="value"></param>
 /// <returns></returns>
 public static ConfiguredCall ReturnsNull <T>(this ValueTask <T> value) where T : class
 {
     return(value.Returns(i => SubstituteExtensions.CompletedValueTask <T>(null)));
 }