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;
+ }
}
}
request = new HttpRequestStub2 (requestUrl, path, appPath);
}
- Hashtable items = new Hashtable ();
+ Hashtable items = new MyDictionary ();
HttpRequestStub request;
HttpResponseBase response;
}
}
+ 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)
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)
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]
}
[Test]
- public void PostResolveRequestCacheErrorHttpHandler ()
+ public void PostResolveRequestCacheCallRewritePath ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
}
[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 {
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");
+ }
+ }
}
}