/// <summary> /// Applies the constraint to an ActualValueDelegate that returns /// the value to be tested. The default implementation simply evaluates /// the delegate but derived classes may override it to provide for /// delayed processing. /// </summary> public override ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del) { #if ASYNC if (typeof(TActual) == typeof(Task)) { return(ApplyTo(new AsyncTestDelegate(() => (Task)(object)del.Invoke()))); } #endif return(ApplyTo(new TestDelegate(() => del.Invoke()))); }
private static object InvokeDelegate <T>(ActualValueDelegate <T> del) { #if ASYNC var invokeResult = del.Invoke(); object awaitedResult; return(AwaitUtils.TryAwait(del, invokeResult, out awaitedResult) ? awaitedResult : invokeResult); #else return(del.Invoke()); #endif }
public override ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del) { if (del == null) { throw new ArgumentNullException(); } return(ApplyTo(() => del.Invoke(), del)); }
private static object InvokeDelegate <T>(ActualValueDelegate <T> del) { if (AsyncToSyncAdapter.IsAsyncOperation(del)) { return(AsyncToSyncAdapter.Await(() => del.Invoke())); } return(del()); }
/// <summary> /// Applies the constraint to an ActualValueDelegate that returns /// the value to be tested. The default implementation simply evaluates /// the delegate but derived classes may override it to provide for /// delayed processing. /// </summary> /// <param name="del">An ActualValueDelegate</param> /// <returns>A ConstraintResult</returns> public virtual ConstraintResult ApplyTo <TActual>(ActualValueDelegate <TActual> del) { if (AsyncToSyncAdapter.IsAsyncOperation(del)) { return(ApplyTo(AsyncToSyncAdapter.Await(() => del.Invoke()))); } return(ApplyTo(GetTestObject(del))); }
/// <summary> /// Applies the constraint to an ActualValueDelegate that returns /// the value to be tested. The default implementation simply evaluates /// the delegate but derived classes may override it to provide for /// delayed processing. /// </summary> /// <param name="del">An ActualValueDelegate</param> /// <returns>A ConstraintResult</returns> /// <remarks> /// The value has already been validated when this method is called. /// </remarks> protected virtual ConstraintResult ApplyConstraint <T>(ActualValueDelegate <T> del) { #if NYI // async if (AsyncToSyncAdapter.IsAsyncOperation(del)) { return(ApplyConstraint(AsyncToSyncAdapter.Await(() => del.Invoke()))); } #endif return(ApplyConstraint(del())); }