/// <summary> /// Extracts the response from the completed <see cref="System.Web.HttpWorkerRequest"/> /// and returns a new <see cref="Response"/> instance. This method works with HttpWorkerRequest /// created with <see cref="CreateWorkerRequest"/>. /// </summary> /// <param name="request">this must be the same request that was returned by /// CreateWorkerRequest</param> /// <returns>New <see cref="Response"/> instance, containing the results of the /// request.</returns> /// <seealso cref="System.Web.HttpWorkerRequest"/> /// <seealso cref="Response"/> public virtual Response ExtractResponse(HttpWorkerRequest request) { BaseWorkerRequest br = (BaseWorkerRequest)request; IForeignData d = (IForeignData)br; TextWriter wr = (TextWriter)d[GetType()]; d[GetType()] = null; wr.Close(); Response r = new Response(); r.Body = wr.ToString(); r.StatusCode = br.StatusCode; r.StatusDescription = br.StatusDescription; return(r); }
private static MyData GetMyData(HttpWorkerRequest wr) { IForeignData fd = wr as IForeignData; if (fd == null) { throw new ArgumentException("Invalid worker request. Probable reason is using WebTest.Invoke from a real web application"); } MyData d = (MyData)fd[typeof(MyHost)]; if (d == null) { d = new MyData(); fd[typeof(MyHost)] = d; } return(d); }