public void BeginEndFetchInternalTest() { var requestProvider = new MockRequestProvider { CreateSuspendedRequests = true }; var request = new MockServiceRequest <string>(requestProvider); // Request validation is done in the MockSchemaAwareRequestExecutor. string result = null; IAsyncResult async = request.BeginFetchInternal( cb => result = request.EndFetch(cb), null, res => request.FetchObject(res.GetResponse())); // Test that the operation is not yet completed. Assert.IsFalse(async.IsCompleted); Assert.IsFalse(async.CompletedSynchronously); Assert.IsNotNull(async.AsyncWaitHandle); Assert.IsNull(async.AsyncState); // Let the async operation continue. requestProvider.LastRequest.SuspendAsyncRequest = false; if (!async.AsyncWaitHandle.WaitOne(5000)) { Assert.Fail("Async Operation seems to be stuck."); } // Check the result. Assert.IsTrue(async.IsCompleted); Assert.AreEqual("FooBar", result); Assert.IsFalse(async.CompletedSynchronously); }