[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)]
+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.
+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.
[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 ();
}
}
[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; }
}
}
[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]
[MonoTODO]
public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
{
+ if (requestContext == null)
+ throw new ArgumentNullException ("requestContext");
+ // null values is allowed.
+
throw new NotImplementedException ();
}
[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 ();
}
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;
}
}
}
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;
}
}
}
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class RouteTable
{
- [MonoTODO]
+ static RouteTable ()
+ {
+ Routes = new RouteCollection ();
+ }
+
public static RouteCollection Routes { get; private set; }
}
}
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);
}
}
}
[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)
[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);
[MonoTODO]
public RouteCollection RouteCollection { get; set; }
- [MonoTODO]
protected virtual void Dispose ()
{
- throw new NotImplementedException ();
}
void IHttpModule.Dispose ()
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]
[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; }
}
}
--- /dev/null
+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
--- /dev/null
+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.
--- /dev/null
+//
+// 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));
+ }
+ }
+}
--- /dev/null
+//
+// 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);
+ }
+ }
+}
--- /dev/null
+//
+// 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"));
+ }
+ }
+}
--- /dev/null
+//
+// 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");
+ }
+ }
+}
--- /dev/null
+//
+// 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 ()));
+ }
+ }
+}
--- /dev/null
+//
+// 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 ();
+ }
+ }
+}
--- /dev/null
+//
+// 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));
+ }
+ }
+}
--- /dev/null
+//
+// 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);
+ }
+ }
+}