Ejemplo n.º 1
0
        public void GetRouteData46()
        {
            var r = new Route("Foo", null)
            {
                Defaults = new RouteValueDictionary(new {
                    controller = "Foo",
                    action     = "Index"
                })
            };
            var hc = new HttpContextStub("/Foo/123", String.Empty);
            var rd = r.GetRouteData(hc);

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

            r = new Route("Foo", null)
            {
                Defaults = new RouteValueDictionary(new {
                    controller = "Foo",
                    action     = "Index"
                })
            };
            hc = new HttpContextStub("~/Foo/123", String.Empty);
            rd = r.GetRouteData(hc);
            Assert.IsNull(rd, "#2");
        }
Ejemplo n.º 2
0
        public void GetRouteData26()
        {
            var r = new Route("foo/{bar}/{baz}-{dancefloor}", null)
            {
                Defaults = new RouteValueDictionary(new { baz = "nyc", dancefloor = 1 })
            };

            var hc = new HttpContextStub("~/foo/BlueOyster", String.Empty);
            var rd = r.GetRouteData(hc);

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

            hc = new HttpContextStub("~/foo/blueoyster/bigapple", String.Empty);
            rd = r.GetRouteData(hc);
            Assert.IsNull(rd, "#2");

            hc = new HttpContextStub("~/foo/blueoyster/bigapple-3", String.Empty);
            rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#3");
            Assert.AreEqual(r, rd.Route, "#3-1");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3-2");
            Assert.AreEqual(3, rd.Values.Count, "#3-3");
            Assert.AreEqual("blueoyster", rd.Values["bar"], "#3-4");
            Assert.AreEqual("bigapple", rd.Values["baz"], "#3-5");
            Assert.AreEqual("3", rd.Values["dancefloor"], "#3-6");
            Assert.IsTrue(typeof(string) == rd.Values["dancefloor"].GetType(), "#3-7");

            hc = new HttpContextStub("~/foo/blueoyster/-", String.Empty);
            rd = r.GetRouteData(hc);

            Assert.IsNull(rd, "#4");
        }
Ejemplo n.º 3
0
        public void GetRouteData4()
        {
            var r  = new Route("{foo}/{bar}", null);
            var hc = new HttpContextStub("~/x", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNull(rd);              // mismatch
        }
Ejemplo n.º 4
0
        public void GetRouteData16()
        {
            var r  = new Route("My{location}---{sublocation}", null);
            var hc = new HttpContextStub("~/MyHouse-LivingRoom", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNull(rd, "#1");
        }
Ejemplo n.º 5
0
        public void GetRouteData28()
        {
            var r  = new Route("{foo}xyz{bar}xyz{baz}", null);
            var hc = new HttpContextStub("~/xyzxyzxyzxyzblah", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNull(rd, "#1");
        }
Ejemplo n.º 6
0
        public void GetRouteData12()
        {
            var r  = new Route("summary/{action}-{type}/{page}", null);
            var hc = new HttpContextStub("~/summary/test-xml", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNull(rd, "#1");              // mismatch, missing page
        }
Ejemplo n.º 7
0
        public void InvalidConstraint()
        {
            var r = new Route("{foo}/{bar}", new StopRoutingHandler());
            var c = new RouteValueDictionary();

            c ["foo"]     = Guid.NewGuid();
            r.Constraints = c;
            var hc = new HttpContextStub("~/x/y", String.Empty);
            var rd = r.GetRouteData(hc);
        }
Ejemplo n.º 8
0
        public void GetRouteData33()
        {
            var r  = new Route(null, null);
            var hc = new HttpContextStub("~/", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(0, rd.Values.Count, "#4");
        }
Ejemplo n.º 9
0
        public void GetRouteData27()
        {
            var r = new Route("foo/{bar}/{baz}/{dancefloor}", null)
            {
                Defaults = new RouteValueDictionary(new { bar = "BlueOyster", dancefloor = 1 })
            };

            var hc = new HttpContextStub("~/foo/nyc", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNull(rd, "#1");
        }
Ejemplo n.º 10
0
        public void GetVirtualPath2()
        {
            var r  = new Route("{foo}/{bar}", null);
            var hc = new HttpContextStub("~/x/y", String.Empty);
            var rd = r.GetRouteData(hc);
            var vp = r.GetVirtualPath(new RequestContext(hc, rd), null);

            Assert.IsNotNull(vp, "#1");
            Assert.AreEqual("x/y", vp.VirtualPath, "#2");
            Assert.AreEqual(r, vp.Route, "#3");
            Assert.AreEqual(0, vp.DataTokens.Count, "#4");
        }
Ejemplo n.º 11
0
        public void GetRouteData22()
        {
            var r  = new Route("foo/{ \t\n}", null);
            var hc = new HttpContextStub("~/FOO/stuff", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(1, rd.Values.Count, "#4");
            Assert.AreEqual("stuff", rd.Values[" \t\n"], "#4-1");
        }
Ejemplo n.º 12
0
        public void GetRouteData8()
        {
            var r  = new Route("{first}/{*rest}", null);
            var hc = new HttpContextStub("~/a/b/c/d", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(2, rd.Values.Count, "#4");
            Assert.AreEqual("a", rd.Values ["first"], "#4-1");
            Assert.AreEqual("b/c/d", rd.Values ["rest"], "#4-2");
        }
Ejemplo n.º 13
0
        public void GetRouteData29()
        {
            var r  = new Route("{foo}xyz{bar}", null);
            var hc = new HttpContextStub("~/xyzxyzxyzxyzblah", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(2, rd.Values.Count, "#4");
            Assert.AreEqual("xyzxyzxyz", rd.Values["foo"], "#4-1");
            Assert.AreEqual("blah", rd.Values["bar"], "#4-2");
        }
Ejemplo n.º 14
0
        public void GetRouteData15()
        {
            var r  = new Route("My{location}-{sublocation}", null);
            var hc = new HttpContextStub("~/MyHouse-LivingRoom", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(2, rd.Values.Count, "#4");
            Assert.AreEqual("House", rd.Values["location"], "#4-1");
            Assert.AreEqual("LivingRoom", rd.Values["sublocation"], "#4-2");
        }
Ejemplo n.º 15
0
        public void GetRouteData14()
        {
            var r  = new Route("{filename}.{ext}", null);
            var hc = new HttpContextStub("~/Foo.xml.aspx", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(2, rd.Values.Count, "#4");
            Assert.AreEqual("Foo.xml", rd.Values["filename"], "#4-1");
            Assert.AreEqual("aspx", rd.Values["ext"], "#4-2");
        }
Ejemplo n.º 16
0
        public void GetRouteData2()
        {
            // {} matches and substitutes even at partial state ...
            var r  = new Route("{foo}/bar{baz}", null);
            var hc = new HttpContextStub("~/x/bart", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(2, rd.Values.Count, "#4");
            Assert.AreEqual("x", rd.Values ["foo"], "#4-1");
            Assert.AreEqual("t", rd.Values ["baz"], "#4-2");
        }
Ejemplo n.º 17
0
        public void GetRouteData9()
        {
            var r  = new Route("summary/{action}-{type}/{page}", null);
            var hc = new HttpContextStub("~/summary/test-xml/1", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(0, rd.DataTokens.Count, "#3");
            Assert.AreEqual(3, rd.Values.Count, "#4");
            Assert.AreEqual("test", rd.Values["action"], "#4-1");
            Assert.AreEqual("xml", rd.Values["type"], "#4-2");
            Assert.AreEqual("1", rd.Values["page"], "#4-2");
        }
Ejemplo n.º 18
0
        public void UrlGeneration()
        {
            var c   = new HttpMethodConstraint(new string[] { "GET" }) as IRouteConstraint;
            var req = new HttpContextStub("", "", "HEAD");

            var values = new RouteValueDictionary()
            {
                { "httpMethod", "GET" }
            };

            Assert.IsTrue(c.Match(req, new Route(null, null), "httpMethod", values, RouteDirection.UrlGeneration), "#1");

            values = new RouteValueDictionary()
            {
                { "httpMethod", "POST" }
            };
            Assert.IsFalse(c.Match(req, new Route(null, null), "httpMethod", values, RouteDirection.UrlGeneration), "#2");
        }
Ejemplo n.º 19
0
        public void GetVirtualPath10()
        {
            var r  = new MyRoute("{foo}/{bar}", new MyRouteHandler());
            var hc = new HttpContextStub("~/foo/bar", 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("foo/bar?page=3", vp.VirtualPath, "#2-1");

            vp = r.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { page = 3, another = "stuff" }));
            Assert.IsNotNull(vp, "#3");
            Assert.AreEqual("foo/bar?page=3&another=stuff", vp.VirtualPath, "#3-1");

            vp = r.GetVirtualPath(new RequestContext(hc, rd), new RouteValueDictionary(new { page = 3, another = "stuff", value = "with ; spaces & other chars" }));
            Assert.IsNotNull(vp, "#4");
            Assert.AreEqual("foo/bar?page=3&another=stuff&value=with%20%3B%20spaces%20%26%20other%20chars", vp.VirtualPath, "#4-1");
        }
Ejemplo n.º 20
0
        public void GetRouteData31()
        {
            var r = new Route("{controller}/{action}", null)
            {
                Defaults   = new RouteValueDictionary(new { controller = "Home", action = "Index" }),
                DataTokens = new RouteValueDictionary(new { foobar = "bar" })
            };

            var hc = new HttpContextStub("~/", String.Empty);
            var rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#1");
            Assert.AreEqual(r, rd.Route, "#2");
            Assert.AreEqual(1, rd.DataTokens.Count, "#3");
            Assert.AreEqual(2, rd.Values.Count, "#4");
            Assert.AreEqual("Home", rd.Values["controller"], "#4-1");
            Assert.AreEqual("Index", rd.Values["action"], "#4-2");
            Assert.IsNull(rd.Values["foobar"], "#4-3");
            Assert.IsNotNull(rd.DataTokens, "#5");
            Assert.AreEqual(1, rd.DataTokens.Count, "#6");
            Assert.AreEqual("bar", rd.DataTokens["foobar"], "#6-1");
        }
Ejemplo n.º 21
0
        public void GetRouteData30()
        {
            var r = new Route("{foo}/bar/{baz}/boo/{blah}", null)
            {
                Defaults = new RouteValueDictionary(new { baz = "meep", blah = "blurb" })
            };

            var hc = new HttpContextStub("~/foo/bar", String.Empty);
            var rd = r.GetRouteData(hc);

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

            hc = new HttpContextStub("~/foo/bar/baz/boo", String.Empty);
            rd = r.GetRouteData(hc);

            Assert.IsNotNull(rd, "#2");
            Assert.AreEqual(r, rd.Route, "#3");
            Assert.AreEqual(0, rd.DataTokens.Count, "#4");
            Assert.AreEqual(3, rd.Values.Count, "#4");
            Assert.AreEqual("foo", rd.Values["foo"], "#4-1");
            Assert.AreEqual("baz", rd.Values["baz"], "#4-2");
            Assert.AreEqual("blurb", rd.Values["blah"], "#4-3");
        }
Ejemplo n.º 22
0
        public void GetRouteData23()
        {
            var r = new Route("foo/{bar}-{baz}/{dancefloor}", null)
            {
                Defaults = new RouteValueDictionary(new { bar = "BlueOyster", dancefloor = 1 })
            };

            var hc = new HttpContextStub("~/foo/-nyc/1", String.Empty);
            var rd = r.GetRouteData(hc);

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

            hc = new HttpContextStub("~/foo/blueoyster-nyc", String.Empty);
            rd = r.GetRouteData(hc);
            Assert.IsNotNull(rd, "#2");
            Assert.AreEqual(r, rd.Route, "#2-1");
            Assert.AreEqual(0, rd.DataTokens.Count, "#2-2");
            Assert.AreEqual(3, rd.Values.Count, "#2-3");
            Assert.AreEqual("blueoyster", rd.Values["bar"], "#2-4");
            Assert.AreEqual("nyc", rd.Values["baz"], "#2-5");
            Assert.AreEqual(1, rd.Values["dancefloor"], "#2-6");
            Assert.IsTrue(typeof(int) == rd.Values["dancefloor"].GetType(), "#2-7");
        }
Ejemplo n.º 23
0
		public void GetRouteData12 ()
		{
			var r = new Route ("summary/{action}-{type}/{page}", null);
			var hc = new HttpContextStub ("~/summary/test-xml", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNull (rd, "#1"); // mismatch, missing page
		}
Ejemplo n.º 24
0
		public void GetRouteData33 ()
		{
			var r = new Route (null, null);
			var hc = new HttpContextStub ("~/", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (0, rd.Values.Count, "#4");
		}
Ejemplo n.º 25
0
		public void GetRouteData30 ()
		{
			var r = new Route ("{foo}/bar/{baz}/boo/{blah}", null) {
					Defaults = new RouteValueDictionary (new { baz = "meep", blah = "blurb" })
			};
				
			var hc = new HttpContextStub ("~/foo/bar", String.Empty);
			var rd = r.GetRouteData (hc);

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

			hc = new HttpContextStub ("~/foo/bar/baz/boo", String.Empty);
			rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#2");
			Assert.AreEqual (r, rd.Route, "#3");
			Assert.AreEqual (0, rd.DataTokens.Count, "#4");
			Assert.AreEqual (3, rd.Values.Count, "#4");
			Assert.AreEqual ("foo", rd.Values["foo"], "#4-1");
			Assert.AreEqual ("baz", rd.Values["baz"], "#4-2");
			Assert.AreEqual ("blurb", rd.Values["blah"], "#4-3");
		}
Ejemplo n.º 26
0
		public void GetRouteData26 ()
		{
			var r = new Route ("foo/{bar}/{baz}-{dancefloor}", null) {
					Defaults = new RouteValueDictionary (new { baz = "nyc", dancefloor = 1 })
			};
				
			var hc = new HttpContextStub ("~/foo/BlueOyster", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#1");
			
			hc = new HttpContextStub ("~/foo/blueoyster/bigapple", String.Empty);
			rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#2");
			
			hc = new HttpContextStub ("~/foo/blueoyster/bigapple-3", String.Empty);
			rd = r.GetRouteData (hc);
			
			Assert.IsNotNull (rd, "#3");
			Assert.AreEqual (r, rd.Route, "#3-1");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3-2");
			Assert.AreEqual (3, rd.Values.Count, "#3-3");
			Assert.AreEqual ("blueoyster", rd.Values["bar"], "#3-4");
			Assert.AreEqual ("bigapple", rd.Values["baz"], "#3-5");
			Assert.AreEqual ("3", rd.Values["dancefloor"], "#3-6");
			Assert.IsTrue (typeof (string) == rd.Values["dancefloor"].GetType (), "#3-7");

			hc = new HttpContextStub ("~/foo/blueoyster/-", String.Empty);
			rd = r.GetRouteData (hc);
			
			Assert.IsNull (rd, "#4");
		}
Ejemplo n.º 27
0
		public void GetRouteData22 ()
		{
			var r = new Route ("foo/{ \t\n}", null);
			var hc = new HttpContextStub ("~/FOO/stuff", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (1, rd.Values.Count, "#4");
			Assert.AreEqual ("stuff", rd.Values[" \t\n"], "#4-1");
		}
Ejemplo n.º 28
0
		public void GetRouteData15 ()
		{
			var r = new Route ("My{location}-{sublocation}", null);
			var hc = new HttpContextStub ("~/MyHouse-LivingRoom", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (2, rd.Values.Count, "#4");
			Assert.AreEqual ("House", rd.Values["location"], "#4-1");
			Assert.AreEqual ("LivingRoom", rd.Values["sublocation"], "#4-2");
		}
Ejemplo n.º 29
0
		public void GetRouteData47 ()
		{
			var r = new Route ("Foo/{id}", new StopRoutingHandler ()) {
				Defaults = new RouteValueDictionary (new {
					controller = "Foo",
					action = "Retrieve"
				}),
				Constraints = new RouteValueDictionary (new {
					id = @"\d{1,10}"
				})
			};
			
			var hc = new HttpContextStub ("~/Foo/x123", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNull (rd, "#1");
		}
Ejemplo n.º 30
0
		public void UrlGeneration ()
		{
			var c = new HttpMethodConstraint (new string[] { "GET" }) as IRouteConstraint;
			var req = new HttpContextStub ("", "", "HEAD");

			var values = new RouteValueDictionary () { { "httpMethod", "GET" } };
			Assert.IsTrue (c.Match (req, new Route (null, null), "httpMethod", values, RouteDirection.UrlGeneration), "#1");

			values = new RouteValueDictionary() { { "httpMethod", "POST" } };
			Assert.IsFalse (c.Match (req, new Route (null, null), "httpMethod", values, RouteDirection.UrlGeneration), "#2");
		}
Ejemplo n.º 31
0
		public void GetRouteData43 ()
		{
			// {} matches and substitutes even at partial state ...
			var r = new Route ("{foo}-{bar}-{baz}", null);
			var hc = new HttpContextStub ("~/--", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#1");

			hc = new HttpContextStub ("~/1-2-3", String.Empty);
			rd = r.GetRouteData (hc);
			Assert.IsNotNull (rd, "#2");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (3, rd.Values.Count, "#4");
			Assert.AreEqual ("1", rd.Values ["foo"], "#4-1");
			Assert.AreEqual ("2", rd.Values ["bar"], "#4-2");
			Assert.AreEqual ("3", rd.Values ["baz"], "#4-2");
		}
Ejemplo n.º 32
0
		public void GetRouteData37 ()
		{
			var r = new Route ("{foo}xyz{bar}xyz{baz}", null);
			var hc = new HttpContextStub ("~/xyzxyzxyzxyzxyz", String.Empty);
			var rd = r.GetRouteData (hc);

#if NET_4_0 || !DOTNET
			// When running on Mono this test succeeds - it was a bug in .NET routing for 3.5 which
			// we don't reproduce anymore.
			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (3, rd.Values.Count, "#4");
			Assert.AreEqual ("xyz", rd.Values ["foo"], "#4-1");
			Assert.AreEqual ("xyz", rd.Values ["bar"], "#4-2");
			Assert.AreEqual ("xyz", rd.Values ["baz"], "#4-3");
#else
			Assert.IsNull (rd, "#1");
#endif
		}
Ejemplo n.º 33
0
		public void GetRouteData28 ()
		{
			var r = new Route ("{foo}xyz{bar}xyz{baz}", null);
			var hc = new HttpContextStub ("~/xyzxyzxyzxyzblah", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNull (rd, "#1");
		}
Ejemplo n.º 34
0
		public void GetRouteData13 ()
		{
			var r = new Route ("summary/{action}-{type}/{page}", null) {
					Defaults = new RouteValueDictionary (new { action = "Index", page = 1 } )
						};
			var hc = new HttpContextStub ("~/summary/test-xml/1", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (3, rd.Values.Count, "#4");
			Assert.AreEqual ("test", rd.Values["action"], "#4-1");
			Assert.AreEqual ("xml", rd.Values["type"], "#4-2");
			Assert.AreEqual ("1", rd.Values["page"], "#4-3");
		}
Ejemplo n.º 35
0
		public void GetRouteData14 ()
		{
			var r = new Route ("{filename}.{ext}", null);
			var hc = new HttpContextStub ("~/Foo.xml.aspx", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (2, rd.Values.Count, "#4");
			Assert.AreEqual ("Foo.xml", rd.Values["filename"], "#4-1");
			Assert.AreEqual ("aspx", rd.Values["ext"], "#4-2");
		}
Ejemplo n.º 36
0
		public void GetRouteDataWithCatchAll ()
		{
			var r = new Route ("{*path}", new StopRoutingHandler ()) {
				Defaults = new RouteValueDictionary (new {
					controller = "Error",
					action = "NotFound"
				})
			};

			var hc = new HttpContextStub ("~/", String.Empty);
			var rd = r.GetRouteData (hc);

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

			hc = new HttpContextStub ("~/Foo/x123", String.Empty);
			rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#2");
		}
Ejemplo n.º 37
0
		public void GetRouteData16 ()
		{
			var r = new Route ("My{location}---{sublocation}", null);
			var hc = new HttpContextStub ("~/MyHouse-LivingRoom", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNull (rd, "#1");
		}
Ejemplo n.º 38
0
		public void GetVirtualPath10 ()
		{
			var r = new MyRoute ("{foo}/{bar}", new MyRouteHandler ());
			var hc = new HttpContextStub ("~/foo/bar", 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 ("foo/bar?page=3", vp.VirtualPath, "#2-1");

			vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3, another = "stuff" }));
			Assert.IsNotNull (vp, "#3");
			Assert.AreEqual ("foo/bar?page=3&another=stuff", vp.VirtualPath, "#3-1");

			vp = r.GetVirtualPath (new RequestContext (hc, rd), new RouteValueDictionary (new { page = 3, another = "stuff", value = "with ; spaces & other chars" }));
			Assert.IsNotNull (vp, "#4");
			Assert.AreEqual ("foo/bar?page=3&another=stuff&value=with%20%3B%20spaces%20%26%20other%20chars", vp.VirtualPath, "#4-1");
		}
Ejemplo n.º 39
0
		public void GetRouteData23 ()
		{
			var r = new Route ("foo/{bar}-{baz}/{dancefloor}", null) {
					Defaults = new RouteValueDictionary (new { bar = "BlueOyster", dancefloor = 1 })
			};
				
			var hc = new HttpContextStub ("~/foo/-nyc/1", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#1");

			hc = new HttpContextStub ("~/foo/blueoyster-nyc", String.Empty);
			rd = r.GetRouteData (hc);
			Assert.IsNotNull (rd, "#2");
			Assert.AreEqual (r, rd.Route, "#2-1");
			Assert.AreEqual (0, rd.DataTokens.Count, "#2-2");
			Assert.AreEqual (3, rd.Values.Count, "#2-3");
			Assert.AreEqual ("blueoyster", rd.Values["bar"], "#2-4");
			Assert.AreEqual ("nyc", rd.Values["baz"], "#2-5");
			Assert.AreEqual (1, rd.Values["dancefloor"], "#2-6");
			Assert.IsTrue (typeof (int) == rd.Values["dancefloor"].GetType (), "#2-7");
		}
Ejemplo n.º 40
0
		public void InvalidConstraint ()
		{
			var r = new Route ("{foo}/{bar}", new StopRoutingHandler ());
			var c = new RouteValueDictionary ();
			c ["foo"] = Guid.NewGuid ();
			r.Constraints = c;
			var hc = new HttpContextStub ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);
		}
Ejemplo n.º 41
0
		public void GetRouteData27 ()
		{
			var r = new Route ("foo/{bar}/{baz}/{dancefloor}", null) {
					Defaults = new RouteValueDictionary (new { bar = "BlueOyster", dancefloor = 1 })
			};
				
			var hc = new HttpContextStub ("~/foo/nyc", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#1");
		}
Ejemplo n.º 42
0
		public void GetRouteData ()
		{
			var r = new Route ("{foo}/{bar}", null);
			var hc = new HttpContextStub ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (2, rd.Values.Count, "#4");
			Assert.AreEqual ("x", rd.Values ["foo"], "#4-1");
			Assert.AreEqual ("y", rd.Values ["bar"], "#4-2");
		}
Ejemplo n.º 43
0
		public void GetRouteData31()
		{
			var r = new Route("{controller}/{action}", null)
			{
				Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index" }),
				DataTokens = new RouteValueDictionary(new { foobar = "bar" })
			};

			var hc = new HttpContextStub("~/", String.Empty);
			var rd = r.GetRouteData(hc);

			Assert.IsNotNull(rd, "#1");
			Assert.AreEqual(r, rd.Route, "#2");
			Assert.AreEqual(1, rd.DataTokens.Count, "#3");
			Assert.AreEqual(2, rd.Values.Count, "#4");
			Assert.AreEqual("Home", rd.Values["controller"], "#4-1");
			Assert.AreEqual("Index", rd.Values["action"], "#4-2");
			Assert.IsNull(rd.Values["foobar"], "#4-3");
			Assert.IsNotNull(rd.DataTokens, "#5");
			Assert.AreEqual(1, rd.DataTokens.Count, "#6");
			Assert.AreEqual("bar", rd.DataTokens["foobar"], "#6-1");
		}
Ejemplo n.º 44
0
		public void GetRouteData4 ()
		{
			var r = new Route ("{foo}/{bar}", null);
			var hc = new HttpContextStub ("~/x", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd); // mismatch
		}
Ejemplo n.º 45
0
		public void GetRouteData35 ()
		{
			var r = new Route ("{foo}xyz{bar}xyz{baz}", null);
			var hc = new HttpContextStub ("~/xyzxyzxyzdabxyzblah", String.Empty);
			var rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (3, rd.Values.Count, "#4");
			Assert.AreEqual ("xyzxyz", rd.Values ["foo"], "#4-1");
			Assert.AreEqual ("dab", rd.Values ["bar"], "#4-2");
			Assert.AreEqual ("blah", rd.Values ["baz"], "#4-3");
		}
Ejemplo n.º 46
0
		public void GetRouteData8 ()
		{
			var r = new Route ("{first}/{*rest}", null);
			var hc = new HttpContextStub ("~/a/b/c/d", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (2, rd.Values.Count, "#4");
			Assert.AreEqual ("a", rd.Values ["first"], "#4-1");
			Assert.AreEqual ("b/c/d", rd.Values ["rest"], "#4-2");
		}
Ejemplo n.º 47
0
		public void GetRouteData39 ()
		{
			// {} matches and substitutes even at partial state ...
			var r = new Route ("{foo}/bar{baz}", null);
			var hc = new HttpContextStub ("~/x/barte", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNotNull (rd, "#1");
			Assert.AreEqual (r, rd.Route, "#2");
			Assert.AreEqual (0, rd.DataTokens.Count, "#3");
			Assert.AreEqual (2, rd.Values.Count, "#4");
			Assert.AreEqual ("x", rd.Values ["foo"], "#4-1");
			Assert.AreEqual ("te", rd.Values ["baz"], "#4-2");
		}
Ejemplo n.º 48
0
		public void GetRouteDataWithCatchAll2 ()
		{
			var r = new Route ("something/{*path}", new StopRoutingHandler ()) {
				Defaults = new RouteValueDictionary (new {
					controller = "Error",
					action = "NotFound"
				})
			};

			var hc = new HttpContextStub ("~/", String.Empty);
			var rd = r.GetRouteData (hc);

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

			hc = new HttpContextStub ("~/something", String.Empty);
			rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#2");
			Assert.IsNull (rd.Values["path"], "#2.1");

			hc = new HttpContextStub ("~/something/", String.Empty);
			rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#3");
			Assert.IsNull (rd.Values["path"], "#3.1");

			hc = new HttpContextStub ("~/something/algo", String.Empty);
			rd = r.GetRouteData (hc);

			Assert.IsNotNull (rd, "#4");
			Assert.AreEqual ("algo", rd.Values["path"], "#4.1");

		}
Ejemplo n.º 49
0
		public void GetVirtualPath2 ()
		{
			var r = new Route ("{foo}/{bar}", null);
			var hc = new HttpContextStub ("~/x/y", String.Empty);
			var rd = r.GetRouteData (hc);
			var vp = r.GetVirtualPath (new RequestContext (hc, rd), null);
			Assert.IsNotNull (vp, "#1");
			Assert.AreEqual ("x/y", vp.VirtualPath, "#2");
			Assert.AreEqual (r, vp.Route, "#3");
			Assert.AreEqual (0, vp.DataTokens.Count, "#4");
		}
Ejemplo n.º 50
0
		public void GetRouteData46 ()
		{
			var r = new Route ("Foo", null) {
				Defaults = new RouteValueDictionary (new {
					controller = "Foo",
					action = "Index"
				})
			};
			var hc = new HttpContextStub ("/Foo/123", String.Empty);
			var rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#1");

			r = new Route ("Foo", null) {
				Defaults = new RouteValueDictionary (new {
					controller = "Foo",
					action = "Index"
				})
			};
			hc = new HttpContextStub ("~/Foo/123", String.Empty);
			rd = r.GetRouteData (hc);
			Assert.IsNull (rd, "#2");
		}