public static AspNetHost CreateHost(string webDirectory) { AspNetHost host = (AspNetHost)ApplicationHost. CreateApplicationHost(typeof(AspNetHost), "/", webDirectory); return(host); }
public void AspHostBasicTest() { try { using (AspNetHost host = AspNetHost.CreateHost(TestWebDirectory)) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host.BaseUri); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); using (StreamReader sr = new StreamReader(response.GetResponseStream())) { string content = sr.ReadToEnd(); StringAssert.Contains("Test home page", content); } } } } catch (FileNotFoundException ex) { Assert.Inconclusive( "Unable to execute hosted ASP.NET tests because {0} could not be found. {1}", ex.FileName, ex.FusionLog); } catch (WebException ex) { if (ex.Response != null) { using (var responseStream = new StreamReader(ex.Response.GetResponseStream())) { Console.WriteLine(responseStream.ReadToEnd()); } } throw; } }
private HttpHost(AspNetHost aspNetHost) { this.aspNetHost = aspNetHost; this.Port = 59687; Random r = new Random(); tryAgain: try { this.listener = new HttpListener(); this.listener.Prefixes.Add(string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", this.Port)); this.listener.Start(); } catch (HttpListenerException ex) { if (ex.Message.Contains("conflicts")) { this.Port += r.Next(1, 20); goto tryAgain; } throw; } this.listenerThread = new Thread(this.ProcessRequests); this.listenerThread.Start(); }
private HttpHost(AspNetHost aspNetHost) { this.aspNetHost = aspNetHost; this.Port = 59687; Random r = new Random(); tryAgain: try { this.listener = new HttpListener(); this.listener.Prefixes.Add(string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", this.Port)); this.listener.Start(); } catch (HttpListenerException ex) { if (ex.Message.Contains("conflicts")) { this.Port += r.Next(1, 20); goto tryAgain; } throw; } this.listenerThread = new Thread(this.ProcessRequests); this.listenerThread.Start(); }
public static HttpHost CreateHost(AspNetHost aspNetHost) { return new HttpHost(aspNetHost); }
public static HttpHost CreateHost(string webDirectory) { return(new HttpHost(AspNetHost.CreateHost(webDirectory))); }
public static HttpHost CreateHost(AspNetHost aspNetHost) { return(new HttpHost(aspNetHost)); }