Пример #1
0
        private void ProcessException(Exception ex, RequestInfo request, ScriptExecuteErrorEventArgs e2)
        {
            request.Result.Exception = ex;

            WebException wex = ex as WebException;

            if (wex != null)
            {
                RemoteWebException remoteWebException = new RemoteWebException(wex);
                request.Result.Response = remoteWebException.ResponseText;
            }

            if (this.ExecuteError != null)
            {
                this.ExecuteError(this, e2);
            }
        }
Пример #2
0
 public static int GetStatusCode(this RemoteWebException ex)
 {
     return((ex.InnerException as WebException).GetStatusCode());
 }
Пример #3
0
        private async void btnRun_Click(object sender, EventArgs e)
        {
            if (btnRun.Enabled == false)
            {
                return;
            }

            btnRun.Enabled = false;

            if (CheckWebsiteIsRunning("http://www.fish-ajax-cors.com/") == false ||                     // CrosClientWebSite1
                CheckWebsiteIsRunning("http://www.fish-mvc-demo.com/") == false)                        // DemoWebSite1

            {
                btnRun.Enabled = true;
                return;
            }


            txtTestResult.Text = string.Empty;
            StringBuilder sb    = new StringBuilder();
            int           count = 0;

            foreach (ListViewItem item in this.listView1.Items)
            {
                item.ImageIndex = 0;
            }

            foreach (ListViewItem item in this.listView1.Items)
            {
                if (item.Checked)
                {
                    count++;

                    MethodInfo m = (MethodInfo)item.Tag;
                    item.ImageIndex = 1;

                    try {
                        object instance = Activator.CreateInstance(m.DeclaringType);
                        Task   task     = m.Invoke(instance, null) as Task;
                        if (task != null)
                        {
                            await task;
                        }

                        //Task.Run(() => m.Invoke(instance, null)).Wait();

                        item.ImageIndex = 2;
                    }
                    catch (Exception ex) {
                        item.ImageIndex = 3;

                        string             errorMessage    = null;
                        RemoteWebException remoteException = ex as RemoteWebException;
                        if (remoteException != null)
                        {
                            errorMessage = remoteException.Message;
                        }


                        sb.AppendLine("Method: " + m.DeclaringType.FullName + "." + m.Name)
                        .AppendLine("---------------------------------------------------")
                        .Append(errorMessage ?? ex.GetBaseException().Message)
                        .AppendLine("\r\n---------------------------------------------------\r\n\r\n");
                    }
                }
            }


            btnRun.Enabled = true;

            if (count == 0)
            {
                txtTestResult.Text = "没有需要执行的测试用例。";
            }
            else
            {
                if (sb.Length == 0)
                {
                    txtTestResult.Text = "全部测试用例已通过。";
                }
                else
                {
                    txtTestResult.Text = sb.ToString();
                }
            }
        }