5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 Novell Inc. http://novell.com
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
33 using System.Web.Routing;
34 using NUnit.Framework;
36 namespace MonoTests.System.Web.Routing
38 class HttpContextStub : HttpContextBase
42 public HttpContextStub ()
47 public HttpContextStub (string dummyRequestPath)
48 : this (dummyRequestPath, null)
52 public HttpContextStub (string dummyRequestPath, string pathInfo)
53 : this (dummyRequestPath, pathInfo, null)
57 public HttpContextStub (string dummyRequestPath, string pathInfo, string method)
59 if (dummyRequestPath != null) {
60 req = new HttpRequestStub (dummyRequestPath, pathInfo);
65 public override HttpRequestBase Request {
66 get { return req != null ? req : base.Request; }
70 class HttpRequestStub : HttpRequestBase
72 public HttpRequestStub (string dummyRequestPath, string pathInfo)
74 req_path = dummyRequestPath;
78 string req_path, path_info;
80 public override string AppRelativeCurrentExecutionFilePath {
81 get { return req_path ?? base.AppRelativeCurrentExecutionFilePath; }
84 public override string PathInfo {
85 get { return path_info ?? base.PathInfo; }
88 public override string HttpMethod {
89 get { return Method; }
92 public string Method { get; set; }
95 class MyDictionary : Hashtable
97 public override ICollection Keys {
101 public override object this [object key] {
103 //Console.Error.WriteLine ("Get: {0} {1}", key, key.GetHashCode ());
107 //Console.Error.WriteLine ("Set: {0} {1} = {2}", key, key.GetHashCode (), value);
113 class HttpContextStub2 : HttpContextBase
115 public HttpContextStub2 ()
120 public HttpContextStub2 (string requestUrl, string path)
121 : this (requestUrl, path, null)
125 public HttpContextStub2 (string requestUrl, string path, string appPath)
127 request = new HttpRequestStub2 (requestUrl, path, appPath);
130 Hashtable items = new MyDictionary ();
131 HttpRequestStub request;
132 HttpResponseBase response;
134 public override IDictionary Items {
135 get { return items; }
138 public override HttpRequestBase Request {
139 get { return request ?? base.Request; }
142 public override HttpResponseBase Response {
143 get { return response ?? base.Response; }
146 public override void RewritePath (string path)
148 throw new ApplicationException (path);
151 public void SetResponse (HttpResponseBase response)
153 this.response = response;
157 class HttpRequestStub2 : HttpRequestStub
159 public HttpRequestStub2 (string dummyRequestPath, string dummyPath, string appPath)
160 : base (dummyRequestPath, String.Empty)
166 string path, app_path;
168 public override string ApplicationPath {
169 get { return app_path ?? base.ApplicationPath; }
172 public override string Path {
173 get { return path ?? base.Path; }
177 public class HttpResponseStub : HttpResponseBase
179 public HttpResponseStub ()
186 public HttpResponseStub (int implType)
188 this.impl_type = implType;
191 public override string ApplyAppPathModifier (string virtualPath)
195 return virtualPath; // pass thru
197 return virtualPath + "_modified";
199 throw new ApplicationException (virtualPath);
201 return base.ApplyAppPathModifier (virtualPath);
206 class HttpContextStub3 : HttpContextStub2
208 public HttpContextStub3 (string requestUrl, string path, string appPath, bool supportHandler)
209 : base (requestUrl, path, appPath)
211 this.support_handler = supportHandler;
214 public override void RewritePath (string path)
216 RewrittenPath = path;
219 bool support_handler;
220 public IHttpHandler HttpHandler { get; set; }
222 public override IHttpHandler Handler {
223 get { return support_handler ? HttpHandler : base.Handler; }
228 base.Handler = value;
232 public string RewrittenPath { get; set; }
235 public class MyStopRoutingHandler : StopRoutingHandler
237 public IHttpHandler CallGetHttpHandler (RequestContext rc)
239 return GetHttpHandler (rc);
243 public class MyUrlRoutingHandler : UrlRoutingHandler
245 public void DoProcessRequest (HttpContextBase httpContext)
247 ProcessRequest (httpContext);
250 protected override void VerifyAndProcessRequest (IHttpHandler httpHandler, HttpContextBase httpContext)
252 throw new ApplicationException ("MyUrlRoutingHandler");
256 public class ErrorRouteHandler : IRouteHandler
258 public IHttpHandler GetHttpHandler (RequestContext requestContext)
260 throw new ApplicationException ("ErrorRouteHandler");
264 public class MyRouteHandler : IRouteHandler
266 public MyRouteHandler ()
267 : this (new MyHttpHandler ())
271 public MyRouteHandler (IHttpHandler handler)
273 this.handler = handler;
276 IHttpHandler handler;
278 public IHttpHandler GetHttpHandler (RequestContext requestContext)
284 public class MyHttpHandler : IHttpHandler
286 public bool IsReusable {
290 public void ProcessRequest (HttpContext ctx)
292 throw new MyException ("HOGE");
296 public class MyException : Exception
298 public MyException (string msg) : base (msg) {}
301 public class NullRouteHandler : IRouteHandler
303 public IHttpHandler GetHttpHandler (RequestContext requestContext)
309 public class MyRoute : Route
311 public MyRoute (string url, IRouteHandler handler)
312 : this (url, handler, null)
316 public MyRoute (string url, IRouteHandler handler, Exception ex)
317 : base (url, handler)
324 public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
328 return base.GetVirtualPath (requestContext, values);
331 public bool DoProcessConstraint (HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
333 return ProcessConstraint (httpContext, constraint, parameterName, values, routeDirection);