+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.
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;
}
}
- [MonoTODO]
public bool RouteExistingFiles { get; set; }
public void Add (string name, RouteBase item)
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;
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)
Init (application);
}
- [MonoTODO ("FIXME: add correct arguments")]
protected virtual void Init (HttpApplication application)
{
application.PostMapRequestHandler += PostMapRequestHandler;
--- /dev/null
+2008-09-18 Atsushi Enomoto <atsushi@ximian.com>
+
+ * test.html : dummy file.
+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().
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 ()
{
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");
+ }
}
}
public override string ApplyAppPathModifier (string virtualPath)
{
switch (impl_type) {
+ case 3:
+ return virtualPath; // pass thru
case 2:
return virtualPath + "_modified";
case 1:
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");
+ }
+ }
}
}
--- /dev/null
+<html>
+<body>
+<p>TEST</p>
+</body>
+</html>