示例#1
0
        public void Pipeline3()
        {
            var m = new UrlRoutingModule();

            RouteTable.Routes.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
#if NET_4_0
            var hc = new HttpContextStub5("~/x/y", String.Empty, "apppath");
#else
            var hc = new HttpContextStub2("~/x/y", String.Empty, "apppath");
#endif
            hc.SetResponse(new HttpResponseStub(2));
#if NET_4_0
            Assert.IsNull(m.RouteCollection.GetRouteData(hc), "#0");
#else
            Assert.IsNotNull(m.RouteCollection.GetRouteData(hc), "#0");
            m.PostResolveRequestCache(hc);
            try
            {
                m.PostMapRequestHandler(hc);
                Assert.Fail("#1");
            }
            catch (ApplicationException ex)
            {
                Assert.AreEqual("~/UrlRouting.axd", ex.Message, "#2");
            }
#endif
        }
示例#2
0
        public void GetVirtualPath6()
        {
            var r = new MyRoute("summary/{action}-{type}/{page}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { action = "Index", page = 1 })
            };
            var hc     = new HttpContextStub2("~/summary/Index-test/1", String.Empty);
            var rd     = r.GetRouteData(hc);
            var values = new RouteValueDictionary(new { page = 2 });

            Assert.IsNotNull(rd, "#1");
            var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

            Assert.IsNotNull(vp, "#2");
            Assert.AreEqual("summary/Index-test/2", vp.VirtualPath, "#2-1");
            Assert.AreEqual(r, vp.Route, "#2-2");
            Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");

            values = new RouteValueDictionary(new { page = 2, extra = "stuff" });
            vp     = r.GetVirtualPath(new RequestContext(hc, rd), values);

            Assert.IsNotNull(vp, "#3");
            Assert.AreEqual("summary/Index-test/2?extra=stuff", vp.VirtualPath, "#3-2");
            Assert.AreEqual(0, vp.DataTokens.Count, "#3-3");
        }
示例#3
0
        public void GetRouteDataNerdDinner2()
        {
            var c = new RouteCollection();

            c.Add("UpcomingDiners",
                  new MyRoute("Dinners/Page/{page}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Dinners", action = "Index" })
            }
                  );

            c.Add("Default",
                  new MyRoute("{controller}/{action}/{id}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" })
            }
                  );

            var hc = new HttpContextStub2("~/Home/Index", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A1");
        }
示例#4
0
        public void Ignore_String_Object()
        {
            var c = new RouteCollection();

            AssertExtensions.Throws <ArgumentNullException> (() => {
                c.Ignore(null, new { allaspx = @".*\.aspx(/.*)?" });
            }, "#A1");

            c.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
            var hc = new HttpContextStub2("~/page.aspx", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A1-1");
            Assert.IsNotNull(rd.RouteHandler, "#A1-2");
            Assert.AreEqual(typeof(StopRoutingHandler), rd.RouteHandler.GetType(), "#A1-3");
            Assert.IsTrue(rd.Route is Route, "#A1-4");
            Assert.IsNotNull(((Route)rd.Route).Constraints, "#A1-5");
            Assert.AreEqual(1, ((Route)rd.Route).Constraints.Count, "#A1-6");
            Assert.AreEqual(@".*\.aspx(/.*)?", ((Route)rd.Route).Constraints ["allaspx"], "#A1-7");

            c = new RouteCollection();
            c.Ignore("{*allaspx}", "something invalid");

            AssertExtensions.Throws <InvalidOperationException> (() => {
                rd = c.GetRouteData(hc);
            }, "#A2");
        }
示例#5
0
        public void MapPageRoute_String_String_String()
        {
            var c = new RouteCollection();

            c.MapPageRoute(null, "{foo}-{bar}", "~/some-url");
            var hc = new HttpContextStub2("~/some-url", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A1-1");
            Assert.IsNotNull(rd.RouteHandler, "#A1-2");
            Assert.AreEqual(typeof(PageRouteHandler), rd.RouteHandler.GetType(), "#A1-3");

            c = new RouteCollection();
            AssertExtensions.Throws <ArgumentNullException> (() => {
                c.MapPageRoute("RouteName", null, "~/some-url");
            }, "#A2");

            c = new RouteCollection();
            c.MapPageRoute("RouteName", String.Empty, "~/some-url");
            rd = c.GetRouteData(hc);

            Assert.IsNull(rd, "#A2");

            c = new RouteCollection();
            // thrown by PageRouteHandler's constructor
            AssertExtensions.Throws <ArgumentException> (() => {
                c.MapPageRoute("RouteName", "~/some-url", null);
            }, "#A3");
        }
示例#6
0
        public void GetVirtualPathNoApplicationPath()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/x/y", String.Empty);
            var rd = c.GetRouteData(hc);
            // it tries to get HttpContextBase.Request.ApplicationPath and then throws NIE.
            var vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);
        }
示例#7
0
        public void GetVirtualPathNoApplyAppPathModifier()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/x/y", String.Empty, "apppath");

            // it tries to call HttpContextBase.Response.ApplyAppPathModifier() and then causes NIE.
            hc.SetResponse(new HttpResponseStub());
            var rd  = c.GetRouteData(hc);
            var vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);
        }
示例#8
0
        public void GetVirtualPath3()
        {
            var r  = new MyRoute("{foo}/{bar}", new MyRouteHandler());
            var hc = new HttpContextStub2("~/x/y", String.Empty);
            var rd = r.GetRouteData(hc);
            var vp = r.GetVirtualPath(new RequestContext(hc, rd), rd.Values);

            Assert.IsNotNull(vp, "#1");
            Assert.AreEqual("x/y", vp.VirtualPath, "#2");
            Assert.AreEqual(r, vp.Route, "#3");
            Assert.AreEqual(0, vp.DataTokens.Count, "#4");
        }
示例#9
0
        public void GetVirtualPath6()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("reports/{year}/{month}/{day}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary {
                    { "day", 1 }
                }
            }
                  );

            var hc = new HttpContextStub2("~/reports/2009/05", String.Empty, "/myapp");

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");

            var vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary {
                { "year", 2007 },
                { "month", 1 },
                { "day", 12 },
            }
                                      );

            Assert.IsNotNull(vp, "#2");
            Assert.AreEqual("/myapp/reports/2007/1/12", vp.VirtualPath, "#2-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary {
                { "year", 2007 },
                { "month", 1 }
            }
                                  );
            Assert.IsNotNull(vp, "#3");
            Assert.AreEqual("/myapp/reports/2007/1", vp.VirtualPath, "#3-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary {
                { "year", 2007 },
                { "month", 1 },
                { "day", 12 },
                { "category", 123 }
            }
                                  );
            Assert.IsNotNull(vp, "#4");
            Assert.AreEqual("/myapp/reports/2007/1/12?category=123", vp.VirtualPath, "#4-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary {
                { "year", 2007 },
            }
                                  );
            Assert.IsNull(vp, "#5");
        }
示例#10
0
        public void MapPageRoute_String_String_String_Bool_RVD_RVD_RVD()
        {
            var c           = new RouteCollection();
            var defaults    = new RouteValueDictionary();
            var constraints = new RouteValueDictionary();
            var dataTokens  = new RouteValueDictionary();

            c.MapPageRoute(null, "{foo}-{bar}", "~/some-url", true, defaults, constraints, dataTokens);
            var hc = new HttpContextStub2("~/some-url", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A1-1");
            Assert.IsNotNull(rd.RouteHandler, "#A1-2");
            Assert.AreEqual(typeof(PageRouteHandler), rd.RouteHandler.GetType(), "#A1-3");
            Assert.IsTrue(((PageRouteHandler)rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");

            c = new RouteCollection();
            AssertExtensions.Throws <ArgumentNullException> (() => {
                c.MapPageRoute("RouteName", null, "~/some-url", true, defaults, constraints, dataTokens);
            }, "#A2");

            c = new RouteCollection();
            c.MapPageRoute("RouteName", String.Empty, "~/some-url", true, defaults, constraints, dataTokens);
            rd = c.GetRouteData(hc);

            Assert.IsNull(rd, "#A2");

            c = new RouteCollection();
            // thrown by PageRouteHandler's constructor
            AssertExtensions.Throws <ArgumentException> (() => {
                c.MapPageRoute("RouteName", "~/some-url", null, true, defaults, constraints, dataTokens);
            }, "#A3");

            c.MapPageRoute(null, "{foo}-{bar}", "~/some-url", false, defaults, constraints, dataTokens);
            rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A4-1");
            Assert.IsNotNull(rd.RouteHandler, "#A4-2");
            Assert.AreEqual(typeof(PageRouteHandler), rd.RouteHandler.GetType(), "#A4-3");
            Assert.IsFalse(((PageRouteHandler)rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");

            c.MapPageRoute(null, "{foo}-{bar}", "~/some-url", false, null, constraints, dataTokens);
            rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A4-1");
            Assert.IsNotNull(rd.RouteHandler, "#A4-2");
            Assert.AreEqual(typeof(PageRouteHandler), rd.RouteHandler.GetType(), "#A4-3");
            Assert.IsFalse(((PageRouteHandler)rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
        }
示例#11
0
        public void PostResolveRequestCacheCallRewritePath()
        {
            var m = new UrlRoutingModule();

            RouteTable.Routes.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/x/y", "z");

            try {
                m.PostResolveRequestCache(hc);
                Assert.Fail("#1");
            } catch (ApplicationException ex) {
                Assert.AreEqual("~/UrlRouting.axd", ex.Message, "#2");
            }
        }
示例#12
0
        public void GetVirtualPathToExistingFile()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/Test/test.html", String.Empty, ".");

            // it tries to get HttpContextBase.Response, so set it.
            hc.SetResponse(new HttpResponseStub(3));
            var rd  = c.GetRouteData(hc);
            var vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);

            Assert.AreEqual("./Test/test.html", vpd.VirtualPath, "#1");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#2");
        }
示例#13
0
        public void GetVirtualPath4()
        {
            var r  = new MyRoute("{foo}/{bar}", new MyRouteHandler());
            var hc = new HttpContextStub2("~/x/y", String.Empty);
            var rd = r.GetRouteData(hc);

            // override a value incompletely
            var values = new RouteValueDictionary();

            values ["foo"] = "A";

            var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

            Assert.IsNull(vp);
        }
示例#14
0
        public void PostResolveRequestCachePathToExistingFile()
        {
            var m = new UrlRoutingModule();

            RouteTable.Routes.Add(new MyRoute("~/{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/hoge/fuga", String.Empty, ".");

            // it tries to get HttpContextBase.Response, so set it.
            hc.SetResponse(new HttpResponseStub(3));
            try {
                m.PostResolveRequestCache(hc);
                Assert.Fail("#1");
            } catch (ApplicationException ex) {
                Assert.AreEqual("~/UrlRouting.axd", ex.Message, "#2");
            }
        }
示例#15
0
        public void GetVirtualPath8()
        {
            var r = new MyRoute("todo/{action}/{page}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "todo", action = "list", page = 0 })
            };
            var hc = new HttpContextStub2("~/todo/list/2", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");

            var vp = r.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { page = 3 }));

            Assert.IsNotNull(vp, "#2");
            Assert.AreEqual("todo/list/3", vp.VirtualPath, "#2-1");
        }
示例#16
0
        public void GetVirtualPath3()
        {
            var c = new RouteCollection();

            c.Add("todo-route",
                  new MyRoute("todo/{action}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "todo", action = "list", page = 0 })
            }
                  );

            c.Add("another-route",
                  new MyRoute("{controller}/{action}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "home", action = "list", page = 0 })
            }
                  );

            var hc = new HttpContextStub2("~/home/list", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(3, rd.Values.Count, "#1-1");
            Assert.AreEqual("home", rd.Values["controller"], "#1-2");
            Assert.AreEqual("list", rd.Values["action"], "#1-3");
            Assert.AreEqual(0, rd.Values["page"], "#1-4");

            var vp = c.GetVirtualPath(new RequestContext(hc, rd), "todo-route", new RouteValueDictionary());

            Assert.IsNotNull(vp, "#2");
            Assert.AreEqual("/todo", vp.VirtualPath, "#2-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary());
            Assert.IsNotNull(vp, "#3");
            Assert.AreEqual("/todo", vp.VirtualPath, "#3-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { controller = "home" }));
            Assert.IsNotNull(vp, "#4");
            Assert.AreEqual("/", vp.VirtualPath, "#4-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { controller = "home", extra = "stuff" }));
            Assert.IsNotNull(vp, "#5");
            Assert.AreEqual("/?extra=stuff", vp.VirtualPath, "#5-1");
        }
示例#17
0
        public void GetVirtualPathCheckVirtualPathToModify()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/x/y", String.Empty, "apppath");

            // it tries to get HttpContextBase.Response, so set it.
            hc.SetResponse(new HttpResponseStub(1));
            var rd = c.GetRouteData(hc);

            try {
                var vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);
                Assert.Fail("#1");
            } catch (ApplicationException ex) {
                Assert.AreEqual("apppath/x/y", ex.Message, "#2");
            }
        }
示例#18
0
        public void RouteGetRequiredStringWithDefaults()
        {
            var routes = new RouteValueDictionary();
            var route  = new Route("Hello/{name}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Home", action = "Hello" })
            };

            routes.Add("Name", route);

            var hc = new HttpContextStub2("~/Hello/World", String.Empty);
            var rd = route.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A1");
            Assert.AreEqual("Home", rd.GetRequiredString("controller"), "#A2");
            Assert.AreEqual("Hello", rd.GetRequiredString("action"), "#A3");
            Assert.AreEqual("World", rd.Values ["name"], "#A4");
        }
示例#19
0
        public void GetVirtualPath()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("{foo}/{bar}", new MyRouteHandler()));
            var hc = new HttpContextStub2("~/x/y", String.Empty, "apppath");

            // it tries to get HttpContextBase.Response, so set it.
            hc.SetResponse(new HttpResponseStub(2));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");

            var vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);

            Assert.IsNotNull(vpd, "#2");
            Assert.AreEqual("apppath/x/y_modified", vpd.VirtualPath, "#3");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#4");
        }
示例#20
0
        public void GetVirtualPath5()
        {
            var r  = new MyRoute("{foo}/{bar}", new MyRouteHandler());
            var hc = new HttpContextStub2("~/x/y", String.Empty);
            var rd = r.GetRouteData(hc);

            // override values completely.
            var values = new RouteValueDictionary();

            values ["foo"] = "A";
            values ["bar"] = "B";

            var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

            Assert.IsNotNull(vp, "#1");
            Assert.AreEqual("A/B", vp.VirtualPath, "#2");
            Assert.AreEqual(r, vp.Route, "#3");
            Assert.AreEqual(0, vp.DataTokens.Count, "#4");
        }
示例#21
0
        public void GetVirtualPath12()
        {
            var r = new MyRoute("{foo}/{bar}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { bar = "baz" })
            };

            var hc     = new HttpContextStub2("~/x/y", String.Empty);
            var rd     = r.GetRouteData(hc);
            var values = new RouteValueDictionary();

            // Partial override is possible if defaults are specified
            values ["foo"] = "A";
            values ["baz"] = "B";

            var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

            Assert.IsNotNull(vp, "#1");
            Assert.AreEqual("A?baz=B", vp.VirtualPath, "#1-1");
        }
示例#22
0
        public void Ignore_String()
        {
            var c = new RouteCollection();

            AssertExtensions.Throws <ArgumentNullException> (() => {
                c.Ignore(null);
            }, "#A1");

            c.Ignore("{resource}.axd/{*pathInfo}");
            var hc = new HttpContextStub2("~/something.axd/pathinfo", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#A1-1");
            Assert.IsNotNull(rd.RouteHandler, "#A1-2");
            Assert.AreEqual(typeof(StopRoutingHandler), rd.RouteHandler.GetType(), "#A1-3");
            Assert.IsTrue(rd.Route is Route, "#A1-4");
            Assert.IsNotNull(((Route)rd.Route).Constraints, "#A1-5");
            Assert.AreEqual(0, ((Route)rd.Route).Constraints.Count, "#A1-6");
        }
示例#23
0
        public void GetVirtualPath14()
        {
            var r  = new MyRoute("{table}/{action}.aspx", new MyRouteHandler());
            var hc = new HttpContextStub2("~/x/y.aspx", String.Empty);
            var rd = r.GetRouteData(hc);

            // override a value incompletely
            var values = new RouteValueDictionary(new {
                emptyValue    = String.Empty,
                nullValue     = (string)null,
                nonEmptyValue = "SomeValue"
            });

            var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

            Assert.IsNotNull(vp, "#A1");
            Assert.AreEqual("x/y.aspx?nonEmptyValue=SomeValue", vp.VirtualPath, "#A1-1");

            values["nonEmptyValue"] = "Some Value + encoding &";
            vp = r.GetVirtualPath(new RequestContext(hc, rd), values);
            Assert.IsNotNull(vp, "#B1");
            Assert.AreEqual("x/y.aspx?nonEmptyValue=Some%20Value%20%2B%20encoding%20%26", vp.VirtualPath, "#B1-1");
        }
示例#24
0
        public void GetVirtualPath4()
        {
            var c = new RouteCollection();

            c.Add(new MyRoute("blog/{user}/{action}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary {
                    { "controller", "blog" },
                    { "user", "admin" }
                }
            }
                  );

            c.Add(new MyRoute("forum/{user}/{action}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary {
                    { "controller", "forum" },
                    { "user", "admin" }
                }
            }
                  );

            var hc = new HttpContextStub2("~/forum/admin/Index", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd = c.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");

            var vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { action = "Index", controller = "forum" }));

            Assert.IsNotNull(vp, "#2");
            Assert.AreEqual("/forum/admin/Index", vp.VirtualPath, "#2-1");

            vp = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { action = "Index", controller = "blah" }));
            Assert.IsNull(vp, "#3");
        }
示例#25
0
		public void GetVirtualPath14 ()
		{
			var r = new MyRoute ("{table}/{action}.aspx", new MyRouteHandler ());
			var hc = new HttpContextStub2 ("~/x/y.aspx", String.Empty);
			var rd = r.GetRouteData (hc);

			// override a value incompletely
			var values = new RouteValueDictionary (new {
				emptyValue = String.Empty,
				nullValue = (string)null,
				nonEmptyValue = "SomeValue"
			});

			var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
			Assert.IsNotNull (vp, "#A1");
			Assert.AreEqual ("x/y.aspx?nonEmptyValue=SomeValue", vp.VirtualPath, "#A1-1");

			values["nonEmptyValue"] = "Some Value + encoding &";
			vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
			Assert.IsNotNull (vp, "#B1");
			Assert.AreEqual ("x/y.aspx?nonEmptyValue=Some%20Value%20%2B%20encoding%20%26", vp.VirtualPath, "#B1-1");

		}
示例#26
0
		public void GetVirtualPath12 ()
		{
			var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary (new { bar = "baz" })
						};
						
			var hc = new HttpContextStub2 ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);
			var values = new RouteValueDictionary ();

			// Partial override is possible if defaults are specified
			values ["foo"] = "A";
			values ["baz"] = "B";
			
			var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("A?baz=B", vp.VirtualPath, "#1-1");
		}
示例#27
0
        public void GetVirtualPath2()
        {
            var c = new RouteCollection();

            c.Add("Summary",
                  new MyRoute("summary/{action}-{type}/{page}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Summary", action = "Index", page = 1 })
            }
                  );

            c.Add("Apis",
                  new MyRoute("apis/{apiname}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Apis", action = "Index" })
            }
                  );

            c.Add("Single Report",
                  new MyRoute("report/{guid}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Reports", action = "SingleReport" })
            }
                  );

            c.Add("Reports",
                  new MyRoute("reports/{page}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Reports", action = "Index", page = 1 })
            }
                  );

            c.Add("Default",
                  new MyRoute("{controller}/{action}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index" })
            }
                  );

            var hc = new HttpContextStub2("~/Home/About", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(2));
            var rd  = c.GetRouteData(hc);
            var vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);

            Assert.IsNotNull(vpd, "#A1");
            Assert.AreEqual("/Home/About_modified", vpd.VirtualPath, "#A2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#A3");

            hc = new HttpContextStub2("~/Home/Index", String.Empty, String.Empty);
            hc.SetResponse(new HttpResponseStub(2));
            rd  = c.GetRouteData(hc);
            vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);
            Assert.IsNotNull(vpd, "#B1");
            Assert.AreEqual("/_modified", vpd.VirtualPath, "#B2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#B3");

            hc = new HttpContextStub2("~/Account/LogOn", String.Empty, String.Empty);
            hc.SetResponse(new HttpResponseStub(2));
            rd  = c.GetRouteData(hc);
            vpd = c.GetVirtualPath(new RequestContext(hc, rd), rd.Values);
            Assert.IsNotNull(vpd, "#C1");
            Assert.AreEqual("/Account/LogOn_modified", vpd.VirtualPath, "#C2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#C3");

            hc = new HttpContextStub2("~/", String.Empty, String.Empty);
            hc.SetResponse(new HttpResponseStub(3));
            rd  = c.GetRouteData(hc);
            vpd = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { controller = "home" }));
            Assert.IsNotNull(vpd, "#D1");
            Assert.AreEqual("/", vpd.VirtualPath, "#D2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#D3");

            hc = new HttpContextStub2("~/", String.Empty, String.Empty);
            hc.SetResponse(new HttpResponseStub(3));
            rd  = c.GetRouteData(hc);
            vpd = c.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { controller = "Home" }));
            Assert.IsNotNull(vpd, "#E1");
            Assert.AreEqual("/", vpd.VirtualPath, "#E2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#E3");
        }
示例#28
0
		public void GetVirtualPath2 ()
		{
			var c = new RouteCollection ();
			
			c.Add ("Summary",
			       new MyRoute ("summary/{action}-{type}/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Summary", action = "Index", page = 1}) }
			);
			       
			c.Add ("Apis",
			       new MyRoute ("apis/{apiname}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Apis", action = "Index" }) }
			);
							    
			c.Add ("Single Report",
			       new MyRoute ("report/{guid}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "SingleReport" }) }
			);
			
			c.Add ("Reports",
			       new MyRoute ("reports/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Reports", action = "Index", page = 1 }) }
			);

			c.Add ("Default",
			       new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index"}) }
			);

			var hc = new HttpContextStub2 ("~/Home/About", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (2));
			var rd = c.GetRouteData (hc);
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#A1");
			Assert.AreEqual ("/Home/About_modified", vpd.VirtualPath, "#A2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");

			hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (2));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#B1");
			Assert.AreEqual ("/_modified", vpd.VirtualPath, "#B2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");

			hc = new HttpContextStub2 ("~/Account/LogOn", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (2));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#C1");
			Assert.AreEqual ("/Account/LogOn_modified", vpd.VirtualPath, "#C2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");

			hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }) );
			Assert.IsNotNull (vpd, "#D1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#D2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#D3");

			hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = c.GetRouteData (hc);
			vpd = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "Home" }) );
			Assert.IsNotNull (vpd, "#E1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#E2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#E3");
		}
示例#29
0
		public void GetVirtualPathCheckVirtualPathToModify ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
			// it tries to get HttpContextBase.Response, so set it.
			hc.SetResponse (new HttpResponseStub (1));
			var rd = c.GetRouteData (hc);
			try {
				var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
				Assert.Fail ("#1");
			} catch (ApplicationException ex) {
				Assert.AreEqual ("apppath/x/y", ex.Message, "#2");
			}
		}
示例#30
0
		public void GetVirtualPathNoApplicationPath ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/x/y", String.Empty);
			var rd = c.GetRouteData (hc);
			// it tries to get HttpContextBase.Request.ApplicationPath and then throws NIE.
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
		}
示例#31
0
		public void GetVirtualPath4 ()
		{
			var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
			var hc = new HttpContextStub2 ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);

			// override a value incompletely
			var values = new RouteValueDictionary ();
			values ["foo"] = "A";

			var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);
			Assert.IsNull (vp);
		}
示例#32
0
		public void GetVirtualPath4 ()
		{
			var c = new RouteCollection ();

			c.Add (new MyRoute ("blog/{user}/{action}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{ "controller", "blog" },
							{ "user", "admin" }
						}
				}
			);

			c.Add (new MyRoute ("forum/{user}/{action}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{ "controller", "forum" },
							{ "user", "admin" }
						}
				}
			);

			var hc = new HttpContextStub2 ("~/forum/admin/Index", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");

			var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="forum"}));
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("/forum/admin/Index", vp.VirtualPath, "#2-1");
			
			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { action="Index", controller="blah"}));
			Assert.IsNull (vp, "#3");
		}
示例#33
0
		public void GetVirtualPath25()
		{
			var r = new MyRoute("{year}/{month}/{slug}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { controller = "Blog", action = "View" }),
				Constraints = new RouteValueDictionary(new { year = @"\d{4}", month = @"\d{2}" }),
			};
			var hc = new HttpContextStub2("~/", String.Empty);
			var values = new RouteValueDictionary()
			{
				{ "area", string.Empty },
				{ "controller", "Blog" },
				{ "action", "View" },
				{ "year", 2013 }, // Year as an int, not a string
				{ "month", "08" },
				{ "slug", "hello-world" },
			};
			var vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);

			Assert.IsNotNull(vp, "#1");
			Assert.AreEqual("2013/08/hello-world", vp.VirtualPath, "#2");
		}
示例#34
0
		public void GetVirtualPath20 ()
		{
			var r = new MyRoute("summary/{controller}/{id}/{action}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { action = "Index" })
			};
			var hc = new HttpContextStub2("~/summary/kind/1/test", String.Empty);
			var rd = r.GetRouteData(hc);
			Assert.IsNotNull(rd, "#1");

			var values = new RouteValueDictionary(new { id = "2", action = "save" });
			var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

			Assert.IsNotNull(vp, "#2");
			Assert.AreEqual("summary/kind/2/save", vp.VirtualPath, "#2-1");
			Assert.AreEqual(r, vp.Route, "#2-2");
			Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");

			values = new RouteValueDictionary(new { id = "3", action = "save", extra = "stuff" });
			vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

			Assert.IsNotNull(vp, "#3");
			Assert.AreEqual("summary/kind/3/save?extra=stuff", vp.VirtualPath, "#3-2");
			Assert.AreEqual(0, vp.DataTokens.Count, "#3-3");
		}
示例#35
0
		public void MapPageRoute_String_String_String ()
		{
			var c = new RouteCollection ();

			c.MapPageRoute (null, "{foo}-{bar}", "~/some-url");
			var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1-1");
			Assert.IsNotNull (rd.RouteHandler, "#A1-2");
			Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");

			c = new RouteCollection ();
			AssertExtensions.Throws<ArgumentNullException> (() => {
				c.MapPageRoute ("RouteName", null, "~/some-url");
			}, "#A2");

			c = new RouteCollection ();
			c.MapPageRoute ("RouteName", String.Empty, "~/some-url");
			rd = c.GetRouteData (hc);

			Assert.IsNull (rd, "#A2");

			c = new RouteCollection ();
			// thrown by PageRouteHandler's constructor
			AssertExtensions.Throws<ArgumentException> (() => {
				c.MapPageRoute ("RouteName", "~/some-url", null);
			}, "#A3");
		}
示例#36
0
		public void Ignore_String ()
		{
			var c = new RouteCollection ();

			AssertExtensions.Throws<ArgumentNullException> (() => {
				c.Ignore (null);
			}, "#A1");

			c.Ignore ("{resource}.axd/{*pathInfo}");
			var hc = new HttpContextStub2 ("~/something.axd/pathinfo", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1-1");
			Assert.IsNotNull (rd.RouteHandler, "#A1-2");
			Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
			Assert.IsTrue (rd.Route is Route, "#A1-4");
			Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
			Assert.AreEqual (0, ((Route) rd.Route).Constraints.Count, "#A1-6");
		}
示例#37
0
		public void GetVirtualPath8 ()
		{
			var routes = new RouteCollection();

			routes.Add (new MyRoute ("login", new MyRouteHandler ()) {
				Defaults = new RouteValueDictionary (new { controller = "Home", action = "LogOn" })
			});

			routes.Add (new MyRoute ("{site}/{controller}/{action}", new MyRouteHandler ())	{
				Defaults = new RouteValueDictionary (new { site = "_", controller = "Home", action = "Index" }),
				Constraints = new RouteValueDictionary ( new { site = "_?[0-9A-Za-z-]*" })
			});

			routes.Add (new MyRoute ("{*path}", new MyRouteHandler ()) {
				Defaults = new RouteValueDictionary (new { controller = "Error", action = "NotFound" }),
			});

			var hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = routes.GetRouteData (hc);
			var rvs = new RouteValueDictionary () {
				{ "controller", "Home" },
				{ "action" , "Index" }
			};
			var vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
			Assert.IsNotNull (vpd, "#A1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#A2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#A3");

			hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = routes.GetRouteData (hc);
			rvs = new RouteValueDictionary () {
				{ "controller", "Home" }
			};
			vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
			Assert.IsNotNull (vpd, "#B1");
			Assert.AreEqual ("/login", vpd.VirtualPath, "#B2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#B3");

			hc = new HttpContextStub2 ("~/login", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			rd = routes.GetRouteData (hc);
			rvs = new RouteValueDictionary () {
				{ "action" , "Index" }
			};
			vpd = routes.GetVirtualPath (new RequestContext (hc, rd), rvs);
			Assert.IsNotNull (vpd, "#C1");
			Assert.AreEqual ("/", vpd.VirtualPath, "#C2");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#C3");

			hc = new HttpContextStub2 ("~/", String.Empty, String.Empty);
			rd = routes.GetRouteData (hc);
			Assert.IsNotNull (rd, "#D1");
		}
示例#38
0
		public void RouteGetRequiredStringWithDefaults ()
		{
			var routes = new RouteValueDictionary ();
			var route = new Route ("Hello/{name}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary (new {controller = "Home", action = "Hello"})
			};
			
			routes.Add ("Name", route);

			var hc = new HttpContextStub2 ("~/Hello/World", String.Empty);
			var rd = route.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1");
			Assert.AreEqual ("Home", rd.GetRequiredString ("controller"), "#A2");
			Assert.AreEqual ("Hello", rd.GetRequiredString ("action"), "#A3");
			Assert.AreEqual ("World", rd.Values ["name"], "#A4");
		}
示例#39
0
		public void GetVirtualPath3 ()
		{
			var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
			var hc = new HttpContextStub2 ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);
			var vp = r.GetVirtualPath (new RequestContext (hc, rd), rd.Values);

			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("x/y", vp.VirtualPath, "#2");
			Assert.AreEqual (r, vp.Route, "#3");
			Assert.AreEqual (0, vp.DataTokens.Count, "#4");
		}
示例#40
0
		public void GetVirtualPathToExistingFile ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/Test/test.html", String.Empty, ".");
			// it tries to get HttpContextBase.Response, so set it.
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.AreEqual ("./Test/test.html", vpd.VirtualPath, "#1");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#2");
		}
示例#41
0
		public void GetVirtualPath5 ()
		{
			var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
			var hc = new HttpContextStub2 ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);

			// override values completely.
			var values = new RouteValueDictionary ();
			values ["foo"] = "A";
			values ["bar"] = "B";

			var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);

			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("A/B", vp.VirtualPath, "#2");
			Assert.AreEqual (r, vp.Route, "#3");
			Assert.AreEqual (0, vp.DataTokens.Count, "#4");
		}
示例#42
0
		public void GetVirtualPath22 ()
		{
			var r = new MyRoute("summary/{controller}/{id}/{action}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { action = "Index" })
			};
			var hc = new HttpContextStub2("~/summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5/test", String.Empty);
			var rd = r.GetRouteData(hc);
			Assert.IsNotNull(rd, "#0");
			Assert.AreEqual("90941a4f-daf3-4c89-a6dc-83e8de4e3db5", rd.Values["id"]);

			var values = new RouteValueDictionary(new { action = "Index" });
			var vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

			Assert.IsNotNull(vp, "#1");
			Assert.AreEqual("summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5", vp.VirtualPath, "#1-1");
			Assert.AreEqual(r, vp.Route, "#1-2");
			Assert.AreEqual(0, vp.DataTokens.Count, "#1-3");

			values = new RouteValueDictionary(new { action = "save" });
			vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

			Assert.IsNotNull(vp, "#2");
			Assert.AreEqual("summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5/save", vp.VirtualPath, "#2-1");
			Assert.AreEqual(r, vp.Route, "#2-2");
			Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");

			values = new RouteValueDictionary(new { action = "save", extra = "stuff" });
			vp = r.GetVirtualPath(new RequestContext(hc, rd), values);

			Assert.IsNotNull(vp, "#3");
			Assert.AreEqual("summary/kind/90941a4f-daf3-4c89-a6dc-83e8de4e3db5/save?extra=stuff", vp.VirtualPath, "#3-2");
			Assert.AreEqual(0, vp.DataTokens.Count, "#3-3");
		}
示例#43
0
		public void GetVirtualPathNoApplyAppPathModifier ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
			// it tries to call HttpContextBase.Response.ApplyAppPathModifier() and then causes NIE.
			hc.SetResponse (new HttpResponseStub ());
			var rd = c.GetRouteData (hc);
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
		}
示例#44
0
		public void GetVirtualPath9 ()
		{
			var r = new MyRoute ("todo/{action}/{page}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{"controller", "todo"},
							{"action", null},
							{"page", null}
						}
				};
			
			var hc = new HttpContextStub2 ("~/todo/list/2", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			
			var vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3 }));
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("todo/list/3", vp.VirtualPath, "#2-1");
		}
示例#45
0
		public void GetVirtualPath ()
		{
			var c = new RouteCollection ();
			c.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
			var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
			// it tries to get HttpContextBase.Response, so set it.
			hc.SetResponse (new HttpResponseStub (2));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			
			var vpd = c.GetVirtualPath (new RequestContext (hc, rd), rd.Values);
			Assert.IsNotNull (vpd, "#2");
			Assert.AreEqual ("apppath/x/y_modified", vpd.VirtualPath, "#3");
			Assert.AreEqual (0, vpd.DataTokens.Count, "#4");
		}
示例#46
0
		public void GetVirtualPath11 ()
		{
			var r = new MyRoute ("summary/{action}/{page}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary (new { action = "Index", page = 1 })
						};
			var hc = new HttpContextStub2 ("~/summary/test/1", String.Empty);
			var rd = r.GetRouteData (hc);
			var values = new RouteValueDictionary (new { page = 2 });

			Assert.IsNotNull (rd, "#1");
			var vp = r.GetVirtualPath (new RequestContext (hc, rd), values);

			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("summary/test/2", vp.VirtualPath, "#2-1");
			Assert.AreEqual (r, vp.Route, "#2-2");
			Assert.AreEqual (0, vp.DataTokens.Count, "#2-3");

			values = new RouteValueDictionary (new { page = 2, extra = "stuff" });
			vp = r.GetVirtualPath (new RequestContext (hc, rd), values);

			Assert.IsNotNull (vp, "#3");
			Assert.AreEqual ("summary/test/2?extra=stuff", vp.VirtualPath, "#3-2");
			Assert.AreEqual (0, vp.DataTokens.Count, "#3-3");
		}
示例#47
0
		public void GetVirtualPath3 ()
		{
			var c = new RouteCollection ();

			c.Add ("todo-route",
			       new MyRoute ("todo/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "todo", action="list", page=0}) }
			);

			c.Add ("another-route",
			       new MyRoute ("{controller}/{action}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new {controller = "home", action="list", page=0}) }
			);

			var hc = new HttpContextStub2 ("~/home/list", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (3, rd.Values.Count, "#1-1");
			Assert.AreEqual ("home", rd.Values["controller"], "#1-2");
			Assert.AreEqual ("list", rd.Values["action"], "#1-3");
			Assert.AreEqual (0, rd.Values["page"], "#1-4");
			
			var vp = c.GetVirtualPath (new RequestContext (hc, rd), "todo-route", new RouteValueDictionary ());
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("/todo", vp.VirtualPath, "#2-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary ());
			Assert.IsNotNull (vp, "#3");
			Assert.AreEqual ("/todo", vp.VirtualPath, "#3-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home" }));
			Assert.IsNotNull (vp, "#4");
			Assert.AreEqual ("/", vp.VirtualPath, "#4-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { controller = "home", extra="stuff" }));
			Assert.IsNotNull (vp, "#5");
			Assert.AreEqual ("/?extra=stuff", vp.VirtualPath, "#5-1");
		}
示例#48
0
		public void GetVirtualPathWithCatchall2()
		{
			var r = new MyRoute("HelloWorld/{*path}", new MyRouteHandler());
			var hc = new HttpContextStub2("~/", String.Empty);
			var values = new RouteValueDictionary()
			{
				{ "path", "foo/bar/baz" },
			};
			var vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);

			Assert.IsNotNull(vp, "#1");
			Assert.AreEqual("HelloWorld/foo/bar/baz", vp.VirtualPath, "#2");
		}
示例#49
0
		public void GetVirtualPath6 ()
		{
			var c = new RouteCollection ();

			c.Add (new MyRoute ("reports/{year}/{month}/{day}", new MyRouteHandler ()) {
					Defaults = new RouteValueDictionary {
							{ "day", 1 }
						}
				}
			);

			var hc = new HttpContextStub2 ("~/reports/2009/05", String.Empty, "/myapp");
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");

			var vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
					{ "month", 1 },
					{ "day", 12 },
				}
			);
			Assert.IsNotNull (vp, "#2");
			Assert.AreEqual ("/myapp/reports/2007/1/12", vp.VirtualPath, "#2-1");
			
			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
					{ "month", 1 }
				}
			);
			Assert.IsNotNull (vp, "#3");
			Assert.AreEqual ("/myapp/reports/2007/1", vp.VirtualPath, "#3-1");

			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
					{ "month", 1 },
					{ "day", 12 },
					{ "category", 123 }
				}
			);
			Assert.IsNotNull (vp, "#4");
			Assert.AreEqual ("/myapp/reports/2007/1/12?category=123", vp.VirtualPath, "#4-1");
			
			vp = c.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary {
					{ "year", 2007 },
				}
			);
			Assert.IsNull (vp, "#5");
		}
示例#50
0
		public void GetVirtualPath24 ()
		{
			var r = new MyRoute ("{controller}/{country}-{locale}/{action}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary (new { action = "Index", country = "us", locale = "en" })
			};
			var hc = new HttpContextStub2 ("~/login", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#0");

			var values = new RouteValueDictionary ()
			{
				{ "controller", "SomeThing" },
				{ "action", "Index" },
				{ "country", "es" }
			};
			var vp = r.GetVirtualPath (new RequestContext (hc, new RouteData()), values);

			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("SomeThing/es-en", vp.VirtualPath, "#1-1");
			Assert.AreEqual (r, vp.Route, "#1-2");
			Assert.AreEqual (0, vp.DataTokens.Count, "#1-3");

			// Case #2: pass no country, but locale as user value.
			values.Remove("country");
			values.Add("locale", "xx");
			vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);

			Assert.IsNotNull(vp, "#2");
			Assert.AreEqual("SomeThing/us-xx", vp.VirtualPath, "#2-1");
			Assert.AreEqual(r, vp.Route, "#2-2");
			Assert.AreEqual(0, vp.DataTokens.Count, "#2-3");

			// Case #3: make contry required.
			r = new MyRoute("{controller}/{country}-{locale}/{action}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary(new { action = "Index", locale = "en" })
			};
			vp = r.GetVirtualPath(new RequestContext(hc, new RouteData()), values);

			Assert.IsNull(vp, "#3");
		}
示例#51
0
		public void GetRouteDataNerdDinner2 ()
		{
			var c = new RouteCollection ();

			c.Add ("UpcomingDiners",
			       new MyRoute ("Dinners/Page/{page}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Dinners", action = "Index" }) }
			);

			c.Add ("Default",
			       new MyRoute ("{controller}/{action}/{id}", new MyRouteHandler ()) { Defaults = new RouteValueDictionary (new { controller = "Home", action = "Index", id = "" })}
			);

			var hc = new HttpContextStub2 ("~/Home/Index", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);
			
			Assert.IsNotNull (rd, "#A1");
		}
示例#52
0
		public void GetVirtualPath23 ()
		{
			var r0 = new MyRoute ("summary/{id}", new MyRouteHandler());
			var r1 = new MyRoute ("summary/{controller}/{id}/{action}", new MyRouteHandler())
			{
				Defaults = new RouteValueDictionary (new { action = "Index" })
			};
			var hc = new HttpContextStub2 ("~/summary/90941a4f-daf3-4c89-a6dc-83e8de4e3db5", String.Empty);
			var rd = r0.GetRouteData (hc);
			Assert.IsNotNull (rd, "#0");
			Assert.AreEqual ("90941a4f-daf3-4c89-a6dc-83e8de4e3db5", rd.Values["id"]);

			var values = new RouteValueDictionary ()
			{
				{ "controller", "SomeThing" },
				{ "action", "Index" }
			};
			var vp = r1.GetVirtualPath (new RequestContext (hc, rd), values);

			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("summary/SomeThing/90941a4f-daf3-4c89-a6dc-83e8de4e3db5", vp.VirtualPath, "#1-1");
			Assert.AreEqual (r1, vp.Route, "#1-2");
			Assert.AreEqual (0, vp.DataTokens.Count, "#1-3");
		}
示例#53
0
		public void Ignore_String_Object ()
		{
			var c = new RouteCollection ();

			AssertExtensions.Throws<ArgumentNullException> (() => {
				c.Ignore (null, new { allaspx = @".*\.aspx(/.*)?" });
			}, "#A1");

			c.Ignore ("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
			var hc = new HttpContextStub2 ("~/page.aspx", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1-1");
			Assert.IsNotNull (rd.RouteHandler, "#A1-2");
			Assert.AreEqual (typeof (StopRoutingHandler), rd.RouteHandler.GetType (), "#A1-3");
			Assert.IsTrue (rd.Route is Route, "#A1-4");
			Assert.IsNotNull (((Route) rd.Route).Constraints, "#A1-5");
			Assert.AreEqual (1, ((Route) rd.Route).Constraints.Count, "#A1-6");
			Assert.AreEqual (@".*\.aspx(/.*)?", ((Route) rd.Route).Constraints ["allaspx"], "#A1-7");

			c = new RouteCollection ();
			c.Ignore ("{*allaspx}", "something invalid");

			AssertExtensions.Throws<InvalidOperationException> (() => {
				rd = c.GetRouteData (hc);
			}, "#A2");
		}
示例#54
0
        public void GetVirtualPath8()
        {
            var routes = new RouteCollection();

            routes.Add(new MyRoute("login", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Home", action = "LogOn" })
            });

            routes.Add(new MyRoute("{site}/{controller}/{action}", new MyRouteHandler())
            {
                Defaults    = new RouteValueDictionary(new { site = "_", controller = "Home", action = "Index" }),
                Constraints = new RouteValueDictionary(new { site = "_?[0-9A-Za-z-]*" })
            });

            routes.Add(new MyRoute("{*path}", new MyRouteHandler())
            {
                Defaults = new RouteValueDictionary(new { controller = "Error", action = "NotFound" }),
            });

            var hc = new HttpContextStub2("~/login", String.Empty, String.Empty);

            hc.SetResponse(new HttpResponseStub(3));
            var rd  = routes.GetRouteData(hc);
            var rvs = new RouteValueDictionary()
            {
                { "controller", "Home" },
                { "action", "Index" }
            };
            var vpd = routes.GetVirtualPath(new RequestContext(hc, rd), rvs);

            Assert.IsNotNull(vpd, "#A1");
            Assert.AreEqual("/", vpd.VirtualPath, "#A2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#A3");

            hc = new HttpContextStub2("~/login", String.Empty, String.Empty);
            hc.SetResponse(new HttpResponseStub(3));
            rd  = routes.GetRouteData(hc);
            rvs = new RouteValueDictionary()
            {
                { "controller", "Home" }
            };
            vpd = routes.GetVirtualPath(new RequestContext(hc, rd), rvs);
            Assert.IsNotNull(vpd, "#B1");
            Assert.AreEqual("/login", vpd.VirtualPath, "#B2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#B3");

            hc = new HttpContextStub2("~/login", String.Empty, String.Empty);
            hc.SetResponse(new HttpResponseStub(3));
            rd  = routes.GetRouteData(hc);
            rvs = new RouteValueDictionary()
            {
                { "action", "Index" }
            };
            vpd = routes.GetVirtualPath(new RequestContext(hc, rd), rvs);
            Assert.IsNotNull(vpd, "#C1");
            Assert.AreEqual("/", vpd.VirtualPath, "#C2");
            Assert.AreEqual(0, vpd.DataTokens.Count, "#C3");

            hc = new HttpContextStub2("~/", String.Empty, String.Empty);
            rd = routes.GetRouteData(hc);
            Assert.IsNotNull(rd, "#D1");
        }
示例#55
0
		public void MapPageRoute_String_String_String_Bool_RVD_RVD_RVD ()
		{
			var c = new RouteCollection ();
			var defaults = new RouteValueDictionary ();
			var constraints = new RouteValueDictionary ();
			var dataTokens = new RouteValueDictionary ();

			c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", true, defaults, constraints, dataTokens);
			var hc = new HttpContextStub2 ("~/some-url", String.Empty, String.Empty);
			hc.SetResponse (new HttpResponseStub (3));
			var rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A1-1");
			Assert.IsNotNull (rd.RouteHandler, "#A1-2");
			Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A1-3");
			Assert.IsTrue (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A1-4");

			c = new RouteCollection ();
			AssertExtensions.Throws<ArgumentNullException> (() => {
				c.MapPageRoute ("RouteName", null, "~/some-url", true, defaults, constraints, dataTokens);
			}, "#A2");

			c = new RouteCollection ();
			c.MapPageRoute ("RouteName", String.Empty, "~/some-url", true, defaults, constraints, dataTokens);
			rd = c.GetRouteData (hc);

			Assert.IsNull (rd, "#A2");

			c = new RouteCollection ();
			// thrown by PageRouteHandler's constructor
			AssertExtensions.Throws<ArgumentException> (() => {
				c.MapPageRoute ("RouteName", "~/some-url", null, true, defaults, constraints, dataTokens);
			}, "#A3");

			c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, defaults, constraints, dataTokens);
			rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A4-1");
			Assert.IsNotNull (rd.RouteHandler, "#A4-2");
			Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
			Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");

			c.MapPageRoute (null, "{foo}-{bar}", "~/some-url", false, null, constraints, dataTokens);
			rd = c.GetRouteData (hc);

			Assert.IsNotNull (rd, "#A4-1");
			Assert.IsNotNull (rd.RouteHandler, "#A4-2");
			Assert.AreEqual (typeof (PageRouteHandler), rd.RouteHandler.GetType (), "#A4-3");
			Assert.IsFalse (((PageRouteHandler) rd.RouteHandler).CheckPhysicalUrlAccess, "#A4-4");
		}
示例#56
0
		public void Pipeline3 ()
		{
			var m = new UrlRoutingModule ();
			RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
#if NET_4_0
			var hc = new HttpContextStub5 ("~/x/y", String.Empty, "apppath");
#else
			var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
#endif
			hc.SetResponse (new HttpResponseStub (2));
#if NET_4_0
			Assert.IsNull (m.RouteCollection.GetRouteData (hc), "#0");
#else
			Assert.IsNotNull (m.RouteCollection.GetRouteData (hc), "#0");
			m.PostResolveRequestCache (hc);
			try {
				m.PostMapRequestHandler (hc);
				Assert.Fail ("#1");
			} catch (ApplicationException ex) {
				Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
			}
#endif
		}