Пример #1
0
		public Response Run (string url, string pathInfo, string[] postValues, string[] formValues)
#endif
		{
			if (String.IsNullOrEmpty (url))
				throw new ArgumentNullException ("url");
			
			bool isPost = postValues != null;
			
			ResetState ();
			
			if (String.IsNullOrEmpty (url))
				throw new ArgumentNullException ("url");
			
			var output = new StringWriter ();
			try {
				string fullUrl = "http://localhost";
				if (url [0] == '/')
					fullUrl += url;
				else
					fullUrl += "/" + url;
				
				Uri uri = new Uri (fullUrl, UriKind.RelativeOrAbsolute);
				string query = uri.Query;
				if (!String.IsNullOrEmpty (query) && query [0] == '?')
					query = query.Substring (1);
				
				TestWorkerRequest wr;
				
				if (pathInfo != null)
					wr = new TestWorkerRequest (uri.AbsolutePath, query, pathInfo, output);
				else
					wr = new TestWorkerRequest (uri.AbsolutePath, query, output);
				wr.IsPost = isPost;
				if (isPost) {
					wr.AppendPostData (formValues, true);
					wr.AppendPostData (postValues, false);
				}
				
				HttpRuntime.ProcessRequest (wr);
				StatusCode = (int) wr.StatusCode;
				Redirected = wr.Redirected;
				RedirectLocation = wr.RedirectLocation;
				
				return new Response {
					Body = output.ToString (),
					StatusCode = wr.StatusCode,
					StatusDescription = wr.StatusDescription
				};
			} finally {
				output.Close ();
			}
		}
Пример #2
0
        public Response Run(string url, string pathInfo, string[] postValues, string[] formValues)
#endif
        {
            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }

            bool isPost = postValues != null;

            ResetState();

            if (String.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }

            var output = new StringWriter();

            try {
                string fullUrl = "http://localhost";
                if (url [0] == '/')
                {
                    fullUrl += url;
                }
                else
                {
                    fullUrl += "/" + url;
                }

                Uri    uri   = new Uri(fullUrl, UriKind.RelativeOrAbsolute);
                string query = uri.Query;
                if (!String.IsNullOrEmpty(query) && query [0] == '?')
                {
                    query = query.Substring(1);
                }

                TestWorkerRequest wr;

                if (pathInfo != null)
                {
                    wr = new TestWorkerRequest(uri.AbsolutePath, query, pathInfo, output);
                }
                else
                {
                    wr = new TestWorkerRequest(uri.AbsolutePath, query, output);
                }
                wr.IsPost = isPost;
                if (isPost)
                {
                    wr.AppendPostData(formValues, true);
                    wr.AppendPostData(postValues, false);
                }

                HttpRuntime.ProcessRequest(wr);
                StatusCode       = (int)wr.StatusCode;
                Redirected       = wr.Redirected;
                RedirectLocation = wr.RedirectLocation;

                return(new Response {
                    Body = output.ToString(),
                    StatusCode = wr.StatusCode,
                    StatusDescription = wr.StatusDescription
                });
            } finally {
                output.Close();
            }
        }