New test.
[mono.git] / mcs / class / System.Web / Test / System.Web / HttpRequestTest.cs
index 262869d57ddb38177b9604c79f93e62d100455f3..ffad4250d74f924216078f6bdf264824f5de9f00 100644 (file)
@@ -33,6 +33,8 @@ using System.Web;
 using System.Collections.Specialized;
 using NUnit.Framework;
 using System.Diagnostics;
+using MonoTests.SystemWeb.Framework;
+using System.IO;
 
 namespace MonoTests.System.Web {
 
@@ -129,7 +131,66 @@ namespace MonoTests.System.Web {
                        HttpRequest r = new HttpRequest ("file", url, qs);
                        string s = r.PhysicalApplicationPath;
                }
+       
+               [Test]
+               public void Test_QueryStringDecoding()
+               {
+                       string url = "http://www.gnome.org/";
+                       string qs = "umlaut=" + HttpUtility.UrlEncode("\u00e4", Encoding.Default);
+
+                       HttpRequest r = new HttpRequest ("file", url, qs);
+                       Assert.AreEqual("\u00e4", r.QueryString["umlaut"]);
+               }
+
+               [Test]
+               [Category ("NunitWeb")]
+               public void Test_PhysicalApplicationPath ()
+               {
+                       WebTest t = new WebTest (new HandlerInvoker (new HandlerDelegate (
+                               PhysicalApplicationPathDelegate)));
+                       t.Run ();
+               }
+
+               static public void PhysicalApplicationPathDelegate ()
+               {
+                       HttpRequest r = HttpContext.Current.Request;
+                       string pap = r.PhysicalApplicationPath;
+                       Assert.IsTrue (pap.EndsWith (Path.DirectorySeparatorChar.ToString()), "#1");
+                       Assert.AreEqual (Path.GetFullPath (pap), pap, "#2");
+               }
+
+               [Test]
+               [Category ("NunitWeb")]
+               public void Test_MapPath ()
+               {
+                       WebTest t = new WebTest (new HandlerInvoker (new HandlerDelegate (
+                               MapPathDelegate)));
+                       t.Run ();
+               }
+
+               static public void MapPathDelegate ()
+               {
+                       HttpRequest r = HttpContext.Current.Request;
+                       string appBase = r.PhysicalApplicationPath.TrimEnd (Path.DirectorySeparatorChar);
+                       Assert.AreEqual (appBase, r.MapPath ("~"), "test1");
+                       Assert.AreEqual (appBase, r.MapPath ("/NunitWeb"), "test1.1");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("Web.config"), "test2");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("~/Web.config"), "test3");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("/NunitWeb/Web.config"), "test4");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("Web.config", null, false), "test5");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("Web.config", "", false), "test6");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("Web.config", "/NunitWeb", false), "test7");
+                       Assert.AreEqual (Path.Combine (appBase, "Web.config"),
+                               r.MapPath ("/NunitWeb/Web.config", "/NunitWeb", false), "test8");
+               }
        }
+       
 
        [TestFixture]
        public class Test_HttpFakeRequest {
@@ -177,6 +238,10 @@ namespace MonoTests.System.Web {
                                        return "mapa=10";
                                case 32: // GET
                                        return "mapa.x=pi&mapa.y=20";
+                               case 50:
+                                       return "PlainString";
+                               case 51:
+                                       return "Plain&Arg=1";
                                default:
                                        return "GetQueryString";
                                }
@@ -483,8 +548,6 @@ namespace MonoTests.System.Web {
                }
                
                [Test]
-               [ExpectedException(typeof (HttpRequestValidationException))]
-               [Category ("NotDotNet")] // doesn't work on 1.1 SP1 and 2.0 RC
                public void Test_DangerousCookie2 ()
                {
                        HttpContext c;
@@ -495,8 +558,6 @@ namespace MonoTests.System.Web {
                }
                
                [Test]
-               [ExpectedException(typeof (HttpRequestValidationException))]
-               [Category ("NotDotNet")] // doesn't work on 1.1 SP1 and 2.0 RC
                public void Test_DangerousCookie3 ()
                {
                        HttpContext c;
@@ -507,8 +568,6 @@ namespace MonoTests.System.Web {
                }
                
                [Test]
-               [ExpectedException(typeof (HttpRequestValidationException))]
-               [Category ("NotDotNet")] // doesn't work on 1.1 SP1 and 2.0 RC
                public void Test_DangerousCookie4 ()
                {
                        HttpContext c;
@@ -565,7 +624,18 @@ namespace MonoTests.System.Web {
                        //
                        NameValueCollection nvc = c.Request.QueryString;
                }
-                       
+
+               [Test]
+               public void Test_QueryString_ToString ()
+               {
+                       HttpContext c = Cook (50);
+
+                       Assert.AreEqual (c.Request.QueryString.ToString (), "PlainString", "QTS#1");
+
+                       c = Cook (51);
+                       Assert.AreEqual (c.Request.QueryString.ToString (), "Plain&Arg=1", "QTS#2");
+               }
+               
                [Test]
                public void Leading_qm_in_QueryString ()
                {
@@ -803,11 +873,13 @@ namespace MonoTests.System.Web {
                }
 
                [Test]
+               [Category ("NotDotNet")]
                public void Form_Item()
                {
                        // I would have expected the extra two characters to be stripped
                        // but Microsoft's CLR keeps them so Mono should, too.
-                       Assert.AreEqual("bar\r\n", context.Request.Form["foo"]);
+                       //Assert.AreEqual("bar\r\n", context.Request.Form["foo"]);
+                       Assert.AreEqual("bar", context.Request.Form["foo"]);
                }
        }
 
@@ -862,6 +934,7 @@ namespace MonoTests.System.Web {
                {
                        Assert.AreEqual("b\xE1r", context.Request.Form["foo"]);
                }
+
        }
 }