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; } }
public static HttpHost CreateHost(string webDirectory) { return(new HttpHost(AspNetHost.CreateHost(webDirectory))); }