public static void EnqueueConditional(this EndToEndTestBase test, Func <bool> predicate)
 {
     while (!predicate())
     {
         Sleep(DeltaMilliseconds);
     }
 }
 /// <summary>
 /// Suspends the current thread until the asynchronous operation completes.
 /// </summary>
 /// <param name="test">The caller test</param>
 public static void WaitForTestToComplete(this EndToEndTestBase test)
 {
     while (!test.TestCompleted)
     {
         Sleep(DeltaMilliseconds);
     }
 }
 /// <summary>
 /// Blocks the current thread until the current async result is completed.
 /// </summary>
 /// <param name="asyncResult">The async result to wait for completions</param>
 /// <param name="test">The current test</param>
 /// <returns></returns>
 public static IAsyncResult EnqueueWait(this IAsyncResult asyncResult, EndToEndTestBase test)
 {
     test.EnqueueConditional(() => asyncResult.IsCompleted);
     return asyncResult;
 }
 /// <summary>
 /// Blocks the current thread until the current async result is completed.
 /// </summary>
 /// <param name="asyncResult">The async result to wait for completions</param>
 /// <param name="test">The current test.</param>
 /// <returns></returns>
 public static IAsyncResult EnqueueWait(this IAsyncResult asyncResult, EndToEndTestBase test)
 {
     // "test" parameter is never used, but is needed to maintain the same interface across platforms
     asyncResult.AsyncWaitHandle.WaitOne();
     return(asyncResult);
 }
 public static void EnqueueCallback(this EndToEndTestBase test, Action action)
 {
     action();
 }
 /// <summary>
 /// Mark the test as completed. Test should wait before exiting until this method is called.
 /// </summary>
 /// <param name="test">The asynchronous end-to-end test</param>
 public static void EnqueueTestComplete(this EndToEndTestBase test)
 {
     //If someday all the test cases are changed to the way that Linq_OrderByDescendingThenByDescendingTest is written, then this method should do nothing, just to be able to write test cases in the same way on all 4 platforms.This method is specific to SL.
     test.TestCompleted = true;
 }
 /// <summary>
 /// Blocks the current thread until the current async result is completed.
 /// </summary>
 /// <param name="asyncResult">The async result to wait for completions</param>
 /// <param name="test">The current test.</param>
 /// <returns></returns>
 public static IAsyncResult EnqueueWait(this IAsyncResult asyncResult, EndToEndTestBase test)
 {
     // "test" parameter is never used, but is needed to maintain the same interface across platforms
     asyncResult.AsyncWaitHandle.WaitOne();
     return asyncResult;
 }