Exemplo n.º 1
0
		//
		// This tests the constructor when the user code creates an HttpContext
		//
		[Test] public void ConstructorTests ()
		{
			StringWriter sw = new StringWriter ();
			
			SimpleWorkerRequest swr;

			swr = new SimpleWorkerRequest ("/appVirtualDir", cwd, "pageVirtualPath", "querystring", sw);
			Assert.AreEqual ("/appVirtualDir", swr.GetAppPath (), "S1");
			Assert.AreEqual ("/appVirtualDir/pageVirtualPath", swr.GetFilePath (), "S2");
			Assert.AreEqual ("GET", swr.GetHttpVerbName (), "S3");
			Assert.AreEqual ("HTTP/1.0", swr.GetHttpVersion (), "S4");
			Assert.AreEqual ("127.0.0.1", swr.GetLocalAddress (), "S5");
			Assert.AreEqual (80, swr.GetLocalPort (), "S6");
			Assert.AreEqual ("querystring", swr.GetQueryString (), "S7");
			Assert.AreEqual ("127.0.0.1", swr.GetRemoteAddress (), "S8");
			Assert.AreEqual (0, swr.GetRemotePort (), "S9");
			Assert.AreEqual ("/appVirtualDir/pageVirtualPath?querystring", swr.GetRawUrl (), "S10");
			Assert.AreEqual ("/appVirtualDir/pageVirtualPath", swr.GetUriPath (), "S11");
			Assert.AreEqual ("0", swr.GetUserToken ().ToString (), "S12");
			Assert.AreEqual (null, swr.MapPath ("x"), "S13");
			Assert.AreEqual (null, swr.MachineConfigPath, "S14");
			Assert.AreEqual (null, swr.MachineInstallDirectory, "S15");
			Assert.AreEqual (Path.Combine (cwd, "pageVirtualPath"), swr.GetFilePathTranslated (), "S16");
			Assert.AreEqual ("", swr.GetServerVariable ("AUTH_TYPE"), "S18");
			Assert.AreEqual ("", swr.GetServerVariable ("AUTH_USER"), "S19");
			Assert.AreEqual ("", swr.GetServerVariable ("REMOTE_USER"), "S20");
			Assert.AreEqual ("", swr.GetServerVariable ("SERVER_SOFTWARE"), "S21");
			Assert.AreEqual ("/appVirtualDir/pageVirtualPath", swr.GetUriPath (), "S22");

			//
			// MapPath
			//
			Assert.AreEqual (null, swr.MapPath ("file.aspx"), "MP1");
			Assert.AreEqual (null, swr.MapPath ("/appVirtualDir/pageVirtualPath"), "MP2");
			Assert.AreEqual (null, swr.MapPath ("appVirtualDir/pageVirtualPath"), "MP3");
			Assert.AreEqual (null, swr.MapPath ("/appVirtualDir/pageVirtualPath/page.aspx"), "MP4");
			Assert.AreEqual (null, swr.MapPath ("/appVirtualDir/pageVirtualPath/Subdir"), "MP5");

			swr = new SimpleWorkerRequest ("/appDir", cwd, "/Something/page.aspx", "querystring", sw);

			//Assert.AreEqual ("c:\\tmp\\page.aspx", swr.GetFilePathTranslated (), "S17");

			//
			// GetUriPath tests, veredict: MS implementation is a bit fragile on this interface
			//
			swr = new SimpleWorkerRequest ("/appDir", cwd, "/page.aspx", null, sw);
			Assert.AreEqual ("/appDir//page.aspx", swr.GetUriPath (), "S23");

			swr = new SimpleWorkerRequest ("/appDir/", cwd, "/page.aspx", null, sw);
			Assert.AreEqual ("/appDir///page.aspx", swr.GetUriPath (), "S24");

			swr = new SimpleWorkerRequest ("/appDir/", cwd, "page.aspx", null, sw);
			Assert.AreEqual ("/appDir//page.aspx", swr.GetUriPath (), "S25");

			swr = new SimpleWorkerRequest ("/appDir", cwd, "page.aspx", null, sw);
			Assert.AreEqual ("/appDir/page.aspx", swr.GetUriPath (), "S26");
			
		}
Exemplo n.º 2
0
			public void Demo ()
			{
				StringWriter sw = new StringWriter ();
				SimpleWorkerRequest swr = new SimpleWorkerRequest("file.aspx", "querystring", sw);

				Assert.AreEqual ("/appVirtualDir", swr.GetAppPath (), "T1");
				Assert.AreEqual (cwd + Path.DirectorySeparatorChar, swr.GetAppPathTranslated (), "TRANS1");
				Assert.AreEqual ("/appVirtualDir/file.aspx", swr.GetFilePath (), "T2");
				Assert.AreEqual ("GET", swr.GetHttpVerbName (), "T3");
				Assert.AreEqual ("HTTP/1.0", swr.GetHttpVersion (), "T4");
				Assert.AreEqual ("127.0.0.1", swr.GetLocalAddress (), "T5");
				Assert.AreEqual (80, swr.GetLocalPort (), "T6");
				Assert.AreEqual ("querystring", swr.GetQueryString (), "T7");
				Assert.AreEqual ("127.0.0.1", swr.GetRemoteAddress (), "T8");
				Assert.AreEqual (0, swr.GetRemotePort (), "T9");
				Assert.AreEqual ("/appVirtualDir/file.aspx?querystring", swr.GetRawUrl (), "T10");
				Assert.AreEqual ("/appVirtualDir/file.aspx", swr.GetUriPath (), "T11");
				Assert.AreEqual ("0", swr.GetUserToken ().ToString (), "T12");
				Assert.AreEqual ("", swr.GetPathInfo (), "TRANS2");

				//
				// On windows:
				// \windows\microsoft.net\framework\v1.1.4322\Config\machine.config
				//
				Assert.AreEqual (true, swr.MachineConfigPath != null, "T14");
				//
				// On windows:
				// \windows\microsoft.net\framework\v1.1.4322
				//
				Assert.AreEqual (true, swr.MachineInstallDirectory != null, "T15");

				// Disabled T16. It throws a nullref on MS
				//      Assert.AreEqual (Path.Combine (cwd, "file.aspx"), swr.GetFilePathTranslated (), "T16");
				//
				Assert.AreEqual ("", swr.GetServerVariable ("AUTH_TYPE"), "T18");
				Assert.AreEqual ("", swr.GetServerVariable ("AUTH_USER"), "T19");
				Assert.AreEqual ("", swr.GetServerVariable ("REMOTE_USER"), "T20");
				Assert.AreEqual ("", swr.GetServerVariable ("TERVER_SOFTWARE"), "T21");
				Assert.AreEqual ("/appVirtualDir/file.aspx", swr.GetUriPath (), "T22");

				//
				// MapPath
				//
				Assert.AreEqual (Path.Combine (cwd, "file.aspx"), swr.MapPath ("/appVirtualDir/file.aspx"), "TP2");
				Assert.AreEqual (Path.Combine (cwd, "file.aspx"), swr.MapPath ("/appVirtualDir/file.aspx"), "TP4");
				Assert.AreEqual (Path.Combine (cwd, Path.Combine ("Subdir", "file.aspx")), swr.MapPath ("/appVirtualDir/Subdir/file.aspx"), "TP5");

			}