2008-10-10 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 10 Oct 2008 11:34:01 +0000 (11:34 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 10 Oct 2008 11:34:01 +0000 (11:34 -0000)
* UrlRoutingModule.cs : implement PostMapRequestHandler() and
  PostResolveRequestCache() to work correctly in order.
  Now it should practically work.

* UrlRoutingModuleTest.cs , TestStubTypes.cs : added test for
  pipeline processing of requests.

svn path=/trunk/mcs/; revision=115424

mcs/class/System.Web.Routing/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs
mcs/class/System.Web.Routing/Test/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/Test/System.Web.Routing/TestStubTypes.cs
mcs/class/System.Web.Routing/Test/System.Web.Routing/UrlRoutingModuleTest.cs

index 92d0a349f764fe27aeda54444d30e3326e16268f..837fa054c0d932f091657e122e4d0f7522957000 100644 (file)
@@ -1,3 +1,9 @@
+2008-10-10  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * UrlRoutingModule.cs : implement PostMapRequestHandler() and 
+         PostResolveRequestCache() to work correctly in order.
+         Now it should practically work.
+
 2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * UrlRoutingModule.cs, RouteCollection.cs :
index 822073582c7e39b0dd37764e95697f4684fd40d0..f3c7b55319d04fa216195f22b879af3181eb51dc 100644 (file)
@@ -29,6 +29,7 @@
 //
 using System;
 using System.Security.Permissions;
+using System.Threading;
 using System.Web;
 
 namespace System.Web.Routing
@@ -38,6 +39,7 @@ namespace System.Web.Routing
        public class UrlRoutingModule : IHttpModule
        {
                RouteCollection routes;
+               object module_identity = new object ();
 
                public RouteCollection RouteCollection {
                        get {
@@ -80,10 +82,15 @@ namespace System.Web.Routing
                        PostResolveRequestCache (new HttpContextWrapper (app.Context));
                }
 
-               [MonoTODO]
                public virtual void PostMapRequestHandler (HttpContextBase context)
                {
+                       if (context == null)
+                               throw new ArgumentNullException ("context");
+
                        // FIXME: find out what it actually does.
+                       IHttpHandler h = (IHttpHandler) context.Items [module_identity];
+                       if (h != null)
+                               context.Handler = h;
                }
 
                [MonoTODO]
@@ -114,6 +121,8 @@ namespace System.Web.Routing
 
                        // default handler (forbidden in MVC/DynamicData projects)
                        context.RewritePath ("~/UrlRouting.axd");
+
+                       context.Items [module_identity] = http;
                }
        }
 }
index cd5807cf994d6908e59497074be24d816a4dbede..7604241a3b193e0fa3db1ceb9777e0d0a7ded52a 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-10  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * UrlRoutingModuleTest.cs , TestStubTypes.cs : added test for
+         pipeline processing of requests.
+
 2008-09-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * UrlRoutingModuleTest.cs, TestStubTypes.cs, RouteCollectionTest.cs:
index 591f13a0917fb2adf1268bead237591e876ecfe7..e445d2bab3bc9e36e130c71e7adddec3b7d9d7aa 100644 (file)
@@ -100,10 +100,13 @@ namespace MonoTests.System.Web.Routing
 
                public override object this [object key] {
                        get {
-                               Console.Error.WriteLine (key);
+                               //Console.Error.WriteLine ("Get: {0} {1}", key, key.GetHashCode ());
                                return base [key];
                        }
-                       set { base [key] = value; }
+                       set {
+                               //Console.Error.WriteLine ("Set: {0} {1} = {2}", key, key.GetHashCode (), value);
+                               base [key] = value; 
+                       }
                }
        }
 
@@ -124,7 +127,7 @@ namespace MonoTests.System.Web.Routing
                        request = new HttpRequestStub2 (requestUrl, path, appPath);
                }
 
-               Hashtable items = new Hashtable ();
+               Hashtable items = new MyDictionary ();
                HttpRequestStub request;
                HttpResponseBase response;
 
@@ -200,6 +203,35 @@ namespace MonoTests.System.Web.Routing
                }
        }
 
+       class HttpContextStub3 : HttpContextStub2
+       {
+               public HttpContextStub3 (string requestUrl, string path, string appPath, bool supportHandler)
+                       : base (requestUrl, path, appPath)
+               {
+                       this.support_handler = supportHandler;
+               }
+
+               public override void RewritePath (string path)
+               {
+                       RewrittenPath = path;
+               }
+
+               bool support_handler;
+               public IHttpHandler HttpHandler { get; set; }
+
+               public override IHttpHandler Handler {
+                       get { return support_handler ? HttpHandler : base.Handler; }
+                       set {
+                               if (support_handler)
+                                       HttpHandler = value;
+                               else
+                                       base.Handler = value;
+                       }
+               }
+
+               public string RewrittenPath { get; set; }
+       }
+
        public class MyStopRoutingHandler : StopRoutingHandler
        {
                public IHttpHandler CallGetHttpHandler (RequestContext rc)
@@ -257,10 +289,15 @@ namespace MonoTests.System.Web.Routing
 
                public void ProcessRequest (HttpContext ctx)
                {
-                       throw new Exception ("HOGE");
+                       throw new MyException ("HOGE");
                }
        }
 
+       public class MyException : Exception
+       {
+               public MyException (string msg) : base (msg) {}
+       }
+
        public class NullRouteHandler : IRouteHandler
        {
                public IHttpHandler GetHttpHandler (RequestContext requestContext)
index 61cdb8eba3d3f60e1a1d8382075a642775e09d9b..09dcc563e9028bdefdd590f032d765e3ca0bd41d 100644 (file)
@@ -74,23 +74,6 @@ namespace MonoTests.System.Web.Routing
                        m.PostMapRequestHandler (new HttpContextStub2 ("~/foo/bar", null));
                }
 
-               [Test]
-               [Ignore ("It fails at #1. Isn't it expected to do something?")]
-               public void PostMapRequestHandlerModifiedPath ()
-               {
-                       var m = new UrlRoutingModule ();
-                       RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
-                       var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
-                       hc.SetResponse (new HttpResponseStub (2));
-                       Assert.IsNotNull (m.RouteCollection.GetRouteData (hc), "#0");
-                       try {
-                               m.PostMapRequestHandler (hc);
-                               Assert.Fail ("#1");
-                       } catch (ApplicationException ex) {
-                               Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
-                       }
-               }
-
                // PostResolveRequestCache
 
                [Test]
@@ -122,7 +105,7 @@ namespace MonoTests.System.Web.Routing
                }
 
                [Test]
-               public void PostResolveRequestCacheErrorHttpHandler ()
+               public void PostResolveRequestCacheCallRewritePath ()
                {
                        var m = new UrlRoutingModule ();
                        RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
@@ -151,12 +134,24 @@ namespace MonoTests.System.Web.Routing
                }
 
                [Test]
-               [Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
-               public void PathToExistingFile ()
+               public void PostResolveRequestCache ()
                {
                        var m = new UrlRoutingModule ();
                        RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
-                       var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
+                       var hc = new HttpContextStub3 ("~/x/y", "z", "apppath", false);
+                       hc.SetResponse (new HttpResponseStub (2));
+                       m.PostResolveRequestCache (hc);
+                       Assert.AreEqual ("~/UrlRouting.axd", hc.RewrittenPath, "#1");
+                       // it internally stores the handler 
+               }
+
+               [Test]
+               [Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
+               public void PostResolveRequestCachePathToExistingFile ()
+               {
+                       var m = new UrlRoutingModule ();
+                       RouteTable.Routes.Add (new MyRoute ("~/{foo}/{bar}", new MyRouteHandler ()));
+                       var hc = new HttpContextStub2 ("~/hoge/fuga", String.Empty, ".");
                        // it tries to get HttpContextBase.Response, so set it.
                        hc.SetResponse (new HttpResponseStub (3));
                        try {
@@ -166,5 +161,51 @@ namespace MonoTests.System.Web.Routing
                                Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
                        }
                }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void Pipeline1 ()
+               {
+                       var m = new UrlRoutingModule ();
+                       RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
+                       var hc = new HttpContextStub3 ("~/x/y", "z", "apppath", false);
+                       hc.SetResponse (new HttpResponseStub (2));
+                       m.PostResolveRequestCache (hc);
+                       Assert.AreEqual ("~/UrlRouting.axd", hc.RewrittenPath, "#1");
+                       // It tries to set Handler and causes NIE
+                       m.PostMapRequestHandler (hc);
+               }
+
+               [Test]
+               public void Pipeline2 ()
+               {
+                       var m = new UrlRoutingModule ();
+                       RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
+                       var hc = new HttpContextStub3 ("~/x/y", "z", "apppath", true);
+                       hc.HttpHandler = new MyHttpHandler ();
+                       hc.SetResponse (new HttpResponseStub (2));
+                       m.PostResolveRequestCache (hc);
+                       Assert.AreEqual ("~/UrlRouting.axd", hc.RewrittenPath, "#1");
+                       // It tries to set Handler and causes NIE
+                       m.PostMapRequestHandler (hc);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ApplicationException))]
+               public void Pipeline3 ()
+               {
+                       var m = new UrlRoutingModule ();
+                       RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
+                       var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
+                       hc.SetResponse (new HttpResponseStub (2));
+                       Assert.IsNotNull (m.RouteCollection.GetRouteData (hc), "#0");
+                       m.PostResolveRequestCache (hc);
+                       try {
+                               m.PostMapRequestHandler (hc);
+                               Assert.Fail ("#1");
+                       } catch (ApplicationException ex) {
+                               Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
+                       }
+               }
        }
 }