예제 #1
0
        void IAsyncProfileTestFixture.Begin(IAsyncTestResult result, MethodInfo beginMethod, MethodInfo endMethod)
        {
            // Store the end method and invoke the begin right now.

            _endMethod = endMethod;
            beginMethod.Invoke(this, null);

            // Everything should now be set up.

            BeginSend(result);
        }
예제 #2
0
        private void End(IAsyncTestResult result, bool completedSynchronously)
        {
            try
            {
                // Give the test case a chance to check the response.

                _endMethod.Invoke(this, null);

                // Mark it as complete.

                result.SetComplete(completedSynchronously);
            }
            catch (Exception ex)
            {
                result.SetComplete(ex, completedSynchronously);
            }
        }
예제 #3
0
        private void BeginSend(IAsyncTestResult result)
        {
            Prepare();

            // Create the request.

            var request = _isGet ? CreateGetRequest() : CreatePostRequest();

            // Set up RequestState.

            var state = new RequestState {
                Request = request, Result = result
            };

            // Send it.

            var timer = GetTimer();

            timer.Start();
            var innerResult = _client.BeginSend(request, ResponseCallback, state);

            // Check whether it has already been done.

            if (innerResult.CompletedSynchronously)
            {
                timer.Stop();
                var response = (HttpWebResponse)request.GetResponse();
                var content  = _client.ReadResponse(response, response.GetResponseStream());

                // End it.

                Process(content);
                End(result, true);
            }
            else
            {
                // Register timeout callback.

                ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, ResponseTimeoutCallback, state, 60000, true);
            }
        }