2 // RouteCollectionTest.cs
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.
32 using System.Web.Routing;
33 using NUnit.Framework;
35 using MonoTests.Common;
37 namespace MonoTests.System.Web.Routing
40 public class RouteCollectionTest
43 public void ConstructorNullArgs ()
46 new RouteCollection (null);
50 public void RouteExistingFiles ()
52 var c = new RouteCollection ();
53 Assert.IsFalse (c.RouteExistingFiles);
57 public void AddNullMame ()
59 var c = new RouteCollection ();
60 // when name is null, no duplicate check is done.
61 c.Add (null, new Route (null, null));
62 c.Add (null, new Route (null, null));
66 public void AddDuplicateEmpty ()
68 var c = new RouteCollection ();
69 // when name is "", no duplicate check is done.
70 c.Add ("", new Route (null, null));
71 c.Add ("", new Route (null, null));
75 [ExpectedException (typeof (ArgumentException))]
76 public void AddDuplicateName ()
78 var c = new RouteCollection ();
79 c.Add ("x", new Route (null, null));
80 c.Add ("x", new Route (null, null));
84 public void IndexForNonExistent ()
86 Assert.IsNull (new RouteCollection () [null]);
90 public void IndexForExistent ()
92 var c = new RouteCollection ();
93 var r = new Route (null, null);
95 Assert.AreEqual (r, c ["x"]);
99 public void IndexForNonExistentAfterRemoval ()
101 var c = new RouteCollection ();
102 var r = new Route (null, null);
105 Assert.IsNull(c ["x"]);
109 [ExpectedException (typeof (ArgumentException))]
110 public void GetRouteDataNoRequest ()
112 new RouteCollection ().GetRouteData (new HttpContextStub (true));
116 [ExpectedException (typeof (ArgumentNullException))]
117 public void GetRouteDataNullArg ()
119 new RouteCollection ().GetRouteData (null);
123 public void GetRouteDataForNonExistent ()
125 var rd = new RouteCollection ().GetRouteData (new HttpContextStub ("~/foo"));
130 public void GetRouteDataForNonExistent2 ()
132 var rd = new RouteCollection () { RouteExistingFiles = true }.GetRouteData (new HttpContextStub2 (null, null, null));
133 Assert.IsNull (rd, "#A1");
135 rd = new RouteCollection ().GetRouteData (new HttpContextStub2 (null, null, null));
136 Assert.IsNull (rd, "#A2");
139 new RouteCollection ().GetRouteData (new HttpContextStub2 (null, null, null));
141 } catch (NotImplementedException) {
142 // it should fail due to the NIE on AppRelativeCurrentExecutionFilePath.
148 public void GetRouteDataWrongPathNoRoute ()
150 new RouteCollection ().GetRouteData (new HttpContextStub (String.Empty, String.Empty));
154 comment out those tests; I cannot explain those tests.
157 [ExpectedException (typeof (ArgumentOutOfRangeException))]
158 public void GetRouteDataWrongPathOneRoute ()
160 var c = new RouteCollection ();
161 var r = new Route ("foo", null);
163 // it somehow causes ArgumentOutOfRangeException for
164 // Request.AppRelativeCurrentExecutionFilePath.
165 c.GetRouteData (new HttpContextStub (String.Empty, String.Empty));
169 public void GetRouteDataWrongPathOneRoute2 ()
171 var c = new RouteCollection ();
172 var r = new Route ("foo", null);
174 c.GetRouteData (new HttpContextStub ("/~", String.Empty));
179 [ExpectedException (typeof (NotImplementedException))]
180 public void GetRouteDataForPathInfoNIE ()
182 var c = new RouteCollection ();
183 var r = new Route ("foo", null);
185 // it retrieves PathInfo and then dies.
186 var rd = c.GetRouteData (new HttpContextStub ("~/foo"));
190 public void GetRouteDataForNullHandler ()
192 var c = new RouteCollection ();
193 var r = new Route ("foo", null); // allowed
195 var rd = c.GetRouteData (new HttpContextStub ("~/foo", String.Empty));
196 Assert.IsNotNull (rd, "#1");
197 Assert.AreEqual (r, rd.Route, "#2");
200 // below tests in RouteCollection, unlike Route, do some additional checks than Route.GetVirtualPath().
203 [ExpectedException (typeof (NotImplementedException))]
204 public void GetVirtualPathNoApplicationPath ()
206 var c = new RouteCollection ();
207 c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
208 var hc = new HttpContextStub2 ("~/x/y", String.Empty);
209 var rd = c.GetRouteData (hc);
210 // it tries to get HttpContextBase.Request.ApplicationPath and then throws NIE.
211 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
215 [ExpectedException (typeof (NotImplementedException))]
216 public void GetVirtualPathNoApplyAppPathModifier ()
218 var c = new RouteCollection ();
219 c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
220 var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
221 // it tries to call HttpContextBase.Response.ApplyAppPathModifier() and then causes NIE.
222 hc.SetResponse (new HttpResponseStub ());
223 var rd = c.GetRouteData (hc);
224 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
228 public void GetVirtualPathCheckVirtualPathToModify ()
230 var c = new RouteCollection ();
231 c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
232 var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
233 // it tries to get HttpContextBase.Response, so set it.
234 hc.SetResponse (new HttpResponseStub (1));
235 var rd = c.GetRouteData (hc);
237 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
239 } catch (ApplicationException ex) {
240 Assert.AreEqual ("apppath/x/y", ex.Message, "#2");
245 public void GetVirtualPath ()
247 var c = new RouteCollection ();
248 c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
249 var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
250 // it tries to get HttpContextBase.Response, so set it.
251 hc.SetResponse (new HttpResponseStub (2));
252 var rd = c.GetRouteData (hc);
253 Assert.IsNotNull (rd, "#1");
255 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
256 Assert.IsNotNull (vpd, "#2");
257 Assert.AreEqual ("apppath/x/y_modified", vpd.VirtualPath, "#3");
258 Assert.AreEqual (0, vpd.DataTokens.Count, "#4");
261 [Test (Description = "Bug #502555")]
262 public void GetVirtualPath2 ()
264 var c = new RouteCollection ();
267 new MyRoute ("summary/{action}-{type}/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Summary", action = "Index", page = 1}) }
271 new MyRoute ("apis/{apiname}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Apis", action = "Index" }) }
274 c.Add ("Single Report",
275 new MyRoute ("report/{guid}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "SingleReport" }) }
279 new MyRoute ("reports/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "Index", page = 1 }) }
283 new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index"}) }
286 var hc = new HttpContextStub2 ("~/Home/About", String.Empty, String.Empty);
287 hc.SetResponse (new HttpResponseStub (2));
288 var rd = c.GetRouteData (hc);
289 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
290 Assert.IsNotNull (vpd, "#A1");
291 Assert.AreEqual ("/Home/About_modified", vpd.VirtualPath, "#A2");
292 Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");
294 hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
295 hc.SetResponse (new HttpResponseStub (2));
296 rd = c.GetRouteData (hc);
297 vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
298 Assert.IsNotNull (vpd, "#B1");
299 Assert.AreEqual ("/_modified", vpd.VirtualPath, "#B2");
300 Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");
302 hc = new HttpContextStub2 ("~/Account/LogOn", String.Empty, String.Empty);
303 hc.SetResponse (new HttpResponseStub (2));
304 rd = c.GetRouteData (hc);
305 vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
306 Assert.IsNotNull (vpd, "#C1");
307 Assert.AreEqual ("/Account/LogOn_modified", vpd.VirtualPath, "#C2");
308 Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");
310 hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
311 hc.SetResponse (new HttpResponseStub (3));
312 rd = c.GetRouteData (hc);
313 vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }) );
314 Assert.IsNotNull (vpd, "#D1");
315 Assert.AreEqual ("/", vpd.VirtualPath, "#D2");
316 Assert.AreEqual (0, vpd.DataTokens.Count, "#D3");
318 hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
319 hc.SetResponse (new HttpResponseStub (3));
320 rd = c.GetRouteData (hc);
321 vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "Home" }) );
322 Assert.IsNotNull (vpd, "#E1");
323 Assert.AreEqual ("/", vpd.VirtualPath, "#E2");
324 Assert.AreEqual (0, vpd.DataTokens.Count, "#E3");
328 public void GetVirtualPath3 ()
330 var c = new RouteCollection ();
333 new MyRoute ("todo/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "todo", action="list", page=0}) }
336 c.Add ("another-route",
337 new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "home", action="list", page=0}) }
340 var hc = new HttpContextStub2 ("~/home/list", String.Empty, String.Empty);
341 hc.SetResponse (new HttpResponseStub (3));
342 var rd = c.GetRouteData (hc);
343 Assert.IsNotNull (rd, "#1");
344 Assert.AreEqual (3, rd.Values.Count, "#1-1");
345 Assert.AreEqual ("home", rd.Values["controller"], "#1-2");
346 Assert.AreEqual ("list", rd.Values["action"], "#1-3");
347 Assert.AreEqual (0, rd.Values["page"], "#1-4");
349 var vp = c.GetVirtualPath (new RequestContext (hc, rd), "todo-route", new RouteValueDictionary ());
350 Assert.IsNotNull (vp, "#2");
351 Assert.AreEqual ("/todo", vp.VirtualPath, "#2-1");
353 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary ());
354 Assert.IsNotNull (vp, "#3");
355 Assert.AreEqual ("/todo", vp.VirtualPath, "#3-1");
357 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }));
358 Assert.IsNotNull (vp, "#4");
359 Assert.AreEqual ("/", vp.VirtualPath, "#4-1");
361 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home", extra="stuff" }));
362 Assert.IsNotNull (vp, "#5");
363 Assert.AreEqual ("/?extra=stuff", vp.VirtualPath, "#5-1");
367 public void GetVirtualPath4 ()
369 var c = new RouteCollection ();
371 c.Add (new MyRoute ("blog/{user}/{action}", new MyRouteHandler ()) {
372 Defaults = new RouteValueDictionary {
373 { "controller", "blog" },
379 c.Add (new MyRoute ("forum/{user}/{action}", new MyRouteHandler ()) {
380 Defaults = new RouteValueDictionary {
381 { "controller", "forum" },
387 var hc = new HttpContextStub2 ("~/forum/admin/Index", String.Empty, String.Empty);
388 hc.SetResponse (new HttpResponseStub (3));
389 var rd = c.GetRouteData (hc);
390 Assert.IsNotNull (rd, "#1");
392 var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="forum"}));
393 Assert.IsNotNull (vp, "#2");
394 Assert.AreEqual ("/forum/admin/Index", vp.VirtualPath, "#2-1");
396 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="blah"}));
397 Assert.IsNull (vp, "#3");
401 public void GetVirtualPath5 ()
403 var c = new RouteCollection ();
405 c.Add (new MyRoute ("reports/{year}/{month}/{day}", new MyRouteHandler ()) {
406 Defaults = new RouteValueDictionary {
412 var hc = new HttpContextStub2 ("~/reports/2009/05", String.Empty, String.Empty);
413 hc.SetResponse (new HttpResponseStub (3));
414 var rd = c.GetRouteData (hc);
415 Assert.IsNotNull (rd, "#1");
417 var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
423 Assert.IsNotNull (vp, "#2");
424 Assert.AreEqual ("/reports/2007/1/12", vp.VirtualPath, "#2-1");
426 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
431 Assert.IsNotNull (vp, "#3");
432 Assert.AreEqual ("/reports/2007/1", vp.VirtualPath, "#3-1");
434 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
441 Assert.IsNotNull (vp, "#4");
442 Assert.AreEqual ("/reports/2007/1/12?category=123", vp.VirtualPath, "#4-1");
444 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
448 Assert.IsNull (vp, "#5");
452 public void GetVirtualPath6 ()
454 var c = new RouteCollection ();
456 c.Add (new MyRoute ("reports/{year}/{month}/{day}", new MyRouteHandler ()) {
457 Defaults = new RouteValueDictionary {
463 var hc = new HttpContextStub2 ("~/reports/2009/05", String.Empty, "/myapp");
464 hc.SetResponse (new HttpResponseStub (3));
465 var rd = c.GetRouteData (hc);
466 Assert.IsNotNull (rd, "#1");
468 var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
474 Assert.IsNotNull (vp, "#2");
475 Assert.AreEqual ("/myapp/reports/2007/1/12", vp.VirtualPath, "#2-1");
477 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
482 Assert.IsNotNull (vp, "#3");
483 Assert.AreEqual ("/myapp/reports/2007/1", vp.VirtualPath, "#3-1");
485 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
492 Assert.IsNotNull (vp, "#4");
493 Assert.AreEqual ("/myapp/reports/2007/1/12?category=123", vp.VirtualPath, "#4-1");
495 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
499 Assert.IsNull (vp, "#5");
503 public void GetVirtualPath7 ()
505 var c = new RouteCollection ();
507 c.Add (new MyRoute ("{table}/{action}.aspx", new MyRouteHandler ()) {
508 Constraints = new RouteValueDictionary (new { action = "List|Details|Edit|Insert" }),
511 var req = new FakeHttpWorkerRequest ();
512 var ctx = new HttpContext (req);
513 HttpContext.Current = ctx;
514 var rd = new RouteData ();
515 var hc = new HttpContextWrapper (ctx);
517 var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
518 {"Table", "FooTable"},
519 {"Action", "Details"}
522 Assert.IsNotNull (vp, "#A1");
523 Assert.AreEqual ("/FooTable/Details.aspx", vp.VirtualPath, "#A1-1");
525 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
526 {"Table", "FooTable"},
527 {"Action", String.Empty}
530 Assert.IsNull (vp, "#B1");
532 vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
533 {"Table", "FooTable"},
537 Assert.IsNull (vp, "#C1");
541 public void GetVirtualPath8 ()
543 var routes = new RouteCollection();
545 routes.Add (new MyRoute ("login", new MyRouteHandler ()) {
546 Defaults = new RouteValueDictionary (new { controller = "Home", action = "LogOn" })
549 routes.Add (new MyRoute ("{site}/{controller}/{action}", new MyRouteHandler ()) {
550 Defaults = new RouteValueDictionary (new { site = "_", controller = "Home", action = "Index" }),
551 Constraints = new RouteValueDictionary ( new { site = "_?[0-9A-Za-z-]*" })
554 routes.Add (new MyRoute ("{*path}", new MyRouteHandler ()) {
555 Defaults = new RouteValueDictionary (new { controller = "Error", action = "NotFound" }),
558 var hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
559 hc.SetResponse (new HttpResponseStub (3));
560 var rd = routes.GetRouteData (hc);
561 var rvs = new RouteValueDictionary () {
562 { "controller", "Home" },
563 { "action" , "Index" }
565 var vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
566 Assert.IsNotNull (vpd, "#A1");
567 Assert.AreEqual ("/", vpd.VirtualPath, "#A2");
568 Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");
570 hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
571 hc.SetResponse (new HttpResponseStub (3));
572 rd = routes.GetRouteData (hc);
573 rvs = new RouteValueDictionary () {
574 { "controller", "Home" }
576 vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
577 Assert.IsNotNull (vpd, "#B1");
578 Assert.AreEqual ("/login", vpd.VirtualPath, "#B2");
579 Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");
581 hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
582 hc.SetResponse (new HttpResponseStub (3));
583 rd = routes.GetRouteData (hc);
584 rvs = new RouteValueDictionary () {
585 { "action" , "Index" }
587 vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
588 Assert.IsNotNull (vpd, "#C1");
589 Assert.AreEqual ("/", vpd.VirtualPath, "#C2");
590 Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");
592 hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
593 rd = routes.GetRouteData (hc);
594 Assert.IsNotNull (rd, "#D1");
598 [Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
599 public void GetVirtualPathToExistingFile ()
601 var c = new RouteCollection ();
602 c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
603 var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
604 // it tries to get HttpContextBase.Response, so set it.
605 hc.SetResponse (new HttpResponseStub (3));
606 var rd = c.GetRouteData (hc);
607 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
608 Assert.AreEqual ("./Test/test.html", vpd.VirtualPath, "#1");
609 Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
612 [Test (Description="Routes from NerdDinner")]
613 public void GetRouteDataNerdDinner ()
615 var c = new RouteCollection ();
617 c.Add ("UpcomingDiners",
618 new MyRoute ("Dinners/Page/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Dinners", action = "Index" }) }
622 new MyRoute ("{controller}/{action}/{id}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index", id = "" })}
625 var hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
626 hc.SetResponse (new HttpResponseStub (3));
627 var rd = c.GetRouteData (hc);
629 Assert.IsNotNull (rd, "#A1");
632 [Test (Description="Routes from NerdDinner")]
633 public void GetRouteDataNerdDinner2 ()
635 var c = new RouteCollection ();
637 c.Add ("UpcomingDiners",
638 new MyRoute ("Dinners/Page/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Dinners", action = "Index" }) }
642 new MyRoute ("{controller}/{action}/{id}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index", id = "" })}
645 var hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
646 hc.SetResponse (new HttpResponseStub (3));
647 var rd = c.GetRouteData (hc);
649 Assert.IsNotNull (rd, "#A1");
653 public void Ignore_String ()
655 var c = new RouteCollection ();
657 AssertExtensions.Throws<ArgumentNullException> (() => {
661 c.Ignore ("{resource}.axd/{*pathInfo}");
662 var hc = new HttpContextStub2 ("~/something.axd/pathinfo", String.Empty, String.Empty);
663 hc.SetResponse (new HttpResponseStub (3));
664 var rd = c.GetRouteData (hc);
666 Assert.IsNotNull (rd, "#A1-1");
667 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
668 Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
669 Assert.IsTrue (rd.Route is Route, "#A1-4");
670 Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
671 Assert.AreEqual (0, ((Route) rd.Route).Constraints.Count, "#A1-6");
675 public void Ignore_String_Object ()
677 var c = new RouteCollection ();
679 AssertExtensions.Throws<ArgumentNullException> (() => {
680 c.Ignore (null, new { allaspx = @".*\.aspx(/.*)?" });
683 c.Ignore ("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
684 var hc = new HttpContextStub2 ("~/page.aspx", String.Empty, String.Empty);
685 hc.SetResponse (new HttpResponseStub (3));
686 var rd = c.GetRouteData (hc);
688 Assert.IsNotNull (rd, "#A1-1");
689 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
690 Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
691 Assert.IsTrue (rd.Route is Route, "#A1-4");
692 Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
693 Assert.AreEqual (1, ((Route) rd.Route).Constraints.Count, "#A1-6");
694 Assert.AreEqual (@".*\.aspx(/.*)?", ((Route) rd.Route).Constraints ["allaspx"], "#A1-7");
696 c = new RouteCollection ();
697 c.Ignore ("{*allaspx}", "something invalid");
699 AssertExtensions.Throws<InvalidOperationException> (() => {
700 rd = c.GetRouteData (hc);
705 public void MapPageRoute_String_String_String ()
707 var c = new RouteCollection ();
709 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url");
710 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
711 hc.SetResponse (new HttpResponseStub (3));
712 var rd = c.GetRouteData (hc);
714 Assert.IsNotNull (rd, "#A1-1");
715 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
716 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
718 c = new RouteCollection ();
719 AssertExtensions.Throws<ArgumentNullException> (() => {
720 c.MapPageRoute ("RouteName", null, "~/some-url");
723 c = new RouteCollection ();
724 c.MapPageRoute ("RouteName", String.Empty, "~/some-url");
725 rd = c.GetRouteData (hc);
727 Assert.IsNull (rd, "#A2");
729 c = new RouteCollection ();
730 // thrown by PageRouteHandler's constructor
731 AssertExtensions.Throws<ArgumentException> (() => {
732 c.MapPageRoute ("RouteName", "~/some-url", null);
737 public void MapPageRoute_String_String_String_Bool ()
739 var c = new RouteCollection ();
741 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true);
742 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
743 hc.SetResponse (new HttpResponseStub (3));
744 var rd = c.GetRouteData (hc);
746 Assert.IsNotNull (rd, "#A1-1");
747 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
748 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
749 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
751 c = new RouteCollection ();
752 AssertExtensions.Throws<ArgumentNullException> (() => {
753 c.MapPageRoute ("RouteName", null, "~/some-url", true);
756 c = new RouteCollection ();
757 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true);
758 rd = c.GetRouteData (hc);
760 Assert.IsNull (rd, "#A2");
762 c = new RouteCollection ();
763 // thrown by PageRouteHandler's constructor
764 AssertExtensions.Throws<ArgumentException> (() => {
765 c.MapPageRoute ("RouteName", "~/some-url", null, true);
768 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false);
769 rd = c.GetRouteData (hc);
771 Assert.IsNotNull (rd, "#A4-1");
772 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
773 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
774 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
778 public void MapPageRoute_String_String_String_Bool_RVD ()
780 var c = new RouteCollection ();
781 var defaults = new RouteValueDictionary ();
783 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults);
784 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
785 hc.SetResponse (new HttpResponseStub (3));
786 var rd = c.GetRouteData (hc);
788 Assert.IsNotNull (rd, "#A1-1");
789 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
790 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
791 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
793 c = new RouteCollection ();
794 AssertExtensions.Throws<ArgumentNullException> (() => {
795 c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults);
798 c = new RouteCollection ();
799 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults);
800 rd = c.GetRouteData (hc);
802 Assert.IsNull (rd, "#A2");
804 c = new RouteCollection ();
805 // thrown by PageRouteHandler's constructor
806 AssertExtensions.Throws<ArgumentException> (() => {
807 c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults);
810 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults);
811 rd = c.GetRouteData (hc);
813 Assert.IsNotNull (rd, "#A4-1");
814 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
815 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
816 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
818 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null);
819 rd = c.GetRouteData (hc);
821 Assert.IsNotNull (rd, "#A4-1");
822 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
823 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
824 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
828 public void MapPageRoute_String_String_String_Bool_RVD_RVD ()
830 var c = new RouteCollection ();
831 var defaults = new RouteValueDictionary ();
832 var constraints = new RouteValueDictionary ();
834 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults, constraints);
835 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
836 hc.SetResponse (new HttpResponseStub (3));
837 var rd = c.GetRouteData (hc);
839 Assert.IsNotNull (rd, "#A1-1");
840 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
841 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
842 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
844 c = new RouteCollection ();
845 AssertExtensions.Throws<ArgumentNullException> (() => {
846 c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults, constraints);
849 c = new RouteCollection ();
850 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults, constraints);
851 rd = c.GetRouteData (hc);
853 Assert.IsNull (rd, "#A2");
855 c = new RouteCollection ();
856 // thrown by PageRouteHandler's constructor
857 AssertExtensions.Throws<ArgumentException> (() => {
858 c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults, constraints);
861 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults, constraints);
862 rd = c.GetRouteData (hc);
864 Assert.IsNotNull (rd, "#A4-1");
865 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
866 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
867 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
869 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null, constraints);
870 rd = c.GetRouteData (hc);
872 Assert.IsNotNull (rd, "#A4-1");
873 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
874 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
875 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
879 public void MapPageRoute_String_String_String_Bool_RVD_RVD_RVD ()
881 var c = new RouteCollection ();
882 var defaults = new RouteValueDictionary ();
883 var constraints = new RouteValueDictionary ();
884 var dataTokens = new RouteValueDictionary ();
886 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults, constraints, dataTokens);
887 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
888 hc.SetResponse (new HttpResponseStub (3));
889 var rd = c.GetRouteData (hc);
891 Assert.IsNotNull (rd, "#A1-1");
892 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
893 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
894 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
896 c = new RouteCollection ();
897 AssertExtensions.Throws<ArgumentNullException> (() => {
898 c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults, constraints, dataTokens);
901 c = new RouteCollection ();
902 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults, constraints, dataTokens);
903 rd = c.GetRouteData (hc);
905 Assert.IsNull (rd, "#A2");
907 c = new RouteCollection ();
908 // thrown by PageRouteHandler's constructor
909 AssertExtensions.Throws<ArgumentException> (() => {
910 c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults, constraints, dataTokens);
913 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults, constraints, dataTokens);
914 rd = c.GetRouteData (hc);
916 Assert.IsNotNull (rd, "#A4-1");
917 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
918 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
919 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
921 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null, constraints, dataTokens);
922 rd = c.GetRouteData (hc);
924 Assert.IsNotNull (rd, "#A4-1");
925 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
926 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
927 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");