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 [Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
542 public void GetVirtualPathToExistingFile ()
544 var c = new RouteCollection ();
545 c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
546 var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
547 // it tries to get HttpContextBase.Response, so set it.
548 hc.SetResponse (new HttpResponseStub (3));
549 var rd = c.GetRouteData (hc);
550 var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
551 Assert.AreEqual ("./Test/test.html", vpd.VirtualPath, "#1");
552 Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
555 [Test (Description="Routes from NerdDinner")]
556 public void GetRouteDataNerdDinner ()
558 var c = new RouteCollection ();
560 c.Add ("UpcomingDiners",
561 new MyRoute ("Dinners/Page/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Dinners", action = "Index" }) }
565 new MyRoute ("{controller}/{action}/{id}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index", id = "" })}
568 var hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
569 hc.SetResponse (new HttpResponseStub (3));
570 var rd = c.GetRouteData (hc);
572 Assert.IsNotNull (rd, "#A1");
575 [Test (Description="Routes from NerdDinner")]
576 public void GetRouteDataNerdDinner2 ()
578 var c = new RouteCollection ();
580 c.Add ("UpcomingDiners",
581 new MyRoute ("Dinners/Page/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Dinners", action = "Index" }) }
585 new MyRoute ("{controller}/{action}/{id}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index", id = "" })}
588 var hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
589 hc.SetResponse (new HttpResponseStub (3));
590 var rd = c.GetRouteData (hc);
592 Assert.IsNotNull (rd, "#A1");
596 public void Ignore_String ()
598 var c = new RouteCollection ();
600 AssertExtensions.Throws<ArgumentNullException> (() => {
604 c.Ignore ("{resource}.axd/{*pathInfo}");
605 var hc = new HttpContextStub2 ("~/something.axd/pathinfo", String.Empty, String.Empty);
606 hc.SetResponse (new HttpResponseStub (3));
607 var rd = c.GetRouteData (hc);
609 Assert.IsNotNull (rd, "#A1-1");
610 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
611 Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
612 Assert.IsTrue (rd.Route is Route, "#A1-4");
613 Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
614 Assert.AreEqual (0, ((Route) rd.Route).Constraints.Count, "#A1-6");
618 public void Ignore_String_Object ()
620 var c = new RouteCollection ();
622 AssertExtensions.Throws<ArgumentNullException> (() => {
623 c.Ignore (null, new { allaspx = @".*\.aspx(/.*)?" });
626 c.Ignore ("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
627 var hc = new HttpContextStub2 ("~/page.aspx", String.Empty, String.Empty);
628 hc.SetResponse (new HttpResponseStub (3));
629 var rd = c.GetRouteData (hc);
631 Assert.IsNotNull (rd, "#A1-1");
632 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
633 Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
634 Assert.IsTrue (rd.Route is Route, "#A1-4");
635 Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
636 Assert.AreEqual (1, ((Route) rd.Route).Constraints.Count, "#A1-6");
637 Assert.AreEqual (@".*\.aspx(/.*)?", ((Route) rd.Route).Constraints ["allaspx"], "#A1-7");
639 c = new RouteCollection ();
640 c.Ignore ("{*allaspx}", "something invalid");
642 AssertExtensions.Throws<InvalidOperationException> (() => {
643 rd = c.GetRouteData (hc);
648 public void MapPageRoute_String_String_String ()
650 var c = new RouteCollection ();
652 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url");
653 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
654 hc.SetResponse (new HttpResponseStub (3));
655 var rd = c.GetRouteData (hc);
657 Assert.IsNotNull (rd, "#A1-1");
658 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
659 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
661 c = new RouteCollection ();
662 AssertExtensions.Throws<ArgumentNullException> (() => {
663 c.MapPageRoute ("RouteName", null, "~/some-url");
666 c = new RouteCollection ();
667 c.MapPageRoute ("RouteName", String.Empty, "~/some-url");
668 rd = c.GetRouteData (hc);
670 Assert.IsNull (rd, "#A2");
672 c = new RouteCollection ();
673 // thrown by PageRouteHandler's constructor
674 AssertExtensions.Throws<ArgumentException> (() => {
675 c.MapPageRoute ("RouteName", "~/some-url", null);
680 public void MapPageRoute_String_String_String_Bool ()
682 var c = new RouteCollection ();
684 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true);
685 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
686 hc.SetResponse (new HttpResponseStub (3));
687 var rd = c.GetRouteData (hc);
689 Assert.IsNotNull (rd, "#A1-1");
690 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
691 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
692 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
694 c = new RouteCollection ();
695 AssertExtensions.Throws<ArgumentNullException> (() => {
696 c.MapPageRoute ("RouteName", null, "~/some-url", true);
699 c = new RouteCollection ();
700 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true);
701 rd = c.GetRouteData (hc);
703 Assert.IsNull (rd, "#A2");
705 c = new RouteCollection ();
706 // thrown by PageRouteHandler's constructor
707 AssertExtensions.Throws<ArgumentException> (() => {
708 c.MapPageRoute ("RouteName", "~/some-url", null, true);
711 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false);
712 rd = c.GetRouteData (hc);
714 Assert.IsNotNull (rd, "#A4-1");
715 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
716 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
717 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
721 public void MapPageRoute_String_String_String_Bool_RVD ()
723 var c = new RouteCollection ();
724 var defaults = new RouteValueDictionary ();
726 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults);
727 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
728 hc.SetResponse (new HttpResponseStub (3));
729 var rd = c.GetRouteData (hc);
731 Assert.IsNotNull (rd, "#A1-1");
732 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
733 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
734 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
736 c = new RouteCollection ();
737 AssertExtensions.Throws<ArgumentNullException> (() => {
738 c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults);
741 c = new RouteCollection ();
742 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults);
743 rd = c.GetRouteData (hc);
745 Assert.IsNull (rd, "#A2");
747 c = new RouteCollection ();
748 // thrown by PageRouteHandler's constructor
749 AssertExtensions.Throws<ArgumentException> (() => {
750 c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults);
753 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults);
754 rd = c.GetRouteData (hc);
756 Assert.IsNotNull (rd, "#A4-1");
757 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
758 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
759 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
761 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null);
762 rd = c.GetRouteData (hc);
764 Assert.IsNotNull (rd, "#A4-1");
765 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
766 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
767 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
771 public void MapPageRoute_String_String_String_Bool_RVD_RVD ()
773 var c = new RouteCollection ();
774 var defaults = new RouteValueDictionary ();
775 var constraints = new RouteValueDictionary ();
777 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults, constraints);
778 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
779 hc.SetResponse (new HttpResponseStub (3));
780 var rd = c.GetRouteData (hc);
782 Assert.IsNotNull (rd, "#A1-1");
783 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
784 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
785 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
787 c = new RouteCollection ();
788 AssertExtensions.Throws<ArgumentNullException> (() => {
789 c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults, constraints);
792 c = new RouteCollection ();
793 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults, constraints);
794 rd = c.GetRouteData (hc);
796 Assert.IsNull (rd, "#A2");
798 c = new RouteCollection ();
799 // thrown by PageRouteHandler's constructor
800 AssertExtensions.Throws<ArgumentException> (() => {
801 c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults, constraints);
804 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults, constraints);
805 rd = c.GetRouteData (hc);
807 Assert.IsNotNull (rd, "#A4-1");
808 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
809 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
810 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
812 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null, constraints);
813 rd = c.GetRouteData (hc);
815 Assert.IsNotNull (rd, "#A4-1");
816 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
817 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
818 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
822 public void MapPageRoute_String_String_String_Bool_RVD_RVD_RVD ()
824 var c = new RouteCollection ();
825 var defaults = new RouteValueDictionary ();
826 var constraints = new RouteValueDictionary ();
827 var dataTokens = new RouteValueDictionary ();
829 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults, constraints, dataTokens);
830 var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
831 hc.SetResponse (new HttpResponseStub (3));
832 var rd = c.GetRouteData (hc);
834 Assert.IsNotNull (rd, "#A1-1");
835 Assert.IsNotNull (rd.RouteHandler, "#A1-2");
836 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
837 Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");
839 c = new RouteCollection ();
840 AssertExtensions.Throws<ArgumentNullException> (() => {
841 c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults, constraints, dataTokens);
844 c = new RouteCollection ();
845 c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults, constraints, dataTokens);
846 rd = c.GetRouteData (hc);
848 Assert.IsNull (rd, "#A2");
850 c = new RouteCollection ();
851 // thrown by PageRouteHandler's constructor
852 AssertExtensions.Throws<ArgumentException> (() => {
853 c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults, constraints, dataTokens);
856 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults, constraints, dataTokens);
857 rd = c.GetRouteData (hc);
859 Assert.IsNotNull (rd, "#A4-1");
860 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
861 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
862 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
864 c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null, constraints, dataTokens);
865 rd = c.GetRouteData (hc);
867 Assert.IsNotNull (rd, "#A4-1");
868 Assert.IsNotNull (rd.RouteHandler, "#A4-2");
869 Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
870 Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");