RouteCollection.RouteExistingFiles support.
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 18 Sep 2008 18:35:32 +0000 (18:35 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 18 Sep 2008 18:35:32 +0000 (18:35 -0000)
svn path=/trunk/mcs/; revision=113452

mcs/class/System.Web.Routing/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/System.Web.Routing/RouteCollection.cs
mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs
mcs/class/System.Web.Routing/Test/ChangeLog [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteCollectionTest.cs
mcs/class/System.Web.Routing/Test/System.Web.Routing/TestStubTypes.cs
mcs/class/System.Web.Routing/Test/System.Web.Routing/UrlRoutingModuleTest.cs
mcs/class/System.Web.Routing/Test/test.html [new file with mode: 0644]

index 872266325fb41250e0fd74f0dddff7cc695039bd..92d0a349f764fe27aeda54444d30e3326e16268f 100644 (file)
@@ -1,3 +1,8 @@
+2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * UrlRoutingModule.cs, RouteCollection.cs :
+         handle RouteExistingFiles.
+
 2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * Route.cs : reject invalid constraint.
index 96ec363550fc20df74b81fe0d757966b4aa6a01c..f4455c2d7218fa4946341d3b3f0bba9c39b79584 100644 (file)
@@ -31,6 +31,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.IO;
 using System.Security.Permissions;
 using System.Web;
 using System.Web.Hosting;
@@ -89,7 +90,6 @@ namespace System.Web.Routing
                        }
                }
 
-               [MonoTODO]
                public bool RouteExistingFiles { get; set; }
 
                public void Add (string name, RouteBase item)
@@ -112,14 +112,18 @@ namespace System.Web.Routing
                        return read_lock;
                }
 
-               [MonoTODO]
                public RouteData GetRouteData (HttpContextBase httpContext)
                {
                        if (httpContext == null)
                                throw new ArgumentNullException ("httpContext");
 
-                       var path = httpContext.Request.AppRelativeCurrentExecutionFilePath;
-                       // FIXME: do some check wrt the property above.
+                       if (!RouteExistingFiles) {
+                               var path = httpContext.Request.AppRelativeCurrentExecutionFilePath;
+                               if (path.StartsWith ("~/", StringComparison.Ordinal))
+                                       path = path.Substring (2);
+                               if (File.Exists (path))
+                                       return null;
+                       }
 
                        if (Count == 0)
                                return null;
@@ -133,13 +137,11 @@ namespace System.Web.Routing
                        return null;
                }
 
-               [MonoTODO]
                public VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
                {
                        return GetVirtualPath (requestContext, null, values);
                }
 
-               [MonoTODO]
                public VirtualPathData GetVirtualPath (RequestContext requestContext, string name, RouteValueDictionary values)
                {
                        if (requestContext == null)
index e4e99413c47746bc39d9c71cb2fb27ca999748bd..822073582c7e39b0dd37764e95697f4684fd40d0 100644 (file)
@@ -62,7 +62,6 @@ namespace System.Web.Routing
                        Init (application);
                }
 
-               [MonoTODO ("FIXME: add correct arguments")]
                protected virtual void Init (HttpApplication application)
                {
                        application.PostMapRequestHandler += PostMapRequestHandler;
diff --git a/mcs/class/System.Web.Routing/Test/ChangeLog b/mcs/class/System.Web.Routing/Test/ChangeLog
new file mode 100644 (file)
index 0000000..af2aeda
--- /dev/null
@@ -0,0 +1,3 @@
+2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * test.html : dummy file.
index 8f635fce5c2fb598e92c5f996513f486e4412738..cd5807cf994d6908e59497074be24d816a4dbede 100644 (file)
@@ -1,3 +1,8 @@
+2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * UrlRoutingModuleTest.cs, TestStubTypes.cs, RouteCollectionTest.cs:
+         some tests for RouteExistingFiles.
+
 2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * RouteTest.cs : test ProcessConstraint().
index 49bc0d4fd2002b1855db0d1252a412c4425a6d0d..b14de5585e851fa74d6a9a852bf013f6afad9349 100644 (file)
@@ -117,6 +117,19 @@ namespace MonoTests.System.Web.Routing
                        Assert.IsNull (rd);
                }
 
+               [Test]
+               public void GetRouteDataForNonExistent2 ()
+               {
+                       var rd = new RouteCollection () { RouteExistingFiles = true }.GetRouteData (new HttpContextStub2 (null, null, null));
+                       Assert.IsNull (rd);
+                       try {
+                               new RouteCollection ().GetRouteData (new HttpContextStub2 (null, null, null));
+                               Assert.Fail ("#1");
+                       } catch (NotImplementedException) {
+                               // it should fail due to the NIE on AppRelativeCurrentExecutionFilePath.
+                       }
+               }
+
                [Test]
                public void GetRouteDataWrongPathNoRoute ()
                {
@@ -227,5 +240,20 @@ namespace MonoTests.System.Web.Routing
                        Assert.AreEqual ("apppath/x/y_modified", vpd.VirtualPath, "#1");
                        Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
                }
+
+               [Test]
+               [Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
+               public void GetVirtualPathToExistingFile ()
+               {
+                       var c = new RouteCollection ();
+                       c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
+                       var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
+                       // it tries to get HttpContextBase.Response, so set it.
+                       hc.SetResponse (new HttpResponseStub (3));
+                       var rd = c.GetRouteData (hc);
+                       var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
+                       Assert.AreEqual ("./Test/test.html", vpd.VirtualPath, "#1");
+                       Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
+               }
        }
 }
index 177791a0fe44c58df7250e1d7b52bacecf669d9a..591f13a0917fb2adf1268bead237591e876ecfe7 100644 (file)
@@ -188,6 +188,8 @@ namespace MonoTests.System.Web.Routing
                public override string ApplyAppPathModifier (string virtualPath)
                {
                        switch (impl_type) {
+                       case 3:
+                               return virtualPath; // pass thru
                        case 2:
                                return virtualPath + "_modified";
                        case 1:
index 003178be99c6792d9adf773a11e3faa102ea0b5b..61cdb8eba3d3f60e1a1d8382075a642775e09d9b 100644 (file)
@@ -149,5 +149,22 @@ namespace MonoTests.System.Web.Routing
                                Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
                        }
                }
+
+               [Test]
+               [Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
+               public void PathToExistingFile ()
+               {
+                       var m = new UrlRoutingModule ();
+                       RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
+                       var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
+                       // it tries to get HttpContextBase.Response, so set it.
+                       hc.SetResponse (new HttpResponseStub (3));
+                       try {
+                               m.PostResolveRequestCache (hc);
+                               Assert.Fail ("#1");
+                       } catch (ApplicationException ex) {
+                               Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
+                       }
+               }
        }
 }
diff --git a/mcs/class/System.Web.Routing/Test/test.html b/mcs/class/System.Web.Routing/Test/test.html
new file mode 100644 (file)
index 0000000..f39108b
--- /dev/null
@@ -0,0 +1,5 @@
+<html>
+<body>
+<p>TEST</p>
+</body>
+</html>