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); }
public ManosBrowser(ManosApp app) { _app = app; _app.StartInternal (); Request = new MockHttpRequest (); Response = new MockHttpResponse (); Transaction = new MockHttpTransaction (Request, Response); }
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); }
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); }
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"]); }
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"]); }
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"); }
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); } }
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); }
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"]); }
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"]); }
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"); }
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"); }
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); }
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"); }
public With(MockHttpRequest request, DataDictionary dict) { _request = request; _dict = dict; }
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"); }
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); } }
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"); }
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)); }
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"); }
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)); }
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); }