public void RootDirectoryRequestTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port)) { s.Start(); string data = GetPage(string.Format("http://localhost:{0}/", _port)); Assert.AreEqual(false, string.IsNullOrEmpty(data)); s.Stop(); } }
public void SimpleWSCallTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port)) { s.Start(); using (WebService ws = new WebService()) { ws.Url = string.Format("http://localhost:{0}/WebService.asmx", _port); string response = ws.HelloWorld(); Assert.AreEqual("Hello World", response); } s.Stop(); } }
public void PrimitiveTypeWSCallTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port)) { s.Start(); using (WebService ws = new WebService()) { ws.Url = string.Format("http://localhost:{0}/WebService.asmx", _port); int result = ws.DoAdd(4, 7); Assert.AreEqual(11, result); } s.Stop(); } }
public void SimplePostTest_aspxRenderTest() { Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port); s.Start(); try { string data = GetPage("http://localhost:" + _port + "/SimplePostTest.aspx"); Console.WriteLine(data); Assert.AreEqual(true, data.Contains(_doPostbackJS)); } finally { s.Stop(); } }
public void Default_aspxRenderTest() { Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port); s.Start(); try { string data = GetPage("http://localhost:" + _port + "/default.aspx"); Console.WriteLine("received HTML:"); Console.WriteLine(data); Assert.AreEqual(true, data.Contains(_defaultASPX)); } finally { s.Stop(); } }
/* NOTE: * This is only intended to be an example of a web server. * It is not intended to be a serious implementation, and as * such is lacking user input validation. */ static void Main(string[] args) { Console.WriteLine("aspNETserve console server"); Console.Write("IP: "); string rawIp; if (args.Length < 1) { rawIp = Console.ReadLine(); }else { rawIp = args[0]; Console.WriteLine(rawIp); } Console.Write("Port: "); string port; if (args.Length < 2) { port = Console.ReadLine(); }else { port = args[1]; Console.WriteLine(port); } Console.Write("Physical Path: "); string physicalPath; if (args.Length < 3) { physicalPath = Console.ReadLine(); }else { physicalPath = args[2]; Console.WriteLine(physicalPath); } Console.Write("Virtual Path: "); string virtualPath; if (args.Length < 4) { virtualPath = Console.ReadLine(); }else { virtualPath = args[3]; Console.WriteLine(virtualPath); } Console.WriteLine(); Console.Write("Starting..."); System.Net.IPAddress endPoint = System.Net.IPAddress.Parse(rawIp); using (Server s = new Server(endPoint, virtualPath, physicalPath, int.Parse(port))) { s.Start(); Console.WriteLine("DONE"); Console.Write("Press any key to stop"); Console.Read(); } }
public void SimpleGETTest() { Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port); s.Start(); WebClient helper = new WebClient(); string data; try { data = helper.DownloadString("http://localhost:" + _port + "/default.aspx"); } catch { s.Stop(); throw; } Assert.AreEqual(false, string.IsNullOrEmpty(data)); s.Stop(); }
public void ResponseRedirectTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port)) { s.Start(); string expectedPage = GetPage("http://localhost:" + _port + "/RedirectHome.aspx"); Assert.AreNotEqual(null, expectedPage); HttpWebResponse response = GetPageResponse("http://localhost:" + _port + "/RedirectHome.aspx") as HttpWebResponse; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Stream stream = response.GetResponseStream(); byte[] buffer = new byte[response.ContentLength]; stream.Read(buffer, 0, (int)response.ContentLength); string actualPage = Encoding.UTF8.GetString(buffer); Assert.AreEqual(expectedPage, actualPage); s.Stop(); } }
/* NOTE: * This is only intended to be an example of a web server. * It is not intended to be a serious implementation, and as * such is lacking user input validation. */ static void Main(string[] args) { Console.WriteLine("aspNETserve console server"); Console.Write("IP: "); string rawIp = Console.ReadLine(); Console.Write("Port: "); string port = Console.ReadLine(); Console.Write("Physical Path: "); string physicalPath = Console.ReadLine(); Console.Write("Virtual Path: "); string virtualPath = Console.ReadLine(); Console.WriteLine(); Console.Write("Starting..."); System.Net.IPAddress endPoint = System.Net.IPAddress.Parse(rawIp); using (Server s = new Server(endPoint, virtualPath, physicalPath, int.Parse(port))) { s.Start(); Console.WriteLine("DONE"); Console.Write("Press any key to stop"); Console.Read(); } }
protected string GetServerVariable(string variable, string virtualDir) { Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), virtualDir, PhysicalPath, _port); s.Start(); string data = ""; string url; if (virtualDir == "/") url = "http://localhost:" + _port + "/GetServerVariable.aspx?var=" + variable; else url = "http://localhost:" + _port + virtualDir + "/GetServerVariable.aspx?var=" + variable; try { data = GetPage(url); } finally { s.Stop(); } return data; }
public void SimplePostTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port)) { s.Start(); string url = string.Format("http://localhost:{0}/PostTest.aspx", _port); string guid = Guid.NewGuid().ToString(); NameValueCollection values = new NameValueCollection(); values.Add("txtName", guid); string page = PostValues(url, values); Console.WriteLine(guid); Console.WriteLine(page); Assert.AreEqual(true, page.Contains(guid)); s.Stop(); } }
public void CycleTest() { Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port); s.Start(); s.Stop(); }
public void VirtualDirectorySubDirectoryRequestTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/vDir", PhysicalPath, _port)) { s.Start(); string page = GetPage(string.Format("http://localhost:{0}/vDir/SubFolder/", _port)); Assert.AreEqual(true, page.Contains("Hello World")); s.Stop(); } }
public void PathInfoTest() { using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", PhysicalPath, _port)) { s.Start(); string url = string.Format("http://localhost:{0}/Tail.aspx", _port); Console.WriteLine("Getting: " + url); string page = GetPage(url); Console.WriteLine(page); Assert.AreEqual(true, page.Contains("<span id=\"lblTail\"></span>")); url = string.Format("http://localhost:{0}/Tail.aspx/foo", _port); Console.WriteLine("Getting: " + url); page = GetPage(url); Console.WriteLine(page); Assert.AreEqual(true, page.Contains("<span id=\"lblTail\">/foo</span>")); s.Stop(); } }