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;
32 using System.Collections.Generic;
33 using System.Collections.ObjectModel;
34 using System.Collections.Specialized;
35 using System.ComponentModel.DataAnnotations;
36 using System.Data.SqlClient;
37 using System.Data.Linq;
38 using System.Data.Linq.Mapping;
39 using System.Globalization;
40 using System.Reflection;
41 using System.Security.Permissions;
42 using System.Security.Principal;
45 using System.Web.DynamicData;
46 using System.Web.DynamicData.ModelProviders;
47 using System.Web.Routing;
49 using MetaModel = System.Web.DynamicData.MetaModel;
50 using MetaTable = System.Web.DynamicData.MetaTable;
52 using NUnit.Framework;
53 using MonoTests.DataSource;
55 namespace MonoTests.System.Web.DynamicData
57 class MyDynamicDataRoute : DynamicDataRoute
59 public RouteValueDictionary GetVirtualPathValues {
68 public MyDynamicDataRoute (string url)
72 public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
74 GetVirtualPathValues = values;
76 return base.GetVirtualPath (requestContext, values);
80 class MyDynamicDataRouteHandler : DynamicDataRouteHandler
82 public override IHttpHandler CreateHandler (DynamicDataRoute route, MetaTable table, string action)
84 return new Page () as IHttpHandler;
88 class MyDataContext1 : DataContext
90 public MyDataContext1 ()
91 : base (new SqlConnection ("Data Source=localhost"))
96 [Database (Name = "MyDB1")]
97 class MyDataContext2 : DataContext
99 public MyDataContext2 ()
100 : base (new SqlConnection ("Data Source=localhost"))
104 public Table<Foo> FooTable { get { return GetTable<Foo> (); } }
107 class MyDataContext3 : MyDataContext2
111 class UseOnlyInGetModelTestDataContext : MyDataContext2
115 [Table (Name = "dbo...FooTable")]
118 public Foo () : this (false)
122 public Foo (bool noThrow)
125 throw new Exception ("ERROR");
128 [Column (Name = "Col1")]
129 public string Column1 { get; set; }
132 [Table (Name = "BarTable")]
135 [Column (Name = "Col1")]
136 public string Column1 { get; set; }
138 [Column (Name = "Col2")]
139 public string Column2 { get; set; }
142 class HttpContextStub : HttpContextBase
146 public HttpContextStub ()
151 public HttpContextStub (string dummyRequestPath)
152 : this (dummyRequestPath, null)
156 public HttpContextStub (string dummyRequestPath, string pathInfo)
157 : this (dummyRequestPath, pathInfo, null)
161 public HttpContextStub (string dummyRequestPath, string pathInfo, string method)
163 if (dummyRequestPath != null) {
164 req = new HttpRequestStub (dummyRequestPath, pathInfo);
169 public override HttpRequestBase Request {
170 get { return req != null ? req : base.Request; }
174 class HttpRequestStub : HttpRequestBase
176 public HttpRequestStub (string dummyRequestPath, string pathInfo)
178 req_path = dummyRequestPath;
179 path_info = pathInfo;
182 string req_path, path_info;
183 NameValueCollection query_string = new NameValueCollection ();
185 public override string AppRelativeCurrentExecutionFilePath {
186 get { return req_path ?? base.AppRelativeCurrentExecutionFilePath; }
189 public override string PathInfo {
190 get { return path_info ?? base.PathInfo; }
193 public override NameValueCollection QueryString {
194 get { return query_string; }
197 public override string HttpMethod {
198 get { return Method; }
201 public string Method { get; set; }
204 class MyDictionary : Hashtable
206 public override ICollection Keys {
210 public override object this [object key] {
212 //Console.Error.WriteLine ("Get: {0} {1}", key, key.GetHashCode ());
216 //Console.Error.WriteLine ("Set: {0} {1} = {2}", key, key.GetHashCode (), value);
222 class HttpContextStub2 : HttpContextBase
224 public HttpContextStub2 ()
229 public HttpContextStub2 (string requestUrl, string path)
230 : this (requestUrl, path, null)
234 public HttpContextStub2 (string requestUrl, string path, string appPath)
236 request = new HttpRequestStub2 (requestUrl, path, appPath);
239 Hashtable items = new MyDictionary ();
240 HttpRequestStub request;
241 HttpResponseBase response;
243 public override IDictionary Items {
244 get { return items; }
247 public override HttpRequestBase Request {
248 get { return request ?? base.Request; }
251 public override HttpResponseBase Response {
252 get { return response ?? base.Response; }
255 public override void RewritePath (string path)
257 throw new ApplicationException (path);
260 public void SetResponse (HttpResponseBase response)
262 this.response = response;
266 class HttpRequestStub2 : HttpRequestStub
268 public HttpRequestStub2 (string dummyRequestPath, string dummyPath, string appPath)
269 : base (dummyRequestPath, String.Empty)
275 string path, app_path;
277 public override string ApplicationPath {
278 get { return app_path ?? base.ApplicationPath; }
281 public override string Path {
282 get { return path ?? base.Path; }
286 public class HttpResponseStub : HttpResponseBase
288 public HttpResponseStub ()
295 public HttpResponseStub (int implType)
297 this.impl_type = implType;
300 public override string ApplyAppPathModifier (string virtualPath)
304 return virtualPath; // pass thru
306 return virtualPath + "_modified";
308 throw new ApplicationException (virtualPath);
310 return base.ApplyAppPathModifier (virtualPath);
315 class HttpContextStub3 : HttpContextStub2
317 public HttpContextStub3 (string requestUrl, string path, string appPath, bool supportHandler)
318 : base (requestUrl, path, appPath)
320 this.support_handler = supportHandler;
323 public override void RewritePath (string path)
325 RewrittenPath = path;
328 bool support_handler;
329 public IHttpHandler HttpHandler { get; set; }
331 public override IHttpHandler Handler {
332 get { return support_handler ? HttpHandler : base.Handler; }
337 base.Handler = value;
341 public string RewrittenPath { get; set; }
344 public class MyStopRoutingHandler : StopRoutingHandler
346 public IHttpHandler CallGetHttpHandler (RequestContext rc)
348 return GetHttpHandler (rc);
352 public class MyUrlRoutingHandler : UrlRoutingHandler
354 public void DoProcessRequest (HttpContextBase httpContext)
356 ProcessRequest (httpContext);
359 protected override void VerifyAndProcessRequest (IHttpHandler httpHandler, HttpContextBase httpContext)
361 throw new ApplicationException ("MyUrlRoutingHandler");
365 public class ErrorRouteHandler : IRouteHandler
367 public IHttpHandler GetHttpHandler (RequestContext requestContext)
369 throw new ApplicationException ("ErrorRouteHandler");
373 public class MyRouteHandler : IRouteHandler
375 public MyRouteHandler ()
376 : this (new MyHttpHandler ())
380 public MyRouteHandler (IHttpHandler handler)
382 this.handler = handler;
385 IHttpHandler handler;
387 public IHttpHandler GetHttpHandler (RequestContext requestContext)
393 public class MyHttpHandler : IHttpHandler
395 public bool IsReusable {
399 public void ProcessRequest (HttpContext ctx)
401 throw new MyException ("HOGE");
405 public class MyException : Exception
407 public MyException (string msg) : base (msg) {}
410 public class NullRouteHandler : IRouteHandler
412 public IHttpHandler GetHttpHandler (RequestContext requestContext)
418 public class MyRoute : Route
420 public MyRoute (string url, IRouteHandler handler)
421 : this (url, handler, null)
425 public MyRoute (string url, IRouteHandler handler, Exception ex)
426 : base (url, handler)
433 public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
437 return base.GetVirtualPath (requestContext, values);
441 class MyHttpWorkerRequest : HttpWorkerRequest
443 public override void EndOfRequest ()
445 throw new NotImplementedException ();
448 public override void FlushResponse (bool b)
450 throw new NotImplementedException ();
453 public override string GetHttpVerbName ()
455 throw new NotImplementedException ();
458 public override string GetHttpVersion ()
460 throw new NotImplementedException ();
463 public override string GetLocalAddress ()
465 throw new NotImplementedException ();
468 public override int GetLocalPort ()
470 throw new NotImplementedException ();
473 public override string GetQueryString ()
475 throw new NotImplementedException ();
478 public override string GetRawUrl ()
480 throw new NotImplementedException ();
483 public override string GetRemoteAddress ()
485 throw new NotImplementedException ();
488 public override int GetRemotePort ()
490 throw new NotImplementedException ();
493 public override string GetUriPath ()
498 public override void SendKnownResponseHeader (int idx, string v)
500 throw new NotImplementedException ();
503 public override void SendResponseFromFile (IntPtr file, long offset, long len)
505 throw new NotImplementedException ();
508 public override void SendResponseFromFile (string name, long offset, long len)
510 throw new NotImplementedException ();
513 public override void SendResponseFromMemory (byte[] buf, int index)
515 throw new NotImplementedException ();
518 public override void SendStatus (int i, string s)
520 throw new NotImplementedException ();
523 public override void SendUnknownResponseHeader (string n, string v)
525 throw new NotImplementedException ();