Beispiel #1
0
        public static AspNetHost CreateHost(string webDirectory)
        {
            AspNetHost host = (AspNetHost)ApplicationHost.
                              CreateApplicationHost(typeof(AspNetHost), "/", webDirectory);

            return(host);
        }
Beispiel #2
0
        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;
            }
        }
Beispiel #3
0
		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();
		}
Beispiel #4
0
        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();
        }
Beispiel #5
0
		public static HttpHost CreateHost(AspNetHost aspNetHost) {
			return new HttpHost(aspNetHost);
		}
Beispiel #6
0
 public static HttpHost CreateHost(string webDirectory)
 {
     return(new HttpHost(AspNetHost.CreateHost(webDirectory)));
 }
Beispiel #7
0
 public static HttpHost CreateHost(AspNetHost aspNetHost)
 {
     return(new HttpHost(aspNetHost));
 }