Ejemplo n.º 1
0
        public void AddImplicitProperties_AddUninitializedModule_AddsModuleToRoutes()
        {
            var m = new FakeModuleWithUninitializedModuleProperty ();

            var request = new MockHttpRequest ("GET", "/MyModule/FakeAction");
            var r = m.Routes.Find (request);
            Assert.IsNotNull (r);
        }
Ejemplo n.º 2
0
        public void TestDeleteToTarget()
        {
            var m = new MockManosModule ();
            var req = new MockHttpRequest ("DELETE", "/Foobar");

            m.Delete ("/Foobar", new ManosAction (FakeAction));
            Assert.AreEqual (new ManosAction (FakeAction), m.Routes.Find (req).Action);

            req = new MockHttpRequest ("GET", "/Foobar");
            Assert.IsNull (m.Routes.Find (req));
        }
Ejemplo n.º 3
0
        public void Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute()
        {
            var rh_bad = new RouteHandler ("foo", "GET", new ActionTarget (FakeAction));
            var rh_good = new RouteHandler ("foobar", "GET", new ActionTarget (FakeAction2));
            var rh = new RouteHandler ();

            rh.Children.Add (rh_bad);
            rh.Children.Add (rh_good);

            var request = new MockHttpRequest ("GET", "foobar");
            var res = rh.Find (request);

            Assert.AreEqual (rh_good.Target, res);
        }
Ejemplo n.º 4
0
        public void TestDeleteToModule()
        {
            var m = new MockManosModule ();
            var req = new MockHttpRequest ("DELETE", "/FakeModule/FakeAction");

            m.Delete ("/FakeModule", new FakeModule ());

            //
            // I guess technically this is testing the auto name registering too
            //
            Assert.AreEqual (new ManosAction (FakeModule.FakeAction), m.Routes.Find (req).Action);

            req = new MockHttpRequest ("GET", "/FakeModule/FakeAction");
            Assert.IsNull (m.Routes.Find (req));
        }
Ejemplo n.º 5
0
        public void TestChangePatterns()
        {
            //
            // Ensure that changing the patterns property works.
            // This is a bit of an edge case because internally
            // the patterns strings are cached as an array of
            // regexes.
            //

            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", "GET", target);
            var request = new MockHttpRequest ("GET", "foo");

            Assert.AreEqual (target, rh.Find (request), "sanity-1");

            rh.Patterns [0] = "baz";
            Assert.IsNull (rh.Find (request), "sanity-2");

            request = new MockHttpRequest ("GET", "baz");
            Assert.AreEqual (target, rh.Find (request), "changed");
        }
Ejemplo n.º 6
0
        public void UriParamsTestDeep()
        {
            var rh = new RouteHandler ("(?<animal>.+)/", "GET") {
                new RouteHandler ("(?<name>.+)", "GET", new ActionTarget (FakeAction)),
            };
            var request = new MockHttpRequest ("GET", "dog/roxy");

            Should.NotBeNull (rh.Find (request), "target");

            Should.NotBeNull (request.UriData, "uri-data");

            Assert.AreEqual ("dog", request.UriData ["animal"]);
            Assert.AreEqual ("roxy", request.UriData ["name"]);
        }
Ejemplo n.º 7
0
        public void UriParamsTest()
        {
            var rh = new RouteHandler ("(?<name>.+)", "GET", new ActionTarget (FakeAction));
            var request = new MockHttpRequest ("GET", "hello");

            Should.NotBeNull (rh.Find (request), "target");

            Should.NotBeNull (request.UriData, "uri-data");

            Assert.AreEqual ("hello", request.UriData ["name"]);
        }
Ejemplo n.º 8
0
        public void TestStrMatchDeep()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("foo/", "GET") {
                new RouteHandler ("bar", "GET", target),
            };

            var request = new MockHttpRequest ("GET", "foo/bar");
            Assert.AreEqual (target, rh.Find (request));

            request = new MockHttpRequest ("GET", "foo/foo");
            Assert.IsNull (rh.Find (request), "repeate-input");

            request = new MockHttpRequest ("GET", "foo/badbar");
            Assert.IsNull (rh.Find (request), "matched-input");
        }
Ejemplo n.º 9
0
        public void TestStrMatch()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", "GET", target);
            var request = new MockHttpRequest ("GET", "foo");

            Assert.AreEqual (target, rh.Find (request), "should-match");

            request = new MockHttpRequest ("GET", "garbage-foo");
            Assert.IsNull (rh.Find (request), "garbage-input");
        }
Ejemplo n.º 10
0
        public void TestSetPatternsNull()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", "GET", target);
            var request = new MockHttpRequest ("GET", "foo");

            Assert.AreEqual (target, rh.Find (request), "sanity-1");

            rh.Patterns = null;

            Assert.IsNull (rh.Find (request), "is null");
        }
Ejemplo n.º 11
0
        public void TestRouteToTarget()
        {
            string [] methods = new string [] {
                "GET", "PUT", "POST", "HEAD", "DELETE", "TRACE", "OPTIONS",
            };

            for (int i = 0; i < methods.Length; i++) {
                var m = new MockManosModule ();
                var req = new MockHttpRequest (methods [i], "/Foobar");

                m.Route ("/Foobar", new ManosAction (FakeAction));

                Assert.AreEqual (new ManosAction (FakeAction), m.Routes.Find (req).Action);
            }
        }
Ejemplo n.º 12
0
        public void TestRouteToModule()
        {
            string [] methods = new string [] {
                "GET", "PUT", "POST", "HEAD", "DELETE", "TRACE", "OPTIONS",
            };

            for (int i = 0; i < methods.Length; i++) {
                var m = new MockManosModule ();
                var req = new MockHttpRequest (methods [i], "/FakeModule/FakeAction");

                m.Route ("/FakeModule", new FakeModule ());

                //
                // I guess technically this is testing the auto name registering too
                //
                Assert.AreEqual (new ManosAction (FakeModule.FakeAction), m.Routes.Find (req).Action);
            }
        }
Ejemplo n.º 13
0
        public void TestPutToTarget()
        {
            var m = new MockManosModule ();
            var req = new MockHttpRequest ("PUT", "/Foobar");

            m.Put ("/Foobar", new ManosAction (FakeAction));
            Assert.AreEqual (new ManosAction (FakeAction), m.Routes.Find (req).Action);

            req = new MockHttpRequest ("POST", "/Foobar");
            Assert.IsNull (m.Routes.Find (req));
        }
Ejemplo n.º 14
0
        public void TestOptionsToTarget()
        {
            var m = new MockManosModule ();
            var req = new MockHttpRequest ("OPTIONS", "/Foobar");

            m.Options ("/Foobar", new ManosAction (FakeAction));
            Assert.AreEqual (new ManosAction (FakeAction), m.Routes.Find (req).Action);

            req = new MockHttpRequest ("GET", "/Foobar");
            Assert.IsNull (m.Routes.Find (req));
        }