示例#1
0
        public void AddImplicitProperties_AddUninitializedModule_AddsModuleToRoutes()
        {
            var m = new FakeModuleWithUninitializedModuleProperty();

            var request = new MockHttpRequest(HttpMethod.HTTP_GET, "/MyModule/FakeAction");
            IManosTarget r = m.Routes.Find(request);
            Assert.IsNotNull(r);
        }
示例#2
0
        public ManosBrowser(ManosApp app)
        {
            _app = app;
            _app.StartInternal ();

            Request = new MockHttpRequest ();
            Response = new MockHttpResponse ();
            Transaction = new MockHttpTransaction (Request, Response);
        }
示例#3
0
        public void Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute()
        {
            var rh_bad = new RouteHandler ("foo", HttpMethod.HTTP_GET, new ActionTarget (FakeAction));
            var rh_good = new RouteHandler ("foobar", HttpMethod.HTTP_GET, new ActionTarget (FakeAction2));
            var rh = new RouteHandler ();

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

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

            Assert.AreEqual (rh_good.Target, res);
        }
示例#4
0
        public void Find_PartialMatchAtBeginningOfChildlessHandler_ReturnsProperRoute()
        {
            IMatchOperation fooOp = MatchOperationFactory.Create("foo", MatchType.String);
            IMatchOperation foobarOp = MatchOperationFactory.Create("foobar", MatchType.String);
            var rh_bad = new RouteHandler(fooOp, HttpMethod.HTTP_GET, new ActionTarget(FakeAction));
            var rh_good = new RouteHandler(foobarOp, HttpMethod.HTTP_GET, new ActionTarget(FakeAction2));
            var rh = new RouteHandler();

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

            var request = new MockHttpRequest(HttpMethod.HTTP_GET, "foobar");
            IManosTarget res = rh.Find(request);

            Assert.AreEqual(rh_good.Target, res);
        }
示例#5
0
        public void UriParamsTestDeep()
        {
            var rh = new RouteHandler ("(?<animal>.+)/", HttpMethod.HTTP_GET) {
                new RouteHandler ("(?<name>.+)", HttpMethod.HTTP_GET, new ActionTarget (FakeAction)),
            };
            var request = new MockHttpRequest (HttpMethod.HTTP_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"]);
        }
示例#6
0
        public void UriParamsTest()
        {
            var rh = new RouteHandler ("(?<name>.+)", HttpMethod.HTTP_GET, new ActionTarget (FakeAction));
            var request = new MockHttpRequest (HttpMethod.HTTP_GET, "hello");

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

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

            Assert.AreEqual ("hello", request.UriData ["name"]);
        }
示例#7
0
        public void TestSetPatternsNull()
        {
            IMatchOperation fooOp = MatchOperationFactory.Create("^foo", MatchType.Regex);

            var target = new MockManosTarget();
            var rh = new RouteHandler(fooOp, HttpMethod.HTTP_GET, target);
            var request = new MockHttpRequest(HttpMethod.HTTP_GET, "foo");

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

            rh.MatchOps = null;

            Assert.IsNull(rh.Find(request), "is null");
        }
示例#8
0
        public void TestRouteToTarget()
        {
            var methods = new[]
                              {
                                  HttpMethod.HTTP_GET, HttpMethod.HTTP_PUT, HttpMethod.HTTP_POST, HttpMethod.HTTP_HEAD,
                                  HttpMethod.HTTP_DELETE, HttpMethod.HTTP_TRACE, HttpMethod.HTTP_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);
            }
        }
示例#9
0
        public void RouteWorksWithRegexParamsInModuleOnCustomApp()
        {
            var t = new TestApp();
            var req = new MockHttpRequest(HttpMethod.HTTP_GET,"/TESTING/Route3/Andrew/29");
            var txn = new MockHttpTransaction(req);
            t.HandleTransaction(t,txn);

            Assert.AreEqual("'Andrew', you are '29'",txn.ResponseString);

            req = new MockHttpRequest(HttpMethod.HTTP_GET,"/TESTING/Route3/Andrew/29/");
            txn = new MockHttpTransaction(req);
            t.HandleTransaction(t,txn);

            Assert.AreEqual("'Andrew', you are '29'",txn.ResponseString);
        }
示例#10
0
        public void UriParamsTestDeep()
        {
            IMatchOperation animalOp = MatchOperationFactory.Create("(?<animal>.+)/", MatchType.Regex);
            IMatchOperation nameOp = MatchOperationFactory.Create("(?<name>.+)", MatchType.Regex);
            var rh = new RouteHandler(animalOp, HttpMethod.HTTP_GET)
                         {
                             new RouteHandler(nameOp, HttpMethod.HTTP_GET, new ActionTarget(FakeAction)),
                         };

            var request = new MockHttpRequest(HttpMethod.HTTP_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"]);
        }
示例#11
0
        public void UriParamsTest()
        {
            IMatchOperation fooOp = MatchOperationFactory.Create("(?<name>.+)", MatchType.Regex);
            var rh = new RouteHandler(fooOp, HttpMethod.HTTP_GET, new ActionTarget(FakeAction));
            var request = new MockHttpRequest(HttpMethod.HTTP_GET, "hello");

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

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

            Assert.AreEqual("hello", request.UriData["name"]);
        }
示例#12
0
        public void TestStrMatchDeep()
        {
            IMatchOperation fooOp = MatchOperationFactory.Create("foo/", MatchType.String);
            IMatchOperation barOp = MatchOperationFactory.Create("bar", MatchType.String);
            var target = new MockManosTarget();
            var rh = new RouteHandler(fooOp, HttpMethod.HTTP_GET)
                         {
                             new RouteHandler(barOp, HttpMethod.HTTP_GET, target),
                         };

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

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

            request = new MockHttpRequest(HttpMethod.HTTP_GET, "foo/badbar");
            Assert.IsNull(rh.Find(request), "matched-input");
        }
示例#13
0
        public void TestStrMatch()
        {
            IMatchOperation op = MatchOperationFactory.Create("^foo", MatchType.Regex);
            var target = new MockManosTarget();
            var rh = new RouteHandler(op, HttpMethod.HTTP_GET, target);
            var request = new MockHttpRequest(HttpMethod.HTTP_GET, "foo");

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

            request = new MockHttpRequest(HttpMethod.HTTP_GET, "garbage-foo");
            Assert.IsNull(rh.Find(request), "garbage-input");
        }
示例#14
0
        public void ImplicitRouteWorksWithModuleOnCustomApp()
        {
            var t = new TestApp();
            var req = new MockHttpRequest(HttpMethod.HTTP_GET,"/TESTING/Route1");
            var txn = new MockHttpTransaction(req);
            t.HandleTransaction(t,txn);

            Assert.AreEqual("Route1",txn.ResponseString);

            req = new MockHttpRequest(HttpMethod.HTTP_GET, "/TESTING/Route1/");
            txn = new MockHttpTransaction(req);
            t.HandleTransaction(t,txn);
            Assert.AreEqual("Route1",txn.ResponseString);
        }
示例#15
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", HttpMethod.HTTP_GET, target);
            var request = new MockHttpRequest (HttpMethod.HTTP_GET, "foo");

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

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

            request = new MockHttpRequest (HttpMethod.HTTP_GET, "baz");
            Assert.AreEqual (target, rh.Find (request), "changed");
        }
示例#16
0
 public With(MockHttpRequest request, DataDictionary dict)
 {
     _request = request;
     _dict = dict;
 }
示例#17
0
        public void TestSetPatternsNull()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", HttpMethod.HTTP_GET, target);
            var request = new MockHttpRequest (HttpMethod.HTTP_GET, "foo");

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

            rh.Patterns = null;

            Assert.IsNull (rh.Find (request), "is null");
        }
示例#18
0
        public void TestRouteToModule()
        {
            var methods = new[]
                              {
                                  HttpMethod.HTTP_GET, HttpMethod.HTTP_PUT, HttpMethod.HTTP_POST, HttpMethod.HTTP_HEAD,
                                  HttpMethod.HTTP_DELETE, HttpMethod.HTTP_TRACE, HttpMethod.HTTP_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);
            }
        }
示例#19
0
        public void TestStrMatch()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("^foo", HttpMethod.HTTP_GET, target);
            var request = new MockHttpRequest (HttpMethod.HTTP_GET, "foo");

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

            request = new MockHttpRequest (HttpMethod.HTTP_GET, "garbage-foo");
            Assert.IsNull (rh.Find (request), "garbage-input");
        }
示例#20
0
        public void TestTraceToTarget()
        {
            var m = new MockManosModule();
            var req = new MockHttpRequest(HttpMethod.HTTP_TRACE, "/Foobar");

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

            req = new MockHttpRequest(HttpMethod.HTTP_GET, "/Foobar");
            Assert.IsNull(m.Routes.Find(req));
        }
示例#21
0
        public void TestStrMatchDeep()
        {
            var target = new MockManosTarget ();
            var rh = new RouteHandler ("foo/", HttpMethod.HTTP_GET) {
                new RouteHandler ("bar", HttpMethod.HTTP_GET, target),
            };

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

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

            request = new MockHttpRequest (HttpMethod.HTTP_GET, "foo/badbar");
            Assert.IsNull (rh.Find (request), "matched-input");
        }
示例#22
0
        public void TestDeleteToModule()
        {
            var m = new MockManosModule();
            var req = new MockHttpRequest(HttpMethod.HTTP_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(HttpMethod.HTTP_GET, "/FakeModule/FakeAction");
            Assert.IsNull(m.Routes.Find(req));
        }
示例#23
0
        public void RouteWorksWithNamedParametersInModuleOnCustomApp()
        {
            var t = new TestApp();
            var req = new MockHttpRequest(HttpMethod.HTTP_GET, "/TESTING/Route2a/29/Andrew");
            var txn = new MockHttpTransaction(req, new MockHttpResponse());
            t.HandleTransaction(t, txn);

            Assert.AreEqual("(R2a) Hello 'Andrew', you are '29'", txn.ResponseString);

            req = new MockHttpRequest(HttpMethod.HTTP_GET, "/TESTING/Route2b/Andrew/29");

            txn = new MockHttpTransaction(req, new MockHttpResponse());
            t.HandleTransaction(t, txn);

            Assert.AreEqual("(R2b) Hello 'Andrew', you are '29'", txn.ResponseString);
        }