コード例 #1
0
        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);
        }
コード例 #2
0
        public void BeginEndFetchTest()
        {
            var requestProvider = new MockRequestProvider {
                CreateSuspendedRequests = true
            };
            var request = new MockServiceRequest <string>(requestProvider);

            string       result = null;
            IAsyncResult async  = request.BeginFetch(cb => result = request.EndFetch(cb), null);

            // Check the result.
            Assert.IsFalse(async.AsyncWaitHandle.WaitOne(30));
            Assert.IsFalse(async.IsCompleted);
            requestProvider.LastRequest.SuspendAsyncRequest = false;
            if (!async.AsyncWaitHandle.WaitOne(5000))
            {
                Assert.Fail("Asynchronous Fetch operation seems to be stuck.");
            }
            Assert.AreEqual("FooBar", result);
        }