some implementations and tests.
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 11 Sep 2008 14:38:17 +0000 (14:38 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 11 Sep 2008 14:38:17 +0000 (14:38 -0000)
svn path=/trunk/mcs/; revision=112761

24 files changed:
mcs/class/System.Web.Routing/Assembly/AssemblyInfo.cs
mcs/class/System.Web.Routing/Assembly/ChangeLog
mcs/class/System.Web.Routing/System.Web.Routing/ChangeLog
mcs/class/System.Web.Routing/System.Web.Routing/HttpMethodConstraint.cs
mcs/class/System.Web.Routing/System.Web.Routing/RequestContext.cs
mcs/class/System.Web.Routing/System.Web.Routing/Route.cs
mcs/class/System.Web.Routing/System.Web.Routing/RouteCollection.cs
mcs/class/System.Web.Routing/System.Web.Routing/RouteData.cs
mcs/class/System.Web.Routing/System.Web.Routing/RouteTable.cs
mcs/class/System.Web.Routing/System.Web.Routing/RouteValueDictionary.cs
mcs/class/System.Web.Routing/System.Web.Routing/StopRoutingHandler.cs
mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingHandler.cs
mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs
mcs/class/System.Web.Routing/System.Web.Routing/VirtualPathData.cs
mcs/class/System.Web.Routing/System.Web.Routing_test.dll.sources [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/ChangeLog [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/HttpMethodConstraintTest.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteCollectionTest.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteDataTest.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteTest.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/StopRoutingHandlerTest.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/TestStubTypes.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/UrlRoutingHandlerTest.cs [new file with mode: 0644]
mcs/class/System.Web.Routing/Test/System.Web.Routing/VirtualPathDataTest.cs [new file with mode: 0644]

index 08de6ff409b2f7241f16d7c24117ce5e9947887b..083cb09550a4008a36293f36fe44ed6f55168d11 100644 (file)
@@ -55,7 +55,7 @@ using System.Runtime.InteropServices;
 [assembly: NeutralResourcesLanguage ("en-US")]
 [assembly: CLSCompliant (true)]
 [assembly: AssemblyDelaySign (true)]
-[assembly: AssemblyKeyFile ("../ecma.pub")]
+[assembly: AssemblyKeyFile ("../winfx.pub")]
 
 [assembly: ComVisible (false)]
 [assembly: ComCompatibleVersion (1, 0, 3300, 0)]
index 0ed98aa1f75a3c7c6b3b50cebe02c4f18e7de0a6..c8167ea7739dc30c8fdbf1ccd3484045cb949eb6 100644 (file)
@@ -1,3 +1,7 @@
+2008-09-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * AssemblyInfo.cs : fixed pubkey file.
+
 2008-09-04  Atsushi Enomoto  <atsushi@ximian.com>
 
        * AssemblyInfo.cs: initial checkin.
index b941518d2810533b5dd74d93bc19450d0fc6d636..7fdd26c9d1a7486d1db5b1e4d71df17cba602bad 100644 (file)
@@ -1,3 +1,11 @@
+2008-09-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * HttpMethodConstraint.cs, RequestContext.cs, Route.cs,
+         RouteCollection.cs, RouteData.cs, RouteTable.cs,
+         RouteValueDictionary.cs, StopRoutingHandler.cs,
+         UrlRoutingHandler.cs, UrlRoutingModule.cs, VirtualPathData.cs:
+         some implementation.
+
 2008-09-04  Atsushi Enomoto  <atsushi@ximian.com>
 
        *.cs: initial checkin.
index d60c84da3823130bd5d4b5749fc6bcca7d49c4a3..d3247d542f6fdff79bb19da8b58f4f7a1a96647c 100644 (file)
@@ -42,21 +42,30 @@ namespace System.Web.Routing
                [MonoTODO]
                public HttpMethodConstraint (params string[] allowedMethods)
                {
-                       throw new NotImplementedException ();
+                       if (allowedMethods == null)
+                               throw new ArgumentNullException ("allowedMethods");
+                       AllowedMethods = allowedMethods;
                }
 
-               [MonoTODO]
                public ICollection<string> AllowedMethods { get; private set; }
 
-               [MonoTODO]
                bool IRouteConstraint.Match (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
                {
-                       throw new NotImplementedException ();
+                       return Match (httpContext, route, parameterName, values, routeDirection);
                }
 
                [MonoTODO]
                protected virtual bool Match (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
                {
+                       if (httpContext == null)
+                               throw new ArgumentNullException ("httpContext");
+                       if (route == null)
+                               throw new ArgumentNullException ("route");
+                       if (parameterName == null)
+                               throw new ArgumentNullException ("parameterName");
+                       if (values == null)
+                               throw new ArgumentNullException ("values");
+
                        throw new NotImplementedException ();
                }
        }
index 1887dd9a57ca2ebd1731941cc8863054f4c2c620..8cb73a40faea5932525e1a7a3dd6a8f22c9aed79 100644 (file)
@@ -37,15 +37,19 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class RequestContext
        {
-               [MonoTODO]
                public RequestContext (HttpContextBase httpContext, RouteData routeData)
                {
+                       if (httpContext == null)
+                               throw new ArgumentNullException ("httpContext");
+                       if (routeData == null)
+                               throw new ArgumentNullException ("routeData");
+
+                       HttpContext = httpContext;
+                       RouteData = routeData;
                }
 
-               [MonoTODO]
-               public HttpContextBase HttpContext { get; internal set; }
+               public HttpContextBase HttpContext { get; private set; }
 
-               [MonoTODO]
-               public RouteData RouteData { get; internal set; }
+               public RouteData RouteData { get; private set; }
        }
 }
index 77ab8d6b7595457dee017c14bb2d40105eaf4135..434127d0537e87bf843398aa1e0f3c99f2d05b80 100644 (file)
@@ -37,39 +37,43 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class Route : RouteBase
        {
-               [MonoTODO]
+               string url;
+
                public RouteValueDictionary Constraints { get; set; }
-               [MonoTODO]
+
                public RouteValueDictionary DataTokens { get; set; }
-               [MonoTODO]
+
                public RouteValueDictionary Defaults { get; set; }
-               [MonoTODO]
+
                public IRouteHandler RouteHandler { get; set; }
-               [MonoTODO]
-               public string Url { get; set; }
 
-               [MonoTODO]
+               public string Url {
+                       get { return url; }
+                       set { url = value ?? String.Empty; }
+               }
+
                public Route (string url, IRouteHandler routeHandler)
+                       : this (url, null, routeHandler)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public Route (string url, RouteValueDictionary defaults, IRouteHandler routeHandler)
+                       : this (url, defaults, null, routeHandler)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public Route (string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler)
+                       : this (url, defaults, constraints, null, routeHandler)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public Route (string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler)
                {
-                       throw new NotImplementedException ();
+                       Url = url;
+                       Defaults = defaults;
+                       Constraints = constraints;
+                       DataTokens = dataTokens;
+                       RouteHandler = routeHandler;
                }
 
                [MonoTODO]
@@ -81,6 +85,10 @@ namespace System.Web.Routing
                [MonoTODO]
                public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
                {
+                       if (requestContext == null)
+                               throw new ArgumentNullException ("requestContext");
+                       // null values is allowed.
+
                        throw new NotImplementedException ();
                }
 
index 838299b30a1e18253c79bddc91d9570dbc2b3537..72750ad508c4bd55cbfa9cea638f2db5c437f479 100644 (file)
@@ -41,47 +41,88 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class RouteCollection : Collection<RouteBase>
        {
-               [MonoTODO]
+               class Lock : IDisposable
+               {
+                       RouteCollection owner;
+                       bool read;
+
+                       public Lock (RouteCollection owner, bool read)
+                       {
+                               this.owner = owner;
+                               this.read = read;
+                       }
+
+                       public void Dispose ()
+                       {
+                               //if (read)
+                               //      owner.read_lock = null;
+                               //else
+                               //      owner_write_lock = null;
+                       }
+               }
+
                public RouteCollection ()
+                       : this (null)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public RouteCollection (VirtualPathProvider virtualPathProvider)
                {
-                       throw new NotImplementedException ();
+                       // null argument is allowed
+                       provider = virtualPathProvider;
+
+                       read_lock = new Lock (this, true);
+                       write_lock = new Lock (this, false);
                }
 
-               [MonoTODO]
+               VirtualPathProvider provider;
+               Dictionary<string,RouteBase> d = new Dictionary<string,RouteBase> ();
+
+               Lock read_lock, write_lock;
+
                public RouteBase this [string name] {
-                       get { throw new NotImplementedException (); }
+                       get {
+                               foreach (var p in d)
+                                       if (p.Key == name)
+                                               return p.Value;
+                               return null;
+                       }
                }
 
                [MonoTODO]
                public bool RouteExistingFiles { get; set; }
 
-               [MonoTODO]
                public void Add (string name, RouteBase item)
                {
-                       throw new NotImplementedException ();
+                       lock (GetWriteLock ()) {
+                               base.Add (item);
+                               if (!String.IsNullOrEmpty (name))
+                                       d.Add (name, item);
+                       }
                }
 
-               [MonoTODO]
                protected override void ClearItems ()
                {
-                       throw new NotImplementedException ();
+                       lock (GetWriteLock ())
+                               base.ClearItems ();
                }
 
-               [MonoTODO]
                public IDisposable GetReadLock ()
                {
-                       throw new NotImplementedException ();
+                       return read_lock;
                }
 
                [MonoTODO]
                public RouteData GetRouteData (HttpContextBase httpContext)
                {
+                       if (httpContext == null)
+                               throw new ArgumentNullException ("httpContext");
+                       var path = httpContext.Request.AppRelativeCurrentExecutionFilePath;
+
+                       // some matching test is done here.
+
+                       var pathInfo = httpContext.Request.PathInfo;
+
                        throw new NotImplementedException ();
                }
 
@@ -97,28 +138,47 @@ namespace System.Web.Routing
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public IDisposable GetWriteLock ()
                {
-                       throw new NotImplementedException ();
+                       return write_lock;
                }
 
-               [MonoTODO]
                protected override void InsertItem (int index, RouteBase item)
                {
-                       throw new NotImplementedException ();
+                       // FIXME: what happens wrt its name?
+                       lock (GetWriteLock ())
+                               base.InsertItem (index, item);
                }
 
-               [MonoTODO]
                protected override void RemoveItem (int index)
                {
-                       throw new NotImplementedException ();
+                       // FIXME: what happens wrt its name?
+                       lock (GetWriteLock ()) {
+                               string k = GetKey (index);
+                               base.RemoveItem (index);
+                               if (k != null)
+                                       d.Remove (k);
+                       }
                }
 
-               [MonoTODO]
                protected override void SetItem (int index, RouteBase item)
                {
-                       throw new NotImplementedException ();
+                       // FIXME: what happens wrt its name?
+                       lock (GetWriteLock ()) {
+                               string k = GetKey (index);
+                               base.SetItem (index, item);
+                               if (k != null)
+                                       d.Remove (k);
+                       }
+               }
+
+               string GetKey (int index)
+               {
+                       var item = this [index];
+                       foreach (var p in d)
+                               if (p.Value == item)
+                                       return p.Key;
+                       return null;
                }
        }
 }
index e38c27ec8cf137f5d73de1f580c8999f881a402f..a3d28aa07c0865cfbbb75645985c064bc2a0ee07 100644 (file)
@@ -38,29 +38,37 @@ namespace System.Web.Routing
        public class RouteData
        {
                public RouteData ()
+                       : this (null, null)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public RouteData (RouteBase route, IRouteHandler routeHandler)
                {
-                       throw new NotImplementedException ();
+                       // arguments can be null.
+                       Route = route;
+                       RouteHandler = routeHandler;
+
+                       DataTokens = new RouteValueDictionary ();
+                       Values = new RouteValueDictionary ();
                }
 
-               [MonoTODO]
                public RouteValueDictionary DataTokens { get; private set; }
-               [MonoTODO]
+
                public RouteBase Route { get; set; }
-               [MonoTODO]
+
                public IRouteHandler RouteHandler { get; set; }
-               [MonoTODO]
+
                public RouteValueDictionary Values { get; private set; }
 
-               [MonoTODO]
                public string GetRequiredString (string valueName)
                {
-                       throw new NotImplementedException ();
+                       object o;
+                       if (!Values.TryGetValue (valueName, out o))
+                               throw new InvalidOperationException (String.Format ("value name {0} does not match any of the values.", valueName));
+                       string s = o as string;
+                       if (String.IsNullOrEmpty (s))
+                               throw new InvalidOperationException (String.Format ("The value for the name {0} must be a non-empty string", valueName));
+                       return s;
                }
        }
 }
index 381db48bc87d0056a0eebd226f9a29085cb5fe0d..5ab3369ad0c18a349a86839dbc053963f95ac2a9 100644 (file)
@@ -38,7 +38,11 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class RouteTable
        {
-               [MonoTODO]
+               static RouteTable ()
+               {
+                       Routes = new RouteCollection ();
+               }
+
                public static RouteCollection Routes { get; private set; }
        }
 }
index c23b3c35c9514b46cc673e4dfe80068b5d90b28a..c356a3d0aae8e24be7593a2321a39167fbfe696b 100644 (file)
@@ -33,137 +33,128 @@ using System.Collections.Generic;
 using System.Security.Permissions;
 using System.Web;
 
+using PairCollection = System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<string, object>>;
+
 namespace System.Web.Routing
 {
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
-       public class RouteValueDictionary : IDictionary<string, object>, 
-               ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, 
-               IEnumerable
+       public class RouteValueDictionary : IDictionary<string, object>
        {
-               [MonoTODO]
+               Dictionary<string,object> d = new Dictionary<string,object> ();
+
                public RouteValueDictionary ()
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public RouteValueDictionary (IDictionary<string, object> dictionary)
                {
-                       throw new NotImplementedException ();
+                       if (dictionary == null)
+                               throw new ArgumentNullException ("dictionary");
+                       foreach (var p in dictionary)
+                               Add (p.Key, p.Value);
                }
 
-               [MonoTODO]
                public RouteValueDictionary (object values)
                {
-                       throw new NotImplementedException ();
+                       if (values == null)
+                               throw new ArgumentNullException ("values");
+                       foreach (var p in (IEnumerable<KeyValuePair<string,object>>) values)
+                               Add (p.Key, p.Value);
+               }
+
+               public int Count {
+                       get { return d.Count; }
                }
 
-               [MonoTODO]
-               public int Count { get; private set; }
-               [MonoTODO]
-               bool ICollection<KeyValuePair<string, object>>.IsReadOnly {
-                       get { throw new NotImplementedException (); }
+               bool PairCollection.IsReadOnly {
+                       get { return ((PairCollection) d).IsReadOnly; }
                }
 
-               [MonoTODO]
                ICollection<string> IDictionary<string, object>.Keys {
-                       get { throw new NotImplementedException (); }
+                       get { return d.Keys; }
                }
 
-               [MonoTODO]
                ICollection<Object> IDictionary<string, object>.Values {
-                       get { throw new NotImplementedException (); }
+                       get { return d.Values; }
                }
 
-               [MonoTODO]
                public object this [string key] {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { return d [key]; }
+                       set { d [key] = value; }
                }
 
-               [MonoTODO]
-               public Dictionary<string, object>.KeyCollection Keys { get; private set; }
+               public Dictionary<string, object>.KeyCollection Keys {
+                       get { return d.Keys; }
+               }
 
-               [MonoTODO]
-               public Dictionary<string, object>.ValueCollection Values { get; private set; }
+               public Dictionary<string, object>.ValueCollection Values {
+                       get { return d.Values; }
+               }
 
-               [MonoTODO]
                public void Add (string key, object value)
                {
-                       throw new NotImplementedException ();
+                       d.Add (key, value);
                }
 
-               [MonoTODO]
                public void Clear ()
                {
-                       throw new NotImplementedException ();
+                       d.Clear ();
                }
 
-               [MonoTODO]
                public bool ContainsKey (string key)
                {
-                       throw new NotImplementedException ();
+                       return d.ContainsKey (key);
                }
 
-               [MonoTODO]
                public bool ContainsValue (object value)
                {
-                       throw new NotImplementedException ();
+                       return d.ContainsValue (value);
                }
 
-               [MonoTODO]
                public Dictionary<string, object>.Enumerator GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return d.GetEnumerator ();
                }
 
-               [MonoTODO]
                void ICollection<KeyValuePair<string, object>>.Add (KeyValuePair<string, object> item)
                {
-                       throw new NotImplementedException ();
+                       ((PairCollection) d).Add (item);
                }
 
-               [MonoTODO]
                bool ICollection<KeyValuePair<string, object>>.Contains (KeyValuePair<string, object> item)
                {
-                       throw new NotImplementedException ();
+                       return ((PairCollection) d).Contains (item);
                }
 
-               [MonoTODO]
                void ICollection<KeyValuePair<string, object>>.CopyTo (KeyValuePair<string, object> [] array, int arrayIndex)
                {
-                       throw new NotImplementedException ();
+                       ((PairCollection) d).CopyTo (array, arrayIndex);
                }
 
-               [MonoTODO]
                bool ICollection<KeyValuePair<string, object>>.Remove (KeyValuePair<string, object> item)
                {
-                       throw new NotImplementedException ();
+                       return ((PairCollection) d).Remove (item);
                }
 
-               [MonoTODO]
                IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator()
                {
-                       throw new NotImplementedException ();
+                       return d.GetEnumerator ();
                }
 
-               [MonoTODO]
                IEnumerator IEnumerable.GetEnumerator ()
                {
-                       throw new NotImplementedException ();
+                       return d.GetEnumerator ();
                }
 
-               [MonoTODO]
                public bool Remove (string key)
                {
-                       throw new NotImplementedException ();
+                       return d.Remove (key);
                }
 
-               [MonoTODO]
                public bool TryGetValue (string key, out object value)
                {
-                       throw new NotImplementedException ();
+                       return d.TryGetValue (key, out value);
                }
        }
 }
index e083e1bb5fa97099ebdaa7d0fa49ef160aeb0360..5549563dcc9d9c11a4b0bba32d72bae64eda3380 100644 (file)
@@ -37,10 +37,9 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class StopRoutingHandler : IRouteHandler
        {
-               [MonoTODO]
                protected virtual IHttpHandler GetHttpHandler (RequestContext requestContext)
                {
-                       throw new NotImplementedException ();
+                       throw new NotSupportedException ();
                }
 
                IHttpHandler IRouteHandler.GetHttpHandler (RequestContext requestContext)
index ce0a6a1e930f1a5e0d0d5635e8a190541ed85ce9..561e6998a6d708b49cd20f4dfe3aa9edd0c91ec4 100644 (file)
@@ -37,32 +37,46 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public abstract class UrlRoutingHandler : IHttpHandler
        {
-               [MonoTODO]
+               RouteCollection routes;
+
                bool IHttpHandler.IsReusable {
                        get { return IsReusable; }
                }
 
-               [MonoTODO]
-               protected virtual bool IsReusable { get; private set; }
+               protected virtual bool IsReusable { get { return false; } }
 
-               [MonoTODO]
-               public RouteCollection RouteCollection { get; set; }
+               public RouteCollection RouteCollection {
+                       get {
+                               if (routes == null)
+                                       routes = RouteTable.Routes;
+                               return routes;
+                       }
+                       set { routes = value; }
+               }
 
                void IHttpHandler.ProcessRequest (HttpContext context)
                {
                        ProcessRequest (context);
                }
 
-               [MonoTODO]
                protected virtual void ProcessRequest (HttpContext httpContext)
                {
-                       throw new NotImplementedException ();
+                       ProcessRequest (new HttpContextWrapper (httpContext));
                }
 
                [MonoTODO]
                protected virtual void ProcessRequest (HttpContextBase httpContext)
                {
+                       var rd = RouteCollection.GetRouteData (httpContext);
+                       if (rd == null)
+                               throw new HttpException ("The incoming request does not match any route");
+
                        throw new NotImplementedException ();
+
+                       RequestContext rc = null;
+
+                       var hh = rd.RouteHandler.GetHttpHandler (rc);
+                       VerifyAndProcessRequest (hh, httpContext);
                }
 
                protected abstract void VerifyAndProcessRequest (IHttpHandler httpHandler, HttpContextBase httpContext);
index c11e7e66480ca61e866558d5a65d5cca60eeebb1..156562b1c53b19e1d9669feb18ee98b81d359874 100644 (file)
@@ -40,10 +40,8 @@ namespace System.Web.Routing
                [MonoTODO]
                public RouteCollection RouteCollection { get; set; }
 
-               [MonoTODO]
                protected virtual void Dispose ()
                {
-                       throw new NotImplementedException ();
                }
 
                void IHttpModule.Dispose ()
@@ -56,10 +54,23 @@ namespace System.Web.Routing
                        Init (application);
                }
 
-               [MonoTODO]
+               [MonoTODO ("FIXME: add correct arguments")]
                protected virtual void Init (HttpApplication application)
                {
-                       throw new NotImplementedException ();
+                       application.PostMapRequestHandler += PostMapRequestHandler;
+                       application.PostResolveRequestCache += PostResolveRequestCache;
+               }
+
+               void PostMapRequestHandler (object o, EventArgs e)
+               {
+                       var app = (HttpApplication) o;
+                       PostMapRequestHandler (new HttpContextWrapper (app.Context));
+               }
+
+               void PostResolveRequestCache (object o, EventArgs e)
+               {
+                       var app = (HttpApplication) o;
+                       PostResolveRequestCache (new HttpContextWrapper (app.Context));
                }
 
                [MonoTODO]
index 12e18e17d32ac742c34d84161385a8efa6c71275..05af30095c29f5869c24caef0925b79adf7327bd 100644 (file)
@@ -37,19 +37,18 @@ namespace System.Web.Routing
        [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class VirtualPathData
        {
-               [MonoTODO]
                public VirtualPathData (RouteBase route, string virtualPath)
                {
-                       throw new NotImplementedException ();
+                       // arguments can be null.
+                       Route = route;
+                       VirtualPath = virtualPath;
+                       DataTokens = new RouteValueDictionary ();
                }
 
-               [MonoTODO]
                public RouteValueDictionary DataTokens { get; private set; }
 
-               [MonoTODO]
                public RouteBase Route { get; set; }
 
-               [MonoTODO]
                public string VirtualPath { get; set; }
        }
 }
diff --git a/mcs/class/System.Web.Routing/System.Web.Routing_test.dll.sources b/mcs/class/System.Web.Routing/System.Web.Routing_test.dll.sources
new file mode 100644 (file)
index 0000000..1af5f4c
--- /dev/null
@@ -0,0 +1,8 @@
+System.Web.Routing/HttpMethodConstraintTest.cs
+System.Web.Routing/RouteCollectionTest.cs
+System.Web.Routing/RouteDataTest.cs
+System.Web.Routing/RouteTest.cs
+System.Web.Routing/StopRoutingHandlerTest.cs
+System.Web.Routing/TestStubTypes.cs
+System.Web.Routing/UrlRoutingHandlerTest.cs
+System.Web.Routing/VirtualPathDataTest.cs
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/ChangeLog b/mcs/class/System.Web.Routing/Test/System.Web.Routing/ChangeLog
new file mode 100644 (file)
index 0000000..0abaf50
--- /dev/null
@@ -0,0 +1,6 @@
+2008-09-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * HttpMethodConstraintTest.cs, RouteCollectionTest.cs,
+         RouteDataTest.cs, RouteTest.cs, StopRoutingHandlerTest.cs,
+         TestStubTypes.cs, UrlRoutingHandlerTest.cs,
+         VirtualPathDataTest.cs : initial checkin.
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/HttpMethodConstraintTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/HttpMethodConstraintTest.cs
new file mode 100644 (file)
index 0000000..0e8f378
--- /dev/null
@@ -0,0 +1,105 @@
+//
+// HttpMethodConstraintTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       class MyHttpMethodConstraint : HttpMethodConstraint
+       {
+               public MyHttpMethodConstraint (params string [] args)
+                       : base (args)
+               {
+               }
+
+               public bool CallMatch (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
+               {
+                       return Match (httpContext, route, parameterName, values, routeDirection);
+               }
+       }
+
+       [TestFixture]
+       public class HttpMethodConstraintTest
+       {
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorNullArgs ()
+               {
+                       new HttpMethodConstraint (null);
+               }
+
+               [Test]
+               public void ConstructorEmptyArray ()
+               {
+                       new HttpMethodConstraint (new string [0]);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void MatchNullContext ()
+               {
+                       var c = new MyHttpMethodConstraint (new string [0]);
+                       c.CallMatch (null, new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void MatchNullRoute ()
+               {
+                       var c = new MyHttpMethodConstraint (new string [0]);
+                       c.CallMatch (new HttpContextStub (), null, "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void MatchNullName ()
+               {
+                       var c = new MyHttpMethodConstraint (new string [0]);
+                       c.CallMatch (new HttpContextStub (), new Route (null, null), null, new RouteValueDictionary (), RouteDirection.IncomingRequest);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void MatchNullValues ()
+               {
+                       var c = new MyHttpMethodConstraint (new string [0]);
+                       c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", null, RouteDirection.IncomingRequest);
+               }
+
+               [Test]
+               public void Match ()
+               {
+                       var c = new MyHttpMethodConstraint (new string [0]);
+                       Assert.IsFalse (c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest));
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteCollectionTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteCollectionTest.cs
new file mode 100644 (file)
index 0000000..5107833
--- /dev/null
@@ -0,0 +1,134 @@
+//
+// RouteCollectionTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class RouteCollectionTest
+       {
+               [Test]
+               public void ConstructorNullArgs ()
+               {
+                       // allowed
+                       new RouteCollection (null);
+               }
+
+               [Test]
+               public void AddNullMame ()
+               {
+                       var c = new RouteCollection ();
+                       // when name is null, no duplicate check is done.
+                       c.Add (null, new Route (null, null));
+                       c.Add (null, new Route (null, null));
+               }
+
+               [Test]
+               public void AddDuplicateEmpty ()
+               {
+                       var c = new RouteCollection ();
+                       // when name is "", no duplicate check is done.
+                       c.Add ("", new Route (null, null));
+                       c.Add ("", new Route (null, null));
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void AddDuplicateName ()
+               {
+                       var c = new RouteCollection ();
+                       c.Add ("x", new Route (null, null));
+                       c.Add ("x", new Route (null, null));
+               }
+
+               [Test]
+               public void IndexForNonExistent ()
+               {
+                       Assert.IsNull (new RouteCollection () [null]);
+               }
+
+               [Test]
+               public void IndexForExistent ()
+               {
+                       var c = new RouteCollection ();
+                       var r = new Route (null, null);
+                       c.Add ("x", r);
+                       Assert.AreEqual (r, c ["x"]);
+               }
+
+               [Test]
+               public void IndexForNonExistentAfterRemoval ()
+               {
+                       var c = new RouteCollection ();
+                       var r = new Route (null, null);
+                       c.Add ("x", r);
+                       c.Remove (r);
+                       Assert.IsNull(c ["x"]);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void GetRouteDataNullArg ()
+               {
+                       new RouteCollection ().GetRouteData (null);
+               }
+
+               [Test]
+               public void GetRouteDataForNonExistent ()
+               {
+                       var rd = new RouteCollection ().GetRouteData (new HttpContextStub ("~/foo"));
+                       Assert.IsNull (rd);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void GetRouteDataForPathInfoNIE ()
+               {
+                       var c = new RouteCollection ();
+                       var r = new Route ("foo", null);
+                       c.Add (null, r);
+                       // it retrieves PathInfo and then dies.
+                       var rd = c.GetRouteData (new HttpContextStub ("~/foo"));
+               }
+
+               [Test]
+               public void GetRouteDataForNullHandler ()
+               {
+                       var c = new RouteCollection ();
+                       var r = new Route ("foo", null);
+                       c.Add (null, r);
+                       var rd = c.GetRouteData (new HttpContextStub ("~/foo", String.Empty));
+                       Assert.AreEqual (r, rd.Route);
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteDataTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteDataTest.cs
new file mode 100644 (file)
index 0000000..df7b9ef
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// RouteDataTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class RouteDataTest
+       {
+               [Test]
+               public void ConstructorNullArgs ()
+               {
+                       new RouteData (null, null);
+               }
+
+               [Test]
+               public void DefaultValues ()
+               {
+                       var d = new RouteData ();
+                       Assert.IsNull (d.Route, "#1");
+                       Assert.IsNull (d.RouteHandler, "#2");
+                       Assert.AreEqual (0, d.DataTokens.Count, "#3");
+                       Assert.AreEqual (0, d.Values.Count, "#4");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void GetRequiredStringNull ()
+               {
+                       var d = new RouteData ();
+                       d.GetRequiredString (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void GetRequiredStringNonexistent ()
+               {
+                       var d = new RouteData ();
+                       d.GetRequiredString ("a");
+               }
+
+               [Test]
+               public void GetRequiredStringExistent ()
+               {
+                       var d = new RouteData ();
+                       d.Values.Add ("a", "x");
+                       Assert.AreEqual ("x", d.GetRequiredString ("a"));
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void GetRequiredStringForNonStringValue ()
+               {
+                       var d = new RouteData ();
+                       d.Values.Add ("a", 10);
+                       Assert.AreEqual ("10", d.GetRequiredString ("a"));
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/RouteTest.cs
new file mode 100644 (file)
index 0000000..94e45a1
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// RouteTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class RouteTest
+       {
+               [Test]
+               public void ConstructorNullArgs ()
+               {
+                       var r = new Route (null, null);
+                       Assert.AreEqual (String.Empty, r.Url);
+                       Assert.IsNull (r.RouteHandler);
+               }
+
+               [Test]
+               public void SetNullUrl ()
+               {
+                       var r = new Route (null, null);
+                       r.Url = "urn:foo";
+                       r.Url = null;
+                       Assert.AreEqual (String.Empty, r.Url);
+               }
+
+               [Test]
+               public void RoutingHandler ()
+               {
+                       var r = new Route (null, new StopRoutingHandler ());
+                       Assert.AreEqual (typeof (StopRoutingHandler), r.RouteHandler.GetType (), "#1");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void GetVirtualPathNullContext ()
+               {
+                       try {
+                               var r = new Route (null, null);
+                               r.GetVirtualPath (null, new RouteValueDictionary ());
+                       } catch (NullReferenceException) {
+                               // .NET lacks null arg check here. (No need to mimic silly behavior here.)
+                               throw new ArgumentNullException ();
+                       }
+               }
+
+               [Test]
+               public void GetVirtualPathNullValues ()
+               {
+                       // null values is allowed.
+                       var r = new Route (null, null);
+                       var rd = new RouteData ();
+                       var vp = r.GetVirtualPath (new RequestContext (new HttpContextStub (), rd), null);
+                       Assert.AreEqual (String.Empty, vp.VirtualPath, "#1");
+                       Assert.AreEqual (r, vp.Route, "#2");
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/StopRoutingHandlerTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/StopRoutingHandlerTest.cs
new file mode 100644 (file)
index 0000000..3e72772
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// StopRoutingHandlerTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class StopRoutingHandlerTest
+       {
+               [Test]
+               [ExpectedException (typeof (NotSupportedException))]
+               public void GetHandler ()
+               {
+                       new MyStopRoutingHandler ().CallGetHttpHandler (new RequestContext (new HttpContextStub (), new RouteData ()));
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/TestStubTypes.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/TestStubTypes.cs
new file mode 100644 (file)
index 0000000..6820595
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// TestStubTypes.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       class HttpContextStub : HttpContextBase
+       {
+               HttpRequestStub req;
+
+               public HttpContextStub ()
+                       : this (null)
+               {
+               }
+
+               public HttpContextStub (string dummyRequestPath)
+                       : this (dummyRequestPath, null)
+               {
+               }
+
+               public HttpContextStub (string dummyRequestPath, string pathInfo)
+               {
+                       if (dummyRequestPath != null)
+                               req = new HttpRequestStub (dummyRequestPath, pathInfo);
+               }
+
+               public override HttpRequestBase Request {
+                       get { return req != null ? req : base.Request; }
+               }
+       }
+
+       class HttpRequestStub : HttpRequestBase
+       {
+               public HttpRequestStub (string dummyRequestPath, string pathInfo)
+               {
+                       req_path = dummyRequestPath;
+                       path_info = pathInfo;
+               }
+
+               string req_path, path_info;
+
+               public override string AppRelativeCurrentExecutionFilePath {
+                       get { return req_path ?? base.AppRelativeCurrentExecutionFilePath; }
+               }
+
+               public override string PathInfo {
+                       get { return path_info ?? base.PathInfo; }
+               }
+       }
+
+       public class MyStopRoutingHandler : StopRoutingHandler
+       {
+               public IHttpHandler CallGetHttpHandler (RequestContext rc)
+               {
+                       return GetHttpHandler (rc);
+               }
+       }
+
+       public class MyUrlRoutingHandler : UrlRoutingHandler
+       {
+               public void DoProcessRequest (HttpContextBase httpContext)
+               {
+                       ProcessRequest (httpContext);
+               }
+
+               protected override void VerifyAndProcessRequest (IHttpHandler httpHandler, HttpContextBase httpContext)
+               {
+                       throw new ApplicationException ();
+               }
+       }
+
+       public class ErrorRouteHandler : IRouteHandler
+       {
+               public IHttpHandler GetHttpHandler (RequestContext requestContext)
+               {
+                       throw new ApplicationException ();
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/UrlRoutingHandlerTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/UrlRoutingHandlerTest.cs
new file mode 100644 (file)
index 0000000..a8c97ea
--- /dev/null
@@ -0,0 +1,146 @@
+//
+// UrlRoutingHandlerTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class UrlRoutingHandlerTest
+       {
+               [SetUp]
+               public void SetUp ()
+               {
+                       RouteTable.Routes.Clear ();
+               }
+
+               [Test]
+               public void SetRouteCollectionNull ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       RouteTable.Routes.Add (new Route (null, null));
+                       Assert.IsNotNull (h.RouteCollection, "#1");
+                       Assert.AreEqual (RouteTable.Routes, h.RouteCollection, "#1-2");
+                       h.RouteCollection = null;
+                       Assert.IsNotNull (h.RouteCollection, "#2");
+                       Assert.AreEqual (RouteTable.Routes, h.RouteCollection, "#2-2");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ProcessRequestNullArg ()
+               {
+                       new MyUrlRoutingHandler ().DoProcessRequest (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void ProcessRequestForStubContext ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       // it results in call to HttpContextBase.get_Request() and thus NIE.
+                       h.DoProcessRequest (new HttpContextStub ());
+               }
+
+               [Test]
+               [ExpectedException (typeof (HttpException))]
+               public void ProcessRequestNoMatch ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       Assert.AreEqual (0, h.RouteCollection.Count, "#1");
+                       h.DoProcessRequest (new HttpContextStub ("~/foo"));
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotImplementedException))]
+               public void ProcessRequestPathInfoNIE ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       var r = new Route ("foo", null);
+                       h.RouteCollection.Add (r);
+                       // it internally calls RouteCollection.GetRouteData() 
+                       // and borks at HttpContextStub.Request.PathInfo NIE.
+                       h.DoProcessRequest (new HttpContextStub ("~/foo"));
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void ProcessRequestNoHandler ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       var r = new Route ("foo", null);
+                       h.RouteCollection.Add (r);
+                       h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
+               }
+
+               [Test]
+               [ExpectedException (typeof (HttpException))]
+               public void ProcessRequestNoMatch2 ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       var r = new Route ("foo", null);
+                       h.RouteCollection.Add (r);
+                       h.DoProcessRequest (new HttpContextStub ("~/bar", String.Empty));
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void ProcessRequestMatchNoHandler ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       var r = new Route ("foo", null);
+                       h.RouteCollection.Add (r);
+                       h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
+               }
+
+               [Test]
+               [ExpectedException (typeof (NotSupportedException))]
+               public void ProcessRequestMatchStop ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       var r = new Route ("foo", new StopRoutingHandler ());
+                       h.RouteCollection.Add (r);
+                       h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
+                       // thrown by StopRoutingHandler.GetHttpHandler().
+               }
+
+               [Test]
+               [ExpectedException (typeof (ApplicationException))]
+               public void ProcessRequestMatchError ()
+               {
+                       var h = new MyUrlRoutingHandler ();
+                       var r = new Route ("foo", new ErrorRouteHandler ());
+                       h.RouteCollection.Add (r);
+                       h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
+               }
+       }
+}
diff --git a/mcs/class/System.Web.Routing/Test/System.Web.Routing/VirtualPathDataTest.cs b/mcs/class/System.Web.Routing/Test/System.Web.Routing/VirtualPathDataTest.cs
new file mode 100644 (file)
index 0000000..b92431d
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// VirtualPathDataTest.cs
+//
+// Author:
+//     Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Web;
+using System.Web.Routing;
+using NUnit.Framework;
+
+namespace MonoTests.System.Web.Routing
+{
+       [TestFixture]
+       public class VirtualPathDataTest
+       {
+               [Test]
+               public void ConstructorNullArgs ()
+               {
+                       new VirtualPathData (null, null);
+               }
+       }
+}