/// <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)); }); }
public static ConfiguredCall ReturnsNull <T>(this ValueTask <T> value) where T : class => value.Returns(default(T));
/// <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); }
/// <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); }
/// <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))); }